fix: NCWF-4 Token Issues (#8)
Co-authored-by: Lala, Shahd <Shahd.Lala@sybit.de> Co-authored-by: shahdlala66 <shahd.lala66@gmail.com> Reviewed-on: #8
This commit was merged in pull request #8.
This commit is contained in:
@@ -24,23 +24,28 @@ export class GameCompletionService {
|
||||
return { isFinished: true, message };
|
||||
}
|
||||
|
||||
isTimeOut(state: GameState | null): boolean {
|
||||
if (!state?.clock) return false;
|
||||
return state.clock.whiteRemainingMs <= 0 || state.clock.blackRemainingMs <= 0;
|
||||
}
|
||||
|
||||
private buildCompletionMessage(status: GameStatus, state: GameState, game: GameFull): string {
|
||||
const winner = state.winner === 'white' ? game.white.displayName : state.winner === 'black' ? game.black.displayName : null;
|
||||
const loser = state.winner === 'white' ? game.black.displayName : state.winner === 'black' ? game.white.displayName : null;
|
||||
|
||||
switch (status) {
|
||||
case 'checkmate':
|
||||
const winner = state.winner === 'white' ? game.white.displayName : game.black.displayName;
|
||||
return `Checkmate! ${winner} wins!`;
|
||||
return winner ? `Checkmate — ${winner} wins!` : 'Checkmate!';
|
||||
case 'stalemate':
|
||||
return 'Stalemate! The game is a draw.';
|
||||
return 'Stalemate — draw!';
|
||||
case 'resign':
|
||||
const resignedPlayer = state.winner === 'white' ? game.black.displayName : game.white.displayName;
|
||||
const resignedWinner = state.winner === 'white' ? game.white.displayName : game.black.displayName;
|
||||
return `${resignedPlayer} resigned. ${resignedWinner} wins!`;
|
||||
return loser && winner ? `${loser} resigned — ${winner} wins!` : 'Resigned.';
|
||||
case 'draw':
|
||||
return 'Draw! The game ended in a draw.';
|
||||
return 'Draw by agreement.';
|
||||
case 'insufficientMaterial':
|
||||
return 'Insufficient material! The game is a draw.';
|
||||
return 'Draw — insufficient material.';
|
||||
default:
|
||||
return 'Game ended!';
|
||||
return 'Game over.';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user