Skip to content

Commit

Permalink
fix review after timeout
Browse files Browse the repository at this point in the history
do not show count result while reviewing
  • Loading branch information
h908714124 committed Oct 14, 2024
1 parent b390570 commit 1ee463e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
12 changes: 12 additions & 0 deletions src/main/client/src/feature/game/Game.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import {
initialState,
addMove,
createGameState,
isCounting,
gameHasEnded,
} from "./state.js"
import {
Board,
Expand Down Expand Up @@ -78,6 +80,16 @@ export function Game() {
return
}
intervalIdRef.current = setInterval(() => {
let gameState = gameStateRef.current
if (!gameState) {
return
}
if (isCounting(gameState) || gameHasEnded(gameState)) {
if (intervalIdRef.current) {
clearInterval(intervalIdRef.current)
}
return
}
let t = timeRemainingRef.current - 1
setTimeRemaining(t)
if (t <= 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/client/src/feature/game/GamePanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ function WarpControls({gameState, setGameState, activePlay}) {
</div>
{!activePlay && (
<Button title="Forward"
disabled={activePlay || isAtEnd(gameState)}
disabled={isAtEnd(gameState)}
onClick={() => setGameState(moveForward(gameState))}
className="py-1 px-2">
Forward
Expand Down
16 changes: 12 additions & 4 deletions src/main/client/src/feature/game/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ export function gameHasEnded({state, moves}) {
}

export function isReviewing(baseState) {
if (gameHasEnded(baseState)) {
return true
}
return baseState.viewPos < baseState.queueLength
}

Expand Down Expand Up @@ -174,10 +177,11 @@ function goToEnd(baseState) {
let queueLength = baseState.queueLength
let baseBoard = baseState.baseBoard
let historyBoard = baseState.historyBoard
let counting = baseState.state === STATE_COUNTING
for (let i = baseState.viewPos; i < moves.length; i++) {
let move = moves[i]
let previousMove = getMove(moves, i - 1)
let [, updated] = updateBoardState(baseBoard, previousMove, move, !baseState.winnerByTime)
let [, updated] = updateBoardState(baseBoard, previousMove, move, counting)
baseBoard = updated
}
let board = rehydrate(baseBoard, historyBoard)
Expand All @@ -202,8 +206,12 @@ export function addMove(baseState, move) {
})
}
if (action === "end") {
let updated = resetCounting(baseBoard)
return produce(baseState, (draft) => {
draft.moves.push(move)
draft.state = 0
draft.baseBoard = updated
draft.board = rehydrate(updated, historyBoard)
})
}
let [storedMove, updated, forbidden] = updateBoardState(baseBoard, previousMove, move, counting)
Expand All @@ -216,9 +224,9 @@ export function addMove(baseState, move) {
draft.moves.push(storedMove)
draft.lastMove = action === "pass" ? undefined : storedMove
draft.baseBoard = updated
let updatedFinalBoard = counting ? historyBoard : updateHistoryBoard(historyBoard, move)
draft.historyBoard = updatedFinalBoard
draft.board = rehydrate(updated, updatedFinalBoard)
let updatedHistoryBoard = counting ? historyBoard : updateHistoryBoard(historyBoard, move)
draft.historyBoard = updatedHistoryBoard
draft.board = rehydrate(updated, updatedHistoryBoard)
draft.forbidden = forbidden
if (action === "pass" && previousMove?.action === "pass") {
draft.state = STATE_COUNTING
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/bernd/GameController.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ public void action(Move move, Principal p) {
int color = getColorFromGameState(game);
Chat chat = chats.get(game.id());
if (game.timesetting() != 0
&& !game.isCounting()
&& !game.gameHasEnded()
&& System.currentTimeMillis() > game.updated() + game.timesetting() * 1000L) {
games.put(game.withTimeoutState());
String text = color == Board.W ? "B+Time" : "W+Time";
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/bernd/model/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private Game updateInternal(Move move) {
return toBuilder().build();
}
if (isCounting()) {
int[][] updated = move.resetCounting() ?
int[][] updated = (move.pass() || move.resetCounting()) ?
Toggle.resetCounting(board) :
Toggle.toggleStonesAt(board, move.x(), move.y());
return toBuilder()
Expand Down Expand Up @@ -208,7 +208,7 @@ public boolean isForbidden(Move move) {
public String getScore() {
int w = 0;
int b = 0;
for (int y = 0; y < board().length; y++) {
for (int y = 0; y < board.length; y++) {
for (int x = 0; x < board[y].length; x++) {
int color = board[y][x];
if ((color & (Board.W | Board.TERRITORY_W)) != 0) {
Expand Down

0 comments on commit 1ee463e

Please sign in to comment.