Game { private boolean insufficientMaterial() { if (pos.pieceTypeBB[Piece.WQUEEN] != 0) return false; if (pos.pieceTypeBB[Piece.WROOK] != 0) return false; if (pos.pieceTypeBB[Piece.WPAWN] != 0) return false; if (pos.pieceTypeBB[Piece.BQUEEN] != 0) return false; if (pos.pieceTypeBB[Piece.BROOK] != 0) return false; if (pos.pieceTypeBB[Piece.BPAWN] != 0) return false; int wb = Long.bitCount(pos.pieceTypeBB[Piece.WBISHOP]); int wn = Long.bitCount(pos.pieceTypeBB[Piece.WKNIGHT]); int bb = Long.bitCount(pos.pieceTypeBB[Piece.BBISHOP]); int bn = Long.bitCount(pos.pieceTypeBB[Piece.BKNIGHT]); if (wb + wn + bb + bn <= 1) { return true; } if (wn + bn == 0) { long bMask = pos.pieceTypeBB[Piece.WBISHOP] | pos.pieceTypeBB[Piece.BBISHOP]; if (((bMask & BitBoard.maskDarkSq) == 0) || ((bMask & BitBoard.maskLightSq) == 0)) return true; } 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 testInsufficientMaterial() { System.out.println("insufficientMaterial"); Game game = new Game(new HumanPlayer(), new HumanPlayer()); assertEquals(Game.GameState.ALIVE, game.getGameState()); game.processString("setpos 4k3/8/8/8/8/8/8/4K3 w - - 0 1"); assertEquals(Game.GameState.DRAW_NO_MATE, game.getGameState()); final int a1 = Position.getSquare(0, 0); game.pos.setPiece(a1, Piece.WROOK); assertEquals(Game.GameState.ALIVE, game.getGameState()); game.pos.setPiece(a1, Piece.BQUEEN); assertEquals(Game.GameState.ALIVE, game.getGameState()); game.pos.setPiece(a1, Piece.WPAWN); assertEquals(Game.GameState.ALIVE, game.getGameState()); game.pos.setPiece(a1, Piece.BKNIGHT); assertEquals(Game.GameState.DRAW_NO_MATE, game.getGameState()); game.pos.setPiece(a1, Piece.WBISHOP); assertEquals(Game.GameState.DRAW_NO_MATE, game.getGameState()); final int c1 = Position.getSquare(2, 0); game.pos.setPiece(c1, Piece.WKNIGHT); assertEquals(Game.GameState.ALIVE, game.getGameState()); game.pos.setPiece(c1, Piece.BBISHOP); assertEquals(Game.GameState.DRAW_NO_MATE, game.getGameState()); game.pos.setPiece(c1, Piece.WBISHOP); assertEquals(Game.GameState.DRAW_NO_MATE, game.getGameState()); final int b2 = Position.getSquare(1, 1); game.pos.setPiece(b2, Piece.WBISHOP); assertEquals(Game.GameState.DRAW_NO_MATE, game.getGameState()); game.pos.setPiece(b2, Piece.BBISHOP); assertEquals(Game.GameState.DRAW_NO_MATE, game.getGameState()); final int b3 = Position.getSquare(1, 2); game.pos.setPiece(b3, Piece.WBISHOP); assertEquals(Game.GameState.ALIVE, game.getGameState()); game.processString("setpos 8/8/8/8/8/8/8/K3nnk1 w - - 0 1"); assertEquals(Game.GameState.ALIVE, game.getGameState()); }