Game { public boolean processString(String str) { if (handleCommand(str)) { return true; } if (getGameState() != GameState.ALIVE) { return false; } Move m = TextIO.stringToMove(pos, str); if (m == null) { return false; } UndoInfo ui = new UndoInfo(); pos.makeMove(m, ui); TextIO.fixupEPSquare(pos); while (currentMove < moveList.size()) { moveList.remove(currentMove); uiInfoList.remove(currentMove); drawOfferList.remove(currentMove); } moveList.add(m); uiInfoList.add(ui); drawOfferList.add(pendingDrawOffer); pendingDrawOffer = false; currentMove++; return true; } Game(Player whitePlayer, Player blackPlayer); boolean processString(String str); final String getGameStateString(); Move getLastMove(); GameState getGameState(); boolean haveDrawOffer(); List<String> getPosHistory(); final String getMoveListString(boolean compressed); final String getPGNResultString(); ArrayList<Position> getHistory(); public Position pos; }
@Test public void testProcessString() throws ChessParseError { System.out.println("processString"); Game game = new Game(new HumanPlayer(), new HumanPlayer()); assertEquals(TextIO.startPosFEN, TextIO.toFEN(game.pos)); boolean res = game.processString("Nf3"); assertEquals(true, res); assertEquals(1, game.pos.halfMoveClock); assertEquals(1, game.pos.fullMoveCounter); res = game.processString("d5"); assertEquals(true, res); assertEquals(0, game.pos.halfMoveClock); assertEquals(2, game.pos.fullMoveCounter); res = game.processString("undo"); assertEquals(true, res); assertEquals(1, game.pos.halfMoveClock); assertEquals(1, game.pos.fullMoveCounter); res = game.processString("undo"); assertEquals(true, res); assertEquals(TextIO.startPosFEN, TextIO.toFEN(game.pos)); res = game.processString("undo"); assertEquals(true, res); assertEquals(TextIO.startPosFEN, TextIO.toFEN(game.pos)); res = game.processString("redo"); assertEquals(true, res); assertEquals(1, game.pos.halfMoveClock); assertEquals(1, game.pos.fullMoveCounter); res = game.processString("redo"); assertEquals(true, res); assertEquals(0, game.pos.halfMoveClock); assertEquals(2, game.pos.fullMoveCounter); res = game.processString("redo"); assertEquals(true, res); assertEquals(0, game.pos.halfMoveClock); assertEquals(2, game.pos.fullMoveCounter); res = game.processString("new"); assertEquals(true, res); assertEquals(TextIO.startPosFEN, TextIO.toFEN(game.pos)); String fen = "8/8/8/4k3/8/8/2p5/5K2 b - - 47 68"; Position pos = TextIO.readFEN(fen); res = game.processString("setpos " + fen); assertEquals(true, res); assertEquals(pos, game.pos); res = game.processString("junk"); assertEquals(false, res); }