diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2018-03-10 13:07:17 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2018-03-10 13:07:17 +0900 |
| commit | a8d086596f3b549d77128b89f0519267bbf35d9e (patch) | |
| tree | e8b9208d787d0a6f02a1afd354bcb68fbbf238f3 /src | |
| parent | Implement othello map editing (diff) | |
| download | sharkey-a8d086596f3b549d77128b89f0519267bbf35d9e.tar.gz sharkey-a8d086596f3b549d77128b89f0519267bbf35d9e.tar.bz2 sharkey-a8d086596f3b549d77128b89f0519267bbf35d9e.zip | |
:v:
Diffstat (limited to 'src')
| -rw-r--r-- | src/api/stream/othello-game.ts | 30 | ||||
| -rw-r--r-- | src/common/othello/core.ts | 9 |
2 files changed, 39 insertions, 0 deletions
diff --git a/src/api/stream/othello-game.ts b/src/api/stream/othello-game.ts index 5c826e5b41..9ca4864a54 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 62ec34f41c..fc432b2ced 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'; + } + } } /** |