Compare commits

..

5 commits

Author SHA1 Message Date
1265510037 fix(deps): update dependencies (major and minor)
Some checks failed
CI / Get Changed Files (pull_request) Successful in 8s
CI / prettier (pull_request) Successful in 26s
CI / eslint (pull_request) Successful in 32s
CI / Checkstyle Main (pull_request) Failing after 54s
CI / test-build (pull_request) Failing after 24s
2025-03-27 13:16:57 +00:00
4fa7b63b04 Merge pull request 'feat: validate game state on hit (CAS-51)' (!103) from feat/hit-state-validation into main
All checks were successful
Release / Release (push) Successful in 41s
Reviewed-on: #103
Reviewed-by: Jan K9f <jan@kjan.email>
2025-03-27 13:07:37 +00:00
4b4de32e1d Merge pull request 'feat(blackjack): add player lost state in game logic (CAS-51)' (!102) from update-state-on-hit into main
Some checks failed
Release / Release (push) Has been cancelled
Reviewed-on: #102
Reviewed-by: Phan Huy Tran <ptran@noreply.localhost>
2025-03-27 13:07:03 +00:00
Phan Huy Tran
4764c12909 feat: validate game state on hit
All checks were successful
CI / Get Changed Files (pull_request) Successful in 6s
CI / eslint (pull_request) Has been skipped
CI / prettier (pull_request) Has been skipped
CI / test-build (pull_request) Has been skipped
CI / Checkstyle Main (pull_request) Successful in 1m45s
2025-03-27 14:05:13 +01:00
e9a8267208
feat(blackjack): add player lost state in game logic
All checks were successful
CI / Get Changed Files (pull_request) Successful in 8s
CI / eslint (pull_request) Has been skipped
CI / prettier (pull_request) Has been skipped
CI / test-build (pull_request) Has been skipped
CI / Checkstyle Main (pull_request) Successful in 1m1s
2025-03-27 14:03:33 +01:00
4 changed files with 12 additions and 3 deletions

View file

@ -7,6 +7,6 @@ Content-Type: application/json
}
###
POST http://localhost:8080/blackjack/103/hit
POST http://localhost:8080/blackjack/202/hit
Authorization: Bearer {{token}}

View file

@ -40,6 +40,12 @@ public class BlackJackGameController {
return ResponseEntity.notFound().build();
}
if (game.getState() != BlackJackState.IN_PROGRESS) {
Map<String, String> errorResponse = new HashMap<>();
errorResponse.put("error", "Invalid state");
return ResponseEntity.badRequest().body(errorResponse);
}
return ResponseEntity.ok(blackJackService.hit(game));
}

View file

@ -89,12 +89,14 @@ public class BlackJackService {
if (playerHandValue == 21) {
return BlackJackState.PLAYER_WON;
} else if (playerHandValue > 21) {
return BlackJackState.PLAYER_LOST;
}
return BlackJackState.IN_PROGRESS;
}
public int calculateHandValue(List<CardEntity> hand) {
private int calculateHandValue(List<CardEntity> hand) {
int sum = 0;
int aceCount = 0;
for (CardEntity card : hand) {

View file

@ -2,5 +2,6 @@ package de.szut.casino.blackjack;
public enum BlackJackState {
PLAYER_WON,
IN_PROGRESS
IN_PROGRESS,
PLAYER_LOST,
}