Skip to content

Commit

Permalink
pass needs to be staged by time handler
Browse files Browse the repository at this point in the history
  • Loading branch information
merowin committed Jan 4, 2024
1 parent 22c91ef commit 8202395
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions packages/server/src/time-control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { getTimeoutService } from "./index";
* properties for being a config with time control.
*/
export function HasTimeControlConfig(
game_config: unknown,
game_config: unknown
): game_config is IConfigWithTimeControl {
return (
game_config &&
Expand All @@ -29,7 +29,7 @@ export function HasTimeControlConfig(
* properties for being a time control config.
*/
export function ValidateTimeControlConfig(
time_control_config: unknown,
time_control_config: unknown
): time_control_config is ITimeControlConfig {
return (
time_control_config &&
Expand All @@ -44,7 +44,7 @@ export function ValidateTimeControlConfig(
* properties for being a basic time control data object.
*/
export function ValidateTimeControlBase(
time_control: unknown,
time_control: unknown
): time_control is ITimeControlBase {
return (
time_control &&
Expand All @@ -60,7 +60,7 @@ export function ValidateTimeControlBase(
*/
export function GetInitialTimeControl(
variant: string,
config: object,
config: object
): ITimeControlBase | null {
if (!HasTimeControlConfig(config)) return null;

Expand All @@ -76,7 +76,7 @@ export interface ITimeHandler {
*/
initialState(
variant: string,
config: IConfigWithTimeControl,
config: IConfigWithTimeControl
): ITimeControlBase;

/**
Expand All @@ -88,7 +88,7 @@ export interface ITimeHandler {
game: GameResponse,
game_obj: AbstractGame<unknown, unknown>,
playerNr: number,
move: string,
move: string
): ITimeControlBase;

/**
Expand All @@ -106,7 +106,7 @@ class TimeHandlerSequentialMoves implements ITimeHandler {

initialState(
variant: string,
config: IConfigWithTimeControl,
config: IConfigWithTimeControl
): ITimeControlBase {
const numPlayers = makeGameObject(variant, config).numPlayers();

Expand Down Expand Up @@ -144,7 +144,7 @@ class TimeHandlerSequentialMoves implements ITimeHandler {
handleMove(
game: GameResponse,
game_obj: AbstractGame<unknown, unknown>,
playerNr: number,
playerNr: number
): ITimeControlBase {
const config = game.config as IConfigWithTimeControl;

Expand Down Expand Up @@ -176,7 +176,7 @@ class TimeHandlerSequentialMoves implements ITimeHandler {
this._timeoutService.scheduleTimeout(
game.id,
player,
timeControl.forPlayer[player].remainingTimeMS,
timeControl.forPlayer[player].remainingTimeMS
);
});

Expand Down Expand Up @@ -234,7 +234,7 @@ class TimeHandlerParallelMoves implements ITimeHandler {

initialState(
variant: string,
config: IConfigWithTimeControl,
config: IConfigWithTimeControl
): TimeControlParallel {
const numPlayers = makeGameObject(variant, config).numPlayers();

Expand Down Expand Up @@ -274,7 +274,7 @@ class TimeHandlerParallelMoves implements ITimeHandler {
game: GameResponse,
game_obj: AbstractGame<unknown, unknown>,
playerNr: number,
move: string,
move: string
): ITimeControlBase {
const config = game.config as IConfigWithTimeControl;

Expand All @@ -289,7 +289,7 @@ class TimeHandlerParallelMoves implements ITimeHandler {
const playerTimeControl = timeControl.forPlayer[playerNr];
const timestamp = new Date();

if (!Object.keys(game_obj.specialMoves()).includes(move)) {
if (!(move === "resign") && !(move === "timeout")) {
timeControl.forPlayer[playerNr].stagedMoveAt = timestamp;

if (
Expand All @@ -298,7 +298,7 @@ class TimeHandlerParallelMoves implements ITimeHandler {
timestamp.getTime() - playerTimeControl.onThePlaySince.getTime()
) {
throw new Error(
"you can't change your move because it would reduce your remaining time to zero.",
"you can't change your move because it would reduce your remaining time to zero."
);
}
}
Expand All @@ -316,7 +316,7 @@ class TimeHandlerParallelMoves implements ITimeHandler {
.nextToPlay()
.every(
(player_nr) =>
timeControl.forPlayer[player_nr].stagedMoveAt !== null,
timeControl.forPlayer[player_nr].stagedMoveAt !== null
)
) {
for (const player_nr of game_obj.nextToPlay()) {
Expand All @@ -335,7 +335,7 @@ class TimeHandlerParallelMoves implements ITimeHandler {
this._timeoutService.scheduleTimeout(
game.id,
player_nr,
timeControl.forPlayer[player_nr].remainingTimeMS,
timeControl.forPlayer[player_nr].remainingTimeMS
);
playerData.onThePlaySince = timestamp;
playerData.stagedMoveAt = null;
Expand Down

0 comments on commit 8202395

Please sign in to comment.