Skip to content

Commit b718f46

Browse files
committed
add handicap field to game
1 parent 3ff83b1 commit b718f46

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/main/java/com/bernd/LobbyController.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ public void matchAction(MatchRequest request, Principal principal) {
5353
user.name(),
5454
B,
5555
false,
56-
createEmptyBoard(request)));
56+
createEmptyBoard(request),
57+
0));
5758
operations.convertAndSend("/topic/lobby/gamestart", game);
5859
return;
5960
}
@@ -78,7 +79,8 @@ public void matchAction(MatchRequest request, Principal principal) {
7879
user.name(),
7980
B,
8081
false,
81-
createEmptyBoard(request)));
82+
createEmptyBoard(request),
83+
0));
8284
operations.convertAndSend("/topic/lobby/gamestart", game);
8385
}
8486

src/main/java/com/bernd/model/Game.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ public record Game(
2020
String currentPlayer,
2121
int currentColor,
2222
boolean opponentPassed,
23-
int[][] board
23+
int[][] board,
24+
int handicap
2425
) {
2526

2627
private static final Logger logger = LogManager.getLogger(Game.class);
@@ -69,7 +70,8 @@ private Game game(
6970
nextPlayer(),
7071
nextColor(),
7172
opponentPassed,
72-
board);
73+
board,
74+
Math.max(0, handicap - 1));
7375
}
7476

7577
private Game game(int[][] board) {
@@ -81,13 +83,16 @@ private Game startCounting() {
8183
}
8284

8385
private String nextPlayer() {
84-
if (editMode) {
86+
if (editMode || handicap > 0) {
8587
return currentPlayer;
8688
}
8789
return currentPlayer.equals(black.name()) ? white().name() : black().name();
8890
}
8991

9092
private int nextColor() {
93+
if (handicap > 0) {
94+
return currentColor;
95+
}
9196
return currentColor == B ? W : B;
9297
}
9398
}

0 commit comments

Comments
 (0)