Skip to content

Commit 1ee463e

Browse files
committed
fix review after timeout
do not show count result while reviewing
1 parent b390570 commit 1ee463e

File tree

5 files changed

+29
-7
lines changed

5 files changed

+29
-7
lines changed

src/main/client/src/feature/game/Game.jsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ import {
3535
initialState,
3636
addMove,
3737
createGameState,
38+
isCounting,
39+
gameHasEnded,
3840
} from "./state.js"
3941
import {
4042
Board,
@@ -78,6 +80,16 @@ export function Game() {
7880
return
7981
}
8082
intervalIdRef.current = setInterval(() => {
83+
let gameState = gameStateRef.current
84+
if (!gameState) {
85+
return
86+
}
87+
if (isCounting(gameState) || gameHasEnded(gameState)) {
88+
if (intervalIdRef.current) {
89+
clearInterval(intervalIdRef.current)
90+
}
91+
return
92+
}
8193
let t = timeRemainingRef.current - 1
8294
setTimeRemaining(t)
8395
if (t <= 0) {

src/main/client/src/feature/game/GamePanel.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ function WarpControls({gameState, setGameState, activePlay}) {
142142
</div>
143143
{!activePlay && (
144144
<Button title="Forward"
145-
disabled={activePlay || isAtEnd(gameState)}
145+
disabled={isAtEnd(gameState)}
146146
onClick={() => setGameState(moveForward(gameState))}
147147
className="py-1 px-2">
148148
Forward

src/main/client/src/feature/game/state.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ export function gameHasEnded({state, moves}) {
119119
}
120120

121121
export function isReviewing(baseState) {
122+
if (gameHasEnded(baseState)) {
123+
return true
124+
}
122125
return baseState.viewPos < baseState.queueLength
123126
}
124127

@@ -174,10 +177,11 @@ function goToEnd(baseState) {
174177
let queueLength = baseState.queueLength
175178
let baseBoard = baseState.baseBoard
176179
let historyBoard = baseState.historyBoard
180+
let counting = baseState.state === STATE_COUNTING
177181
for (let i = baseState.viewPos; i < moves.length; i++) {
178182
let move = moves[i]
179183
let previousMove = getMove(moves, i - 1)
180-
let [, updated] = updateBoardState(baseBoard, previousMove, move, !baseState.winnerByTime)
184+
let [, updated] = updateBoardState(baseBoard, previousMove, move, counting)
181185
baseBoard = updated
182186
}
183187
let board = rehydrate(baseBoard, historyBoard)
@@ -202,8 +206,12 @@ export function addMove(baseState, move) {
202206
})
203207
}
204208
if (action === "end") {
209+
let updated = resetCounting(baseBoard)
205210
return produce(baseState, (draft) => {
206211
draft.moves.push(move)
212+
draft.state = 0
213+
draft.baseBoard = updated
214+
draft.board = rehydrate(updated, historyBoard)
207215
})
208216
}
209217
let [storedMove, updated, forbidden] = updateBoardState(baseBoard, previousMove, move, counting)
@@ -216,9 +224,9 @@ export function addMove(baseState, move) {
216224
draft.moves.push(storedMove)
217225
draft.lastMove = action === "pass" ? undefined : storedMove
218226
draft.baseBoard = updated
219-
let updatedFinalBoard = counting ? historyBoard : updateHistoryBoard(historyBoard, move)
220-
draft.historyBoard = updatedFinalBoard
221-
draft.board = rehydrate(updated, updatedFinalBoard)
227+
let updatedHistoryBoard = counting ? historyBoard : updateHistoryBoard(historyBoard, move)
228+
draft.historyBoard = updatedHistoryBoard
229+
draft.board = rehydrate(updated, updatedHistoryBoard)
222230
draft.forbidden = forbidden
223231
if (action === "pass" && previousMove?.action === "pass") {
224232
draft.state = STATE_COUNTING

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ public void action(Move move, Principal p) {
9393
int color = getColorFromGameState(game);
9494
Chat chat = chats.get(game.id());
9595
if (game.timesetting() != 0
96+
&& !game.isCounting()
97+
&& !game.gameHasEnded()
9698
&& System.currentTimeMillis() > game.updated() + game.timesetting() * 1000L) {
9799
games.put(game.withTimeoutState());
98100
String text = color == Board.W ? "B+Time" : "W+Time";

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ private Game updateInternal(Move move) {
5454
return toBuilder().build();
5555
}
5656
if (isCounting()) {
57-
int[][] updated = move.resetCounting() ?
57+
int[][] updated = (move.pass() || move.resetCounting()) ?
5858
Toggle.resetCounting(board) :
5959
Toggle.toggleStonesAt(board, move.x(), move.y());
6060
return toBuilder()
@@ -208,7 +208,7 @@ public boolean isForbidden(Move move) {
208208
public String getScore() {
209209
int w = 0;
210210
int b = 0;
211-
for (int y = 0; y < board().length; y++) {
211+
for (int y = 0; y < board.length; y++) {
212212
for (int x = 0; x < board[y].length; x++) {
213213
int color = board[y][x];
214214
if ((color & (Board.W | Board.TERRITORY_W)) != 0) {

0 commit comments

Comments
 (0)