From e6f68e0b9e7f97f0a7f1c9c98c5a3839c843a100 Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 13 Mar 2018 01:49:54 +0900 Subject: オセロで黒白を真理値で表現するように MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/models/othello-game.ts | 6 +++++- src/api/stream/othello-game.ts | 12 ++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) (limited to 'src/api') diff --git a/src/api/models/othello-game.ts b/src/api/models/othello-game.ts index 788fb5cba6..01c6ca6c00 100644 --- a/src/api/models/othello-game.ts +++ b/src/api/models/othello-game.ts @@ -25,7 +25,11 @@ export interface IGame { is_started: boolean; is_ended: boolean; winner_id: mongo.ObjectID; - logs: any[]; + logs: Array<{ + at: Date; + color: boolean; + pos: number; + }>; settings: { map: string[]; bw: string | number; diff --git a/src/api/stream/othello-game.ts b/src/api/stream/othello-game.ts index 87d26e2419..368baa2cb6 100644 --- a/src/api/stream/othello-game.ts +++ b/src/api/stream/othello-game.ts @@ -214,9 +214,9 @@ export default function(request: websocket.request, connection: websocket.connec if (o.isEnded) { let winner; - if (o.winner == 'black') { + if (o.winner === true) { winner = freshGame.black == 1 ? freshGame.user1_id : freshGame.user2_id; - } else if (o.winner == 'white') { + } else if (o.winner === false) { winner = freshGame.black == 1 ? freshGame.user2_id : freshGame.user1_id; } else { winner = null; @@ -263,17 +263,17 @@ export default function(request: websocket.request, connection: websocket.connec const myColor = (game.user1_id.equals(user._id) && game.black == 1) || (game.user2_id.equals(user._id) && game.black == 2) - ? 'black' - : 'white'; + ? true + : false; if (!o.canPut(myColor, pos)) return; o.put(myColor, pos); let winner; if (o.isEnded) { - if (o.winner == 'black') { + if (o.winner === true) { winner = game.black == 1 ? game.user1_id : game.user2_id; - } else if (o.winner == 'white') { + } else if (o.winner === false) { winner = game.black == 1 ? game.user2_id : game.user1_id; } else { winner = null; -- cgit v1.2.3-freya