2018-03-09 18:29:27 +09:00
|
|
|
import $ from 'cafy';
|
2018-03-29 20:32:18 +09:00
|
|
|
import OthelloGame, { pack } from '../../../../../models/othello-game';
|
2018-04-02 12:58:53 +09:00
|
|
|
import Othello from '../../../../../othello/core';
|
2018-03-09 18:29:27 +09:00
|
|
|
|
|
|
|
|
module.exports = (params, user) => new Promise(async (res, rej) => {
|
2018-03-29 14:48:47 +09:00
|
|
|
// Get 'gameId' parameter
|
|
|
|
|
const [gameId, gameIdErr] = $(params.gameId).id().$;
|
|
|
|
|
if (gameIdErr) return rej('invalid gameId param');
|
2018-03-09 18:29:27 +09:00
|
|
|
|
2018-03-29 14:48:47 +09:00
|
|
|
const game = await OthelloGame.findOne({ _id: gameId });
|
2018-03-09 18:29:27 +09:00
|
|
|
|
|
|
|
|
if (game == null) {
|
|
|
|
|
return rej('game not found');
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-10 22:30:38 +09:00
|
|
|
const o = new Othello(game.settings.map, {
|
2018-03-29 14:48:47 +09:00
|
|
|
isLlotheo: game.settings.isLlotheo,
|
|
|
|
|
canPutEverywhere: game.settings.canPutEverywhere,
|
|
|
|
|
loopedBoard: game.settings.loopedBoard
|
2018-03-10 22:30:38 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
game.logs.forEach(log => {
|
|
|
|
|
o.put(log.color, log.pos);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const packed = await pack(game, user);
|
|
|
|
|
|
|
|
|
|
res(Object.assign({
|
|
|
|
|
board: o.board,
|
|
|
|
|
turn: o.turn
|
|
|
|
|
}, packed));
|
2018-03-09 18:29:27 +09:00
|
|
|
});
|