Compare commits
19 commits
08b12d238e
...
d397079561
Author | SHA1 | Date | |
---|---|---|---|
d397079561 | |||
0654a98860 | |||
3c0505b75e | |||
1ea2f7c086 | |||
ae8dcab038 | |||
aad692aea5 | |||
57a4b03bde | |||
ebf2ee0531 | |||
35d53bce30 | |||
f5a16efa67 | |||
a425fdea80 | |||
f881f82ef1 | |||
f1c70f5f2c | |||
732d475a84 | |||
05322e3d83 | |||
23888ceb27 | |||
adc5bbd345 | |||
c9f71f70fa | |||
68ea66d4f9 |
4 changed files with 6 additions and 19 deletions
|
@ -7,7 +7,7 @@ Content-Type: application/json
|
|||
}
|
||||
|
||||
###
|
||||
POST http://localhost:8080/blackjack/54/hit
|
||||
POST http://localhost:8080/blackjack/202/hit
|
||||
Authorization: Bearer {{token}}
|
||||
|
||||
###
|
||||
|
|
|
@ -96,6 +96,7 @@ public class BlackJackService {
|
|||
return game;
|
||||
}
|
||||
|
||||
|
||||
private BlackJackGameEntity refreshGameState(BlackJackGameEntity game) {
|
||||
return blackJackGameRepository.findById(game.getId()).orElse(game);
|
||||
}
|
||||
|
@ -204,20 +205,7 @@ public class BlackJackService {
|
|||
int playerHandValue = calculateHandValue(game.getPlayerCards());
|
||||
|
||||
if (playerHandValue == 21) {
|
||||
CardEntity hole = drawCardFromDeck(game);
|
||||
hole.setCardType(CardType.DEALER);
|
||||
game.getDealerCards().add(hole);
|
||||
|
||||
int dealerHandValue = calculateHandValue(game.getDealerCards());
|
||||
|
||||
if (dealerHandValue == 21) {
|
||||
return BlackJackState.DRAW;
|
||||
} else {
|
||||
BigDecimal blackjackWinnings = game.getBet().multiply(new BigDecimal("1.5"));
|
||||
UserEntity user = getUserWithFreshData(game.getUser());
|
||||
user.setBalance(user.getBalance().add(blackjackWinnings));
|
||||
return BlackJackState.PLAYER_BLACKJACK;
|
||||
}
|
||||
return BlackJackState.PLAYER_WON;
|
||||
} else if (playerHandValue > 21) {
|
||||
return BlackJackState.PLAYER_LOST;
|
||||
}
|
||||
|
@ -228,6 +216,7 @@ public class BlackJackService {
|
|||
private int calculateHandValue(List<CardEntity> hand) {
|
||||
int sum = 0;
|
||||
int aceCount = 0;
|
||||
|
||||
for (CardEntity card : hand) {
|
||||
sum += card.getRank().getValue();
|
||||
if (card.getRank() == Rank.ACE) {
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
package de.szut.casino.blackjack;
|
||||
|
||||
public enum BlackJackState {
|
||||
IN_PROGRESS,
|
||||
PLAYER_BLACKJACK,
|
||||
PLAYER_LOST,
|
||||
PLAYER_WON,
|
||||
IN_PROGRESS,
|
||||
PLAYER_LOST,
|
||||
DRAW,
|
||||
}
|
||||
|
|
|
@ -31,7 +31,6 @@ public class CardEntity {
|
|||
private Rank rank;
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
@JsonIgnore
|
||||
private CardType cardType;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue