Game { public boolean haveDrawOffer() { if (currentMove > 0) { return drawOfferList.get(currentMove - 1); } else { return false; } } 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 testHaveDrawOffer() { System.out.println("haveDrawOffer"); Game game = new Game(new HumanPlayer(), new HumanPlayer()); assertEquals(false, game.haveDrawOffer()); boolean res = game.processString("e4"); assertEquals(true, res); assertEquals(false, game.haveDrawOffer()); res = game.processString("draw offer e5"); assertEquals(true, res); assertEquals(true, game.haveDrawOffer()); assertEquals(Game.GameState.ALIVE, game.getGameState()); assertEquals(Piece.BPAWN, game.pos.getPiece(Position.getSquare(4, 4))); res = game.processString("draw offer Nf3"); assertEquals(true, res); assertEquals(true, game.haveDrawOffer()); assertEquals(Game.GameState.ALIVE, game.getGameState()); assertEquals(Piece.WKNIGHT, game.pos.getPiece(Position.getSquare(5, 2))); res = game.processString("Nc6"); assertEquals(true, res); assertEquals(false, game.haveDrawOffer()); assertEquals(Game.GameState.ALIVE, game.getGameState()); assertEquals(Piece.BKNIGHT, game.pos.getPiece(Position.getSquare(2, 5))); res = game.processString("draw offer Bb5"); assertEquals(true, res); assertEquals(true, game.haveDrawOffer()); assertEquals(Game.GameState.ALIVE, game.getGameState()); assertEquals(Piece.WBISHOP, game.pos.getPiece(Position.getSquare(1, 4))); res = game.processString("draw accept"); assertEquals(true, res); assertEquals(Game.GameState.DRAW_AGREE, game.getGameState()); res = game.processString("undo"); assertEquals(true, res); assertEquals(Piece.EMPTY, game.pos.getPiece(Position.getSquare(1, 4))); assertEquals(false, game.haveDrawOffer()); assertEquals(Game.GameState.ALIVE, game.getGameState()); res = game.processString("undo"); assertEquals(true, res); assertEquals(Piece.EMPTY, game.pos.getPiece(Position.getSquare(2, 5))); assertEquals(true, game.haveDrawOffer()); assertEquals(Game.GameState.ALIVE, game.getGameState()); res = game.processString("redo"); assertEquals(true, res); assertEquals(Piece.BKNIGHT, game.pos.getPiece(Position.getSquare(2, 5))); assertEquals(false, game.haveDrawOffer()); assertEquals(Game.GameState.ALIVE, game.getGameState()); res = game.processString("redo"); assertEquals(true, res); assertEquals(Piece.WBISHOP, game.pos.getPiece(Position.getSquare(1, 4))); assertEquals(true, game.haveDrawOffer()); assertEquals(Game.GameState.ALIVE, game.getGameState()); res = game.processString("redo"); assertEquals(true, res); assertEquals(true, game.haveDrawOffer()); assertEquals(Game.GameState.ALIVE, game.getGameState()); res = game.processString("new"); assertEquals(true, res); assertEquals(false, game.haveDrawOffer()); assertEquals(Game.GameState.ALIVE, game.getGameState()); res = game.processString("draw offer e5"); assertEquals(true, res); assertEquals(TextIO.startPosFEN, TextIO.toFEN(game.pos)); res = game.processString("e4"); assertEquals(true, res); assertEquals(true, game.haveDrawOffer()); assertEquals(Piece.WPAWN, game.pos.getPiece(Position.getSquare(4, 3))); game.processString("new"); game.processString("e4"); game.processString("draw offer e4"); assertEquals(true, game.pendingDrawOffer); game.processString("undo"); game.processString("redo"); game.processString("e5"); assertEquals(true,game.pos.whiteMove); assertEquals(false, game.haveDrawOffer()); }