Esempio n. 1
0
  /**
   * getLegalMovesTestManyPossibilities: This sets a black rook at spot g4 with a random board that
   * has 11 possible moves including taking a white pawn Also checks that you can move in every
   * direction multiple spaces.
   */
  @Test
  public void getLegalMovesTestManyMoves() {
    Rook rookPiece = new Rook('b', "g4");
    List<String> legalMoves =
        rookPiece.getLegalMoves("1nbqkbnr/2Pppppp/p7/1p6/6r1/8/P1PPPPPP/RNBQKBNR w KQkq -");
    String[] legalMovesArray = new String[legalMoves.size()];
    legalMoves.toArray(legalMovesArray);
    assertNotNull(legalMoves);

    String[] expected = new String[11];
    expected[0] = "1nbqkbnr/2Pppppp/p7/1p4r1/8/8/P1PPPPPP/RNBQKBNR w KQkq -";
    expected[1] = "1nbqkbnr/2Pppppp/p5r1/1p6/8/8/P1PPPPPP/RNBQKBNR w KQkq -";
    expected[2] = "1nbqkbnr/2Pppppp/p7/1p6/8/6r1/P1PPPPPP/RNBQKBNR w KQkq -";
    expected[3] = "1nbqkbnr/2Pppppp/p7/1p6/7r/8/P1PPPPPP/RNBQKBNR w KQkq -";
    expected[4] = "1nbqkbnr/2Pppppp/p7/1p6/5r2/8/P1PPPPPP/RNBQKBNR w KQkq -";
    expected[5] = "1nbqkbnr/2Pppppp/p7/1p6/4r3/8/P1PPPPPP/RNBQKBNR w KQkq -";
    expected[6] = "1nbqkbnr/2Pppppp/p7/1p6/3r4/8/P1PPPPPP/RNBQKBNR w KQkq -";
    expected[7] = "1nbqkbnr/2Pppppp/p7/1p6/2r5/8/P1PPPPPP/RNBQKBNR w KQkq -";
    expected[8] = "1nbqkbnr/2Pppppp/p7/1p6/1r6/8/P1PPPPPP/RNBQKBNR w KQkq -";
    expected[9] = "1nbqkbnr/2Pppppp/p7/1p6/r7/8/P1PPPPPP/RNBQKBNR w KQkq -";
    expected[10] = "1nbqkbnr/2Pppppp/p7/1p6/8/8/P1PPPPrP/RNBQKBNR w KQkq -";
    Arrays.sort(legalMovesArray);
    Arrays.sort(expected);
    assertArrayEquals(expected, legalMovesArray);
  }
Esempio n. 2
0
 @Test
 public void basicMovesTest() {
   this.board.getSquare('e', 4).setPiece(wRook);
   this.board.getSquare('d', 5).setPiece(bRook);
   SquareList wSquares = wRook.whereToMove(board, board.getSquare('e', 4));
   boolean ok = true;
   ArrayList<String> squares = new ArrayList();
   squares.add("e5");
   squares.add("e3");
   squares.add("a4");
   squares.add("b4");
   squares.add("c4");
   squares.add("d4");
   squares.add("h4");
   squares.add("g4");
   squares.add("f4");
   squares.add("e7");
   squares.add("e6");
   for (Square square : wSquares.getList()) {
     String s = square.toString();
     if (!squares.contains(s)) {
       ok = false;
     }
   }
   if (squares.size() != wSquares.size()) {
     ok = false;
   }
   assertEquals(true, ok);
   assertEquals(0, bRook.whereToMove(board, board.getSquare('h', 8)).size());
 }
Esempio n. 3
0
 /**
  * getLegalMovesTestNoMoves: This check that if the piece has no legal moves, the return list
  * should be empty
  */
 @Test
 public void getLegalMovesTestNoMoves() {
   Rook rookPiece = new Rook('b', "a8");
   List<String> legalMoves =
       rookPiece.getLegalMoves("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq -");
   assertNotNull(legalMoves);
   assertEquals(legalMoves.size(), 0);
 }
Esempio n. 4
0
  /**
   * getLegalMovesTest: This sets a black rook at spot b7 with a random board that has 3 possible
   * moves including taking a white pawn.
   */
  @Test
  public void getLegalMovesTestFewMoves() {
    Rook rookPiece = new Rook('b', "b7");
    List<String> legalMoves =
        rookPiece.getLegalMoves("1nbqkbnr/1rPppppp/p7/1p6/8/8/P1PPPPPP/RNBQKBNR w KQkq -");
    String[] legalMovesArray = new String[legalMoves.size()];
    legalMoves.toArray(legalMovesArray);
    assertNotNull(legalMoves);

    String[] expected = new String[3];
    expected[0] = "1nbqkbnr/2Pppppp/pr6/1p6/8/8/P1PPPPPP/RNBQKBNR w KQkq -";
    expected[1] = "1nbqkbnr/r1Pppppp/p7/1p6/8/8/P1PPPPPP/RNBQKBNR w KQkq -";
    expected[2] = "1nbqkbnr/2rppppp/p7/1p6/8/8/P1PPPPPP/RNBQKBNR w KQkq -";

    assertArrayEquals(expected, legalMovesArray);
  }
  public PromotionDialog(Square location) {
    // Creating promotion dialog
    if (Board.getBoard().isWhiteMove()) {
      setTitle(
          "Promotion for " + Board.getBoard().getWhitePlayer().getName() + " - Choose a figure");
    } else {
      setTitle(
          "Promotion for " + Board.getBoard().getBlackPlayer().getName() + " - Choose a figure");
    }

    this.location = location;
    JPanel pane = (JPanel) getContentPane();
    pane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    pane.setLayout(new GridLayout(1, 4, 10, 10));

    JButton rookButton = new JButton();
    rookButton.setIcon(rook.getFigureIcon());
    rookButton.addActionListener(this);
    rookButton.setFocusPainted(false);
    pane.add(rookButton);

    JButton knightButton = new JButton();
    knightButton.setIcon(knight.getFigureIcon());
    knightButton.addActionListener(this);
    knightButton.setFocusPainted(false);
    pane.add(knightButton);

    JButton bishopButton = new JButton();
    bishopButton.setIcon(bishop.getFigureIcon());
    bishopButton.addActionListener(this);
    bishopButton.setFocusPainted(false);
    pane.add(bishopButton);

    JButton queenButton = new JButton();
    queenButton.setIcon(queen.getFigureIcon());
    queenButton.addActionListener(this);
    queenButton.setFocusPainted(false);
    pane.add(queenButton);

    // Has to choose
    setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
    // Set to be always on top
    setAlwaysOnTop(true); // http://goo.gl/h3vnma
    // Makes dialog customizable
    setModal(true);
    // Disable resize
    setResizable(false);
    // Makes the dialog like an application (with swing components, etc.)
    setModalityType(ModalityType.APPLICATION_MODAL);
    // Size of dialog
    setMinimumSize(new Dimension(300, 100));
    // Centering by default
    setLocationRelativeTo(null);
    pack();
    setVisible(true);
  }
 @Override
 public void actionPerformed(ActionEvent e) {
   // If figure icon matches the the button selected's icon - insert figure into board
   Icon icon = ((JButton) e.getSource()).getIcon();
   if (icon.equals(rook.getFigureIcon())) {
     location.setFigure(rook);
   } else if (icon.equals(knight.getFigureIcon())) {
     location.setFigure(knight);
   } else if (icon.equals(bishop.getFigureIcon())) {
     location.setFigure(bishop);
   } else if (icon.equals(queen.getFigureIcon())) {
     location.setFigure(queen);
   }
   // Delete frame when clicked
   dispose();
 }
Esempio n. 7
0
 public static long getAttackBitmap(long[][] bitboard, Piece piece) {
   return Rook.getAttackBitmap(bitboard, piece) | Bishop.getAttackBitmap(bitboard, piece);
 }