2020-01-31 05:03:27 +00:00
|
|
|
const Game = require('./Game').Game;
|
|
|
|
|
|
|
|
const gamesInProgress = { }
|
|
|
|
|
|
|
|
const storeGame = (game) => {
|
|
|
|
gamesInProgress[game.id] = new Game(game);
|
|
|
|
}
|
|
|
|
|
|
|
|
const initGame = (game) => {
|
|
|
|
gamesInProgress[game.id] = new Game(game)
|
|
|
|
return gamesInProgress[game.id].initGame();
|
|
|
|
}
|
|
|
|
|
2020-01-31 06:50:34 +00:00
|
|
|
const makeMove = (game, move) => {
|
2020-01-31 05:03:27 +00:00
|
|
|
let meta = {};
|
2020-01-31 06:50:34 +00:00
|
|
|
const board = gamesInProgress[game.id].makeMove(move);
|
2020-01-31 05:03:27 +00:00
|
|
|
return {board, meta}
|
|
|
|
}
|
|
|
|
|
|
|
|
const getBoard = (gameId) => {
|
|
|
|
return gamesInProgress[gameId].getBoardState();
|
|
|
|
}
|
|
|
|
|
|
|
|
const getAllGames = () => {
|
|
|
|
return gamesInProgress;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
2020-01-31 06:50:34 +00:00
|
|
|
makeMove,
|
2020-01-31 05:03:27 +00:00
|
|
|
getAllGames,
|
|
|
|
getBoard,
|
|
|
|
initGame
|
|
|
|
}
|