Game { public GameState getGameState() { MoveGen.MoveList moves = new MoveGen().pseudoLegalMoves(pos); MoveGen.removeIllegal(pos, moves); if (moves.size == 0) { if (MoveGen.inCheck(pos)) { return pos.whiteMove ? GameState.BLACK_MATE : GameState.WHITE_MATE; } else { return pos.whiteMove ? GameState.WHITE_STALEMATE : GameState.BLACK_STALEMATE; } } if (insufficientMaterial()) { return GameState.DRAW_NO_MATE; } if (resignState != GameState.ALIVE) { return resignState; } return drawState; } 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 testGetGameState() { System.out.println("getGameState"); Game game = new Game(new HumanPlayer(), new HumanPlayer()); assertEquals(Game.GameState.ALIVE, game.getGameState()); game.processString("f3"); game.processString("e5"); game.processString("g4"); game.processString("Qh4"); assertEquals(Game.GameState.BLACK_MATE, game.getGameState()); game.processString("setpos 5k2/5P2/5K2/8/8/8/8/8 b - - 0 1"); assertEquals(Game.GameState.BLACK_STALEMATE, game.getGameState()); }