Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 1x 1x 21x 1x 1x 21x 1x 21x 9x 9x 9x 9x 1x 9x 7x 9x 3x 3x 3x 9x 21x 4x 4x 4x 4x 4x 4x 4x 4x 4x 21x 21x 4x 4x 4x 4x 4x 4x 21x 6x 6x 21x 4x 4x 4x 21x 2x 2x 2x 21x 1x 1x 1x 21x 4x 4x 4x 4x 4x 4x 4x 4x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 2x 2x 2x 2x | import { boardBuilder } from './boardBuilder.js'; import { createRegistry } from './registry.js'; import { messageManager } from './message.js'; import { PieceColorEnum } from '../piece/pieceColorEnum.js'; import { GameStatusEnum } from './gameStatusEnum.js'; import { randomPlayer } from './randomPlayer.js'; function createGame(uuidGame) { let uuid = uuidGame; let turn = PieceColorEnum.White; let board = boardBuilder().usingInitialPieceDisposition().build(); let registry = createRegistry(board); let status = GameStatusEnum.ongoing; function getBoard() { return board; } function getUuid() { return uuid; } function undo() { registry.undo(); } function redo() { registry.redo(); } function getRandomMovement() { return messageManager.createMessage(randomPlayer.getMovement(board)); } function play(movementOrigin, movementDestination, playerColor) { if (status === GameStatusEnum.finished) return messageManager.createMessage('Game finished.'); if (playerColor != turn) return messageManager.createErrorMessage('Not ' + playerColor.getLiteral() + "'s turn to play."); if (board.getAllCoordinatesByColor(turn).length == 0){ endGame(); return messageManager.createMessage(playerColor.name + 's win.'); } return performTurn(movementOrigin, movementDestination); } function performTurn (movementOrigin, movementDestination) { let error = board.tryMove(movementOrigin, movementDestination, turn); if(error != undefined) return messageManager.createErrorMessage(error); if(!turn.isWhite()) { registry.register(); } advanceTurn(); updateStatus(); return messageManager.createMessage(); } function advanceTurn() { turn = turn.getOppositeColor(); } function updateStatus() { if(board.isOnCheckMate(turn) || board.isStalemate(turn)) { endGame(); } } function endGame() { status = GameStatusEnum.finished; } function isGameFinished() { return status === GameStatusEnum.finished; } function getStatus() { return messageManager.createMessage({status: status}); } function getBoardResponse() { return messageManager.createMessage(board.getBoardPieceNames()); } function undoableRedoable() { return messageManager.createMessage({ isUndoable: registry.isUndoable(), isRedoable: registry.isRedoable() }); } return{ play, isGameFinished, getStatus, getBoardResponse, undoableRedoable, getBoard, getUuid, getRandomMovement, undo, redo } } export { createGame } |