@@ -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
34293456function drawaccepted ( userid : string , engine : GameBase , game : FullGame , simultaneous : boolean ) {
0 commit comments