From a8d086596f3b549d77128b89f0519267bbf35d9e Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 10 Mar 2018 13:07:17 +0900 Subject: [PATCH] :v: --- src/api/stream/othello-game.ts | 30 ++++++++++++++++++++++++++++++ src/common/othello/core.ts | 9 +++++++++ 2 files changed, 39 insertions(+) diff --git a/src/api/stream/othello-game.ts b/src/api/stream/othello-game.ts index 5c826e5b4..9ca4864a5 100644 --- a/src/api/stream/othello-game.ts +++ b/src/api/stream/othello-game.ts @@ -113,6 +113,36 @@ export default function(request: websocket.request, connection: websocket.connec } }); + //#region 盤面に最初から石がないなどして始まった瞬間に勝敗が決定する場合があるのでその処理 + const o = new Othello(freshGame.settings.map, { + isLlotheo: freshGame.settings.is_llotheo + }); + + if (o.isEnded) { + let winner; + if (o.winner == 'black') { + winner = freshGame.black == 1 ? freshGame.user1_id : freshGame.user2_id; + } else if (o.winner == 'white') { + winner = freshGame.black == 1 ? freshGame.user2_id : freshGame.user1_id; + } else { + winner = null; + } + + await Game.update({ + _id: gameId + }, { + $set: { + is_ended: true, + winner_id: winner + } + }); + + publishOthelloGameStream(gameId, 'ended', { + winner_id: winner + }); + } + //#endregion + publishOthelloGameStream(gameId, 'started', await pack(gameId)); }, 3000); } diff --git a/src/common/othello/core.ts b/src/common/othello/core.ts index 62ec34f41..fc432b2ce 100644 --- a/src/common/othello/core.ts +++ b/src/common/othello/core.ts @@ -49,6 +49,15 @@ export default class Othello { b: this.blackP, w: this.whiteP }]; + + // ゲームが始まった時点で片方の色の石しかないか、始まった時点で勝敗が決定するようなマップの場合がある + if (this.canPutSomewhere('black').length == 0) { + if (this.canPutSomewhere('white').length == 0) { + this.turn = null; + } else { + this.turn = 'white'; + } + } } /**