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 07:35:39 +00:00
|
|
|
const newState = gamesInProgress[game.id].makeMove(move);
|
|
|
|
return {...newState}
|
2020-01-31 05:03:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|