Skip to content

Commit 8340d92

Browse files
committed
calculate remaining handicap
1 parent 686a52c commit 8340d92

File tree

5 files changed

+11
-12
lines changed

5 files changed

+11
-12
lines changed

src/main/java/com/bernd/GameController.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ public void action(Move move, Principal p) {
6666
if (p == null || game == null) {
6767
return;
6868
}
69+
if (game.isForbidden(move)) {
70+
return;
71+
}
6972
int principalColor = getColorFromPrincipal(game, getPrincipal(p));
7073
int color = getColorFromGameState(game);
7174
if (color == 0

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ public ViewGame startEdit(@RequestBody MatchRequest request) {
7676
createEmptyBoard(request.dim()),
7777
request.dim(),
7878
request.handicap(),
79-
request.handicap(),
8079
new int[]{-1, -1},
8180
MoveList.create(request.dim())));
8281
activeGames.put(ActiveGame.fromGame(game));

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ public record Game(
2121
int[][] board,
2222
int dim,
2323
int handicap,
24-
int remainingHandicap,
2524
int[] forbidden,
2625
MoveList moves
2726
) {
@@ -83,7 +82,6 @@ private Game updateInternal(Move move) {
8382
.build();
8483
}
8584
return toBuilder()
86-
.withRemainingHandicap(Math.max(0, remainingHandicap - 1))
8785
.withBoard(result)
8886
.withForbidden(NOT_FORBIDDEN)
8987
.build();
@@ -175,4 +173,12 @@ boolean opponentPassed() {
175173
}
176174
return getLastMove().pass();
177175
}
176+
177+
public int remainingHandicap() {
178+
return Math.max(0, handicap - moves.size());
179+
}
180+
181+
public boolean isForbidden(Move move) {
182+
return move.x() == forbidden[0] && move.y() == forbidden[1];
183+
}
178184
}

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,13 @@ public final class GameBuilder {
55

66
private boolean counting;
77
private int countingAgreed;
8-
private int remainingHandicap;
98
private int[][] board;
109
private int[] forbidden;
1110

1211
private GameBuilder(Game game) {
1312
this.game = game;
1413
}
1514

16-
public GameBuilder withRemainingHandicap(int remainingHandicap) {
17-
this.remainingHandicap = remainingHandicap;
18-
return this;
19-
}
20-
2115
public GameBuilder withCounting(boolean counting) {
2216
this.counting = counting;
2317
return this;
@@ -44,7 +38,6 @@ public GameBuilder withForbidden(int x, int y) {
4438

4539
static GameBuilder builder(Game game) {
4640
GameBuilder builder = new GameBuilder(game);
47-
builder.remainingHandicap = game.remainingHandicap();
4841
builder.counting = game.counting();
4942
builder.countingAgreed = game.countingAgreed();
5043
builder.board = game.board();
@@ -62,7 +55,6 @@ public Game build() {
6255
board,
6356
game.dim(),
6457
game.handicap(),
65-
remainingHandicap,
6658
forbidden,
6759
game.moves()
6860
);

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ public Game accept(String opponent, AcceptRequest acceptRequest) {
3030
createEmptyBoard(dim),
3131
dim,
3232
acceptRequest.handicap(),
33-
acceptRequest.handicap(),
3433
new int[]{-1, -1},
3534
MoveList.create(dim));
3635
}

0 commit comments

Comments
 (0)