Skip to content

Commit 188ca3c

Browse files
committed
Run starttournaments twice a day. Expand resign and timeout functions to work properly if the game is not yet over.
1 parent 0749b14 commit 188ca3c

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

api/abstractplay.ts

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3388,12 +3388,26 @@ function resign(userid: any, engine: GameBase, game: FullGame) {
33883388
throw new Error(`${userid} isn't playing in this game!`);
33893389
engine.resign(player + 1);
33903390
game.state = engine.serialize();
3391-
game.toMove = "";
3392-
game.winner = engine.winner;
3393-
game.numMoves = engine.state().stack.length - 1; // stack has an entry for the board before any moves are made
3391+
game.state = engine.serialize();
3392+
if (engine.gameover) {
3393+
game.toMove = "";
3394+
game.winner = engine.winner;
3395+
game.numMoves = engine.state().stack.length - 1; // stack has an entry for the board before any moves are made
3396+
} else {
3397+
const flags = gameinfo.get(game.metaGame).flags;
3398+
const simultaneous = flags !== undefined && flags.includes('simultaneous');
3399+
if (simultaneous) {
3400+
game.toMove = game.players.map((p, i) => ! (engine as GameBaseSimultaneous).isEliminated(i + 1));
3401+
} else {
3402+
if ( (! ("currplayer" in engine)) || (engine.currplayer === undefined) || (engine.currplayer === null) || (typeof engine.currplayer !== "number") ) {
3403+
throw new Error("The engine must provide a current player for `applyMove()` to be able to function.");
3404+
}
3405+
game.toMove = `${engine.currplayer - 1}`;
3406+
}
3407+
}
33943408
}
33953409

3396-
function timeout(userid: string, engine: GameBase, game: FullGame) {
3410+
function timeout(userid: string, engine: GameBase|GameBaseSimultaneous, game: FullGame) {
33973411
if (game.toMove === '')
33983412
throw new Error("Can't timeout a game that has already ended");
33993413
// Find player that timed out
@@ -3421,9 +3435,22 @@ function timeout(userid: string, engine: GameBase, game: FullGame) {
34213435
}
34223436
engine.timeout(loser + 1);
34233437
game.state = engine.serialize();
3424-
game.toMove = "";
3425-
game.winner = engine.winner;
3426-
game.numMoves = engine.state().stack.length - 1; // stack has an entry for the board before any moves are made
3438+
if (engine.gameover) {
3439+
game.toMove = "";
3440+
game.winner = engine.winner;
3441+
game.numMoves = engine.state().stack.length - 1; // stack has an entry for the board before any moves are made
3442+
} else {
3443+
const flags = gameinfo.get(game.metaGame).flags;
3444+
const simultaneous = flags !== undefined && flags.includes('simultaneous');
3445+
if (simultaneous) {
3446+
game.toMove = game.players.map((p, i) => ! (engine as GameBaseSimultaneous).isEliminated(i + 1));
3447+
} else {
3448+
if ( (! ("currplayer" in engine)) || (engine.currplayer === undefined) || (engine.currplayer === null) || (typeof engine.currplayer !== "number") ) {
3449+
throw new Error("The engine must provide a current player for `applyMove()` to be able to function.");
3450+
}
3451+
game.toMove = `${engine.currplayer - 1}`;
3452+
}
3453+
}
34273454
}
34283455

34293456
function drawaccepted(userid: string, engine: GameBase, game: FullGame, simultaneous: boolean) {

serverless.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,5 +239,5 @@ functions:
239239
name: abstractplay-${self:provider.stage}-starttournaments
240240
description: Checks if any tournaments are ready to start (and starts or cancels them)
241241
enabled: ${self:custom.scheduleEnabled.${self:provider.stage}}
242-
# 10am UTC every morning
243-
schedule: cron(0 10 * * ? *)
242+
# 10am and 10pm UTC every morning
243+
schedule: cron(0 10,22 * * ? *)

0 commit comments

Comments
 (0)