diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2018-03-10 13:42:26 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2018-03-10 13:42:26 +0900 |
| commit | c3a2330569e69ca81e929b6b3416bea05d0247a3 (patch) | |
| tree | 37e5033ec1d8a0d4f048b9451aa83a3c38922d52 /src/api | |
| parent | :v: (diff) | |
| download | sharkey-c3a2330569e69ca81e929b6b3416bea05d0247a3.tar.gz sharkey-c3a2330569e69ca81e929b6b3416bea05d0247a3.tar.bz2 sharkey-c3a2330569e69ca81e929b6b3416bea05d0247a3.zip | |
#1225
Diffstat (limited to 'src/api')
| -rw-r--r-- | src/api/stream/othello-game.ts | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/api/stream/othello-game.ts b/src/api/stream/othello-game.ts index 9ca4864a54..cc936805ba 100644 --- a/src/api/stream/othello-game.ts +++ b/src/api/stream/othello-game.ts @@ -3,6 +3,7 @@ import * as redis from 'redis'; import Game, { pack } from '../models/othello-game'; import { publishOthelloGameStream } from '../event'; import Othello from '../../common/othello/core'; +import * as maps from '../../common/othello/maps'; export default function(request: websocket.request, connection: websocket.connection, subscriber: redis.RedisClient, user: any): void { const gameId = request.resourceURL.query.game; @@ -105,16 +106,25 @@ export default function(request: websocket.request, connection: websocket.connec bw = freshGame.settings.bw as number; } + function getRandomMap() { + const mapCount = Object.entries(maps).length; + const rnd = Math.floor(Math.random() * mapCount); + return Object.entries(maps).find((x, i) => i == rnd)[1].data; + } + + const map = freshGame.settings.map != null ? freshGame.settings.map : getRandomMap(); + await Game.update({ _id: gameId }, { $set: { started_at: new Date(), is_started: true, - black: bw + black: bw, + 'settings.map': map } }); //#region 盤面に最初から石がないなどして始まった瞬間に勝敗が決定する場合があるのでその処理 - const o = new Othello(freshGame.settings.map, { + const o = new Othello(map, { isLlotheo: freshGame.settings.is_llotheo }); |