Compare commits
24 commits
d397079561
...
08b12d238e
Author | SHA1 | Date | |
---|---|---|---|
08b12d238e | |||
d400986c34 | |||
5d803e4b8b | |||
6508a233b2 | |||
889863aad6 | |||
ba854be5db | |||
1d9eec4546 | |||
56c63d48f6 | |||
db3d2e7b82 | |||
2a11675fb6 | |||
2405c00f49 | |||
b4caf70ffe | |||
defe26d0c1 | |||
2d8b137e69 | |||
4b569157aa | |||
349e4ce1ec | |||
deac128935 | |||
acdbea5a99 | |||
d2b22b561d | |||
d90fcdcf1e | |||
4e8530c861 | |||
|
cb6c1550b7 | ||
ed6071a0ba | |||
|
ffd651d74b |
4 changed files with 18 additions and 5 deletions
|
@ -7,7 +7,7 @@ Content-Type: application/json
|
|||
}
|
||||
|
||||
###
|
||||
POST http://localhost:8080/blackjack/202/hit
|
||||
POST http://localhost:8080/blackjack/54/hit
|
||||
Authorization: Bearer {{token}}
|
||||
|
||||
###
|
||||
|
|
|
@ -96,7 +96,6 @@ public class BlackJackService {
|
|||
return game;
|
||||
}
|
||||
|
||||
|
||||
private BlackJackGameEntity refreshGameState(BlackJackGameEntity game) {
|
||||
return blackJackGameRepository.findById(game.getId()).orElse(game);
|
||||
}
|
||||
|
@ -205,7 +204,20 @@ public class BlackJackService {
|
|||
int playerHandValue = calculateHandValue(game.getPlayerCards());
|
||||
|
||||
if (playerHandValue == 21) {
|
||||
return BlackJackState.PLAYER_WON;
|
||||
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;
|
||||
}
|
||||
} else if (playerHandValue > 21) {
|
||||
return BlackJackState.PLAYER_LOST;
|
||||
}
|
||||
|
@ -216,7 +228,6 @@ 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,8 +1,9 @@
|
|||
package de.szut.casino.blackjack;
|
||||
|
||||
public enum BlackJackState {
|
||||
PLAYER_WON,
|
||||
IN_PROGRESS,
|
||||
PLAYER_BLACKJACK,
|
||||
PLAYER_LOST,
|
||||
PLAYER_WON,
|
||||
DRAW,
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ public class CardEntity {
|
|||
private Rank rank;
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
@JsonIgnore
|
||||
private CardType cardType;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue