private void movePiece(Piece p, Square destinationSquare, Square originSquare) { p.setVisible(false); originSquare.removeAll(); destinationSquare.add(p); p.setSquare(destinationSquare); p.setVisible(true); }
public String castleQueenside(Square candidateSquare) { if (piece == 0) { int row; int column; if (color == 1) { row = 1; column = 1; } else { row = 8; column = 1; } int cell = square.getCellFromCoord(row, column); Square sq = (Square) board.getComponent(cell); Piece pc = (Piece) sq.getComponent(0); int newCell; if (pc.getColor() == 1) { newCell = square.getCellFromCoord(1, 4); } else { newCell = square.getCellFromCoord(8, 4); } Square newSquare = (Square) board.getComponent(newCell); // move rook movePiece(pc, newSquare, sq); return ("0-0-0"); } return ""; }
/** *************************************************************************************** */ public void selectCell() { if (p != null) { p.highlight = true; } }
/** *************************************************************************************** */ public void deSelect() { if (p != null) { p.deHighlight(); } }
private void setListForKing() { moveList.clear(); squareList.clear(); int row = square.getRow(); int column = square.getColumn(); int c1, c2, c3, c4, c5, c6, c7, c8; String cell1, cell2, cell3, cell4, cell5, cell6, cell7, cell8; if (((row + 1) < 9) && (column + 1) < 9) { c1 = square.getCellFromCoord(row + 1, column + 1); cell1 = square.getPositionWithArg(c1); Square s = (Square) board.getComponent(c1); if (s.getComponentCount() > 0) { Piece p = (Piece) s.getComponent(0); if (p.getColor() != color) { moveList.add(cell1); squareList.add(s); } } else { moveList.add(cell1); squareList.add(s); } } if (((row + 1) < 9) && (column - 1) > 0) { c2 = square.getCellFromCoord(row + 1, column - 1); cell2 = square.getPositionWithArg(c2); Square s = (Square) board.getComponent(c2); if (s.getComponentCount() > 0) { Piece p = (Piece) s.getComponent(0); if (p.getColor() != color) { moveList.add(cell2); squareList.add(s); } } else { moveList.add(cell2); squareList.add(s); } } if ((row + 1) < 9) { c3 = square.getCellFromCoord(row + 1, column); cell3 = square.getPositionWithArg(c3); Square s = (Square) board.getComponent(c3); if (s.getComponentCount() > 0) { Piece p = (Piece) s.getComponent(0); if (p.getColor() != color) { moveList.add(cell3); squareList.add(s); } } else { moveList.add(cell3); squareList.add(s); } } if ((column + 1) < 9) { c4 = square.getCellFromCoord(row, column + 1); cell4 = square.getPositionWithArg(c4); Square s = (Square) board.getComponent(c4); if (s.getComponentCount() > 0) { Piece p = (Piece) s.getComponent(0); if (p.getColor() != color) { moveList.add(cell4); squareList.add(s); } } else { moveList.add(cell4); squareList.add(s); } } if ((column - 1) > 0) { c5 = square.getCellFromCoord(row, column - 1); cell5 = square.getPositionWithArg(c5); Square s = (Square) board.getComponent(c5); if (s.getComponentCount() > 0) { Piece p = (Piece) s.getComponent(0); if (p.getColor() != color) { moveList.add(cell5); squareList.add(s); } } else { moveList.add(cell5); squareList.add(s); } } if (((row - 1) > 0) && (column - 1) > 0) { c6 = square.getCellFromCoord(row - 1, column - 1); cell6 = square.getPositionWithArg(c6); Square s = (Square) board.getComponent(c6); if (s.getComponentCount() > 0) { Piece p = (Piece) s.getComponent(0); if (p.getColor() != color) { moveList.add(cell6); squareList.add(s); } } else { moveList.add(cell6); squareList.add(s); } } if (((row - 1) > 0) && (column + 1) < 9) { c7 = square.getCellFromCoord(row - 1, column + 1); cell7 = square.getPositionWithArg(c7); Square s = (Square) board.getComponent(c7); if (s.getComponentCount() > 0) { Piece p = (Piece) s.getComponent(0); if (p.getColor() != color) { moveList.add(cell7); squareList.add(s); } } else { moveList.add(cell7); squareList.add(s); } } if ((row - 1) > 0) { c8 = square.getCellFromCoord(row - 1, column); cell8 = square.getPositionWithArg(c8); Square s = (Square) board.getComponent(c8); if (s.getComponentCount() > 0) { Piece p = (Piece) s.getComponent(0); if (p.getColor() != color) { moveList.add(cell8); squareList.add(s); } } else { moveList.add(cell8); squareList.add(s); } } if (queensideClear()) { int cell = square.getCellFromCoord(1, 3); String c = square.getPositionWithArg(cell); moveList.add(c); cell = square.getCellFromCoord(8, 3); c = square.getPositionWithArg(cell); moveList.add(c); } if (kingsideClear()) { int cell = square.getCellFromCoord(1, 7); String c = square.getPositionWithArg(cell); moveList.add(c); cell = square.getCellFromCoord(8, 7); c = square.getPositionWithArg(cell); moveList.add(c); } }
private void setListForKnight() { moveList.clear(); squareList.clear(); /*switch(square.getCellNumber()) { case 56 : moveList.add("c2");moveList.add("b3"); break; case 57 : moveList.add("d2");moveList.add("a3");moveList.add("c3"); break; case 58 : moveList.add("a2");moveList.add("e2");moveList.add("b3");moveList.add("d3"); break; case 59 : moveList.add("b2");moveList.add("f2");moveList.add("c3");moveList.add("e3"); break; case 60 : moveList.add("c2");moveList.add("g2");moveList.add("d3");moveList.add("f3"); break; case 61 : moveList.add("d2");moveList.add("h2");moveList.add("e3");moveList.add("g3"); break; case 62 : moveList.add("e2");moveList.add("f3");moveList.add("h3"); break; case 63 : moveList.add("f2");moveList.add("g3"); break; case 48 : moveList.add("c1");moveList.add("c3");moveList.add("b4"); break; case 49 : moveList.add("d1");moveList.add("d3");moveList.add("a4");moveList.add("c4"); break; case 50 : moveList.add("a1");moveList.add("e1");moveList.add("a3");moveList.add("e3");moveList.add("b4");moveList.add("d4"); break; case 51 : moveList.add("b1");moveList.add("f1");moveList.add("b3");moveList.add("f3");moveList.add("c4");moveList.add("e4"); break; case 52 : moveList.add("c1");moveList.add("g1");moveList.add("c3");moveList.add("g3");moveList.add("d4");moveList.add("f4"); break; case 53 : moveList.add("d1");moveList.add("h1");moveList.add("d3");moveList.add("h3");moveList.add("e4");moveList.add("g4"); break; case 54 : moveList.add("e1");moveList.add("e3");moveList.add("f4");moveList.add("h4"); break; case 55 : moveList.add("f1");moveList.add("f3");moveList.add("g4"); break; case 40 : moveList.add("b1");moveList.add("c2");moveList.add("c4");moveList.add("b5"); break; case 41 : moveList.add("a1");moveList.add("c1");moveList.add("d2");moveList.add("d4");moveList.add("a5");moveList.add("c5"); break; case 42 : moveList.add("b1");moveList.add("d1");moveList.add("a2");moveList.add("e2");moveList.add("a4");moveList.add("e4");moveList.add("b5");moveList.add("d5"); break; case 43 : moveList.add("c1");moveList.add("e1");moveList.add("b2");moveList.add("f2");moveList.add("b4");moveList.add("f4");moveList.add("c5");moveList.add("e5"); break; case 44 : moveList.add("d1");moveList.add("f1");moveList.add("c2");moveList.add("g2");moveList.add("c4");moveList.add("g4");moveList.add("d5");moveList.add("f5"); break; case 45 : moveList.add("e1");moveList.add("g1");moveList.add("d2");moveList.add("h2");moveList.add("d4");moveList.add("h4");moveList.add("e5");moveList.add("g5"); break; case 46 : moveList.add("f1");moveList.add("h1");moveList.add("e2");moveList.add("e4");moveList.add("f5");moveList.add("h5"); break; case 47 : moveList.add("g1");moveList.add("f2");moveList.add("f4");moveList.add("g5"); break; case 32 : moveList.add("b2");moveList.add("c3");moveList.add("c5");moveList.add("b6"); break; case 33 : moveList.add("a2");moveList.add("c2");moveList.add("d3");moveList.add("d5");moveList.add("a6");moveList.add("c6"); break; case 34 : moveList.add("b2");moveList.add("d2");moveList.add("a3");moveList.add("e3");moveList.add("a5");moveList.add("e5");moveList.add("b6");moveList.add("d6"); break; case 35 : moveList.add("c2");moveList.add("e2");moveList.add("b3");moveList.add("f3");moveList.add("b5");moveList.add("f5");moveList.add("c6");moveList.add("e6"); break; case 36 : moveList.add("d2");moveList.add("f2");moveList.add("c3");moveList.add("g3");moveList.add("c5");moveList.add("g5");moveList.add("d6");moveList.add("f6"); break; case 37 : moveList.add("e2");moveList.add("g2");moveList.add("d3");moveList.add("h3");moveList.add("d5");moveList.add("h5");moveList.add("e6");moveList.add("g6"); break; case 38 : moveList.add("f2");moveList.add("h2");moveList.add("e3");moveList.add("e5");moveList.add("f6");moveList.add("h6"); break; case 39 : moveList.add("g2");moveList.add("f3");moveList.add("f5");moveList.add("g6"); break; case 24 : moveList.add("b3");moveList.add("c4");moveList.add("c6");moveList.add("b7"); break; case 25 : moveList.add("a3");moveList.add("c3");moveList.add("d4");moveList.add("d6");moveList.add("a7");moveList.add("c7"); break; case 26 : moveList.add("b3");moveList.add("d3");moveList.add("a4");moveList.add("e4");moveList.add("a6");moveList.add("e6");moveList.add("b7");moveList.add("d7"); break; case 27 : moveList.add("c3");moveList.add("e3");moveList.add("b4");moveList.add("f4");moveList.add("b6");moveList.add("f6");moveList.add("c7");moveList.add("e7"); break; case 28 : moveList.add("d3");moveList.add("f3");moveList.add("c4");moveList.add("g4");moveList.add("c6");moveList.add("g6");moveList.add("d7");moveList.add("f7"); break; case 29 : moveList.add("e3");moveList.add("g3");moveList.add("d4");moveList.add("h4");moveList.add("d6");moveList.add("h6");moveList.add("e7");moveList.add("g7"); break; case 30 : moveList.add("f3");moveList.add("h3");moveList.add("e4");moveList.add("e6");moveList.add("f7");moveList.add("h7"); break; case 31 : moveList.add("g3");moveList.add("f4");moveList.add("f6");moveList.add("g7"); break; case 16 : moveList.add("b4");moveList.add("c5");moveList.add("c7");moveList.add("b8"); break; case 17 : moveList.add("a4");moveList.add("c4");moveList.add("d5");moveList.add("d7");moveList.add("a8");moveList.add("c8"); break; case 18 : moveList.add("b4");moveList.add("d4");moveList.add("a5");moveList.add("e5");moveList.add("a7");moveList.add("e7");moveList.add("b8");moveList.add("d8"); break; case 19 : moveList.add("c4");moveList.add("e4");moveList.add("b5");moveList.add("f5");moveList.add("b7");moveList.add("f7");moveList.add("c8");moveList.add("e8"); break; case 20 : moveList.add("d4");moveList.add("f4");moveList.add("c5");moveList.add("g5");moveList.add("c7");moveList.add("g7");moveList.add("d8");moveList.add("f8"); break; case 21 : moveList.add("e4");moveList.add("g4");moveList.add("d5");moveList.add("h5");moveList.add("d7");moveList.add("h7");moveList.add("e8");moveList.add("g8"); break; case 22 : moveList.add("f4");moveList.add("h4");moveList.add("e5");moveList.add("e7");moveList.add("f8");moveList.add("h8"); break; case 23 : moveList.add("g4");moveList.add("f5");moveList.add("f7");moveList.add("g8"); break; case 8 : moveList.add("b5");moveList.add("c6");moveList.add("c8"); break; case 9 : moveList.add("a5");moveList.add("c5");moveList.add("d6");moveList.add("d8"); break; case 10 : moveList.add("b5");moveList.add("d5");moveList.add("a6");moveList.add("e6");moveList.add("a8");moveList.add("e8"); break; case 11 : moveList.add("c5");moveList.add("e5");moveList.add("b6");moveList.add("f6");moveList.add("b8");moveList.add("f8"); break; case 12 : moveList.add("d5");moveList.add("f5");moveList.add("c6");moveList.add("g6");moveList.add("c8");moveList.add("g8"); break; case 13 : moveList.add("e5");moveList.add("g5");moveList.add("d6");moveList.add("h6");moveList.add("d8");moveList.add("h8"); break; case 14 : moveList.add("f5");moveList.add("h5");moveList.add("e6");moveList.add("e8"); break; case 15 : moveList.add("g5");moveList.add("f6");moveList.add("f8"); break; case 0 : moveList.add("b6");moveList.add("c7"); break; case 1 : moveList.add("a6");moveList.add("c6");moveList.add("d7"); break; case 2 : moveList.add("b6");moveList.add("d6");moveList.add("a7");moveList.add("e7"); break; case 3 : moveList.add("c6");moveList.add("e6");moveList.add("b7");moveList.add("f7"); break; case 4 : moveList.add("d6");moveList.add("f6");moveList.add("c7");moveList.add("g7"); break; case 5 : moveList.add("e6");moveList.add("g6");moveList.add("d7");moveList.add("h7"); break; case 6 : moveList.add("f6");moveList.add("h6");moveList.add("e7");moveList.add("NS"); break; case 7 : moveList.add("g6");moveList.add("f7"); break; }*/ int row = square.getRow(); int column = square.getColumn(); int c1, c2, c3, c4, c5, c6, c7, c8; String cell1, cell2, cell3, cell4, cell5, cell6, cell7, cell8; if (((row + 1) < 9) && (column - 2) > 0) { c1 = square.getCellFromCoord(row + 1, column - 2); cell1 = square.getPositionWithArg(c1); Square s = (Square) board.getComponent(c1); if (s.getComponentCount() > 0) { Piece p = (Piece) s.getComponent(0); if (p.getColor() != color) { moveList.add(cell1); squareList.add(s); } } else { moveList.add(cell1); squareList.add(s); } } if (((row + 2) < 9) && (column - 1) > 0) { c2 = square.getCellFromCoord(row + 2, column - 1); cell2 = square.getPositionWithArg(c2); Square s = (Square) board.getComponent(c2); if (s.getComponentCount() > 0) { Piece p = (Piece) s.getComponent(0); if (p.getColor() != color) { moveList.add(cell2); squareList.add(s); } } else { moveList.add(cell2); squareList.add(s); } } if (((row + 1) < 9) && (column + 1) < 9) { c3 = square.getCellFromCoord(row + 2, column + 1); cell3 = square.getPositionWithArg(c3); Square s = (Square) board.getComponent(c3); if (s.getComponentCount() > 0) { Piece p = (Piece) s.getComponent(0); if (p.getColor() != color) { moveList.add(cell3); squareList.add(s); } } else { moveList.add(cell3); squareList.add(s); } } if (((row + 1) < 9) && (column + 2) < 9) { c4 = square.getCellFromCoord(row + 1, column + 2); cell4 = square.getPositionWithArg(c4); Square s = (Square) board.getComponent(c4); if (s.getComponentCount() > 0) { Piece p = (Piece) s.getComponent(0); if (p.getColor() != color) { moveList.add(cell4); squareList.add(s); } } else { moveList.add(cell4); squareList.add(s); } } if (((row - 1) > 0) && (column - 2) > 0) { c5 = square.getCellFromCoord(row - 1, column - 2); cell5 = square.getPositionWithArg(c5); Square s = (Square) board.getComponent(c5); if (s.getComponentCount() > 0) { Piece p = (Piece) s.getComponent(0); if (p.getColor() != color) { moveList.add(cell5); squareList.add(s); } } else { moveList.add(cell5); squareList.add(s); } } if (((row - 2) > 0) && (column - 1) > 0) { c6 = square.getCellFromCoord(row - 2, column - 1); cell6 = square.getPositionWithArg(c6); Square s = (Square) board.getComponent(c6); if (s.getComponentCount() > 0) { Piece p = (Piece) s.getComponent(0); if (p.getColor() != color) { moveList.add(cell6); squareList.add(s); } } else { moveList.add(cell6); squareList.add(s); } } if (((row - 2) > 0) && (column + 1) < 9) { c7 = square.getCellFromCoord(row - 2, column + 1); cell7 = square.getPositionWithArg(c7); Square s = (Square) board.getComponent(c7); if (s.getComponentCount() > 0) { Piece p = (Piece) s.getComponent(0); if (p.getColor() != color) { moveList.add(cell7); squareList.add(s); } } else { moveList.add(cell7); squareList.add(s); } } if (((row - 1) > 0) && (column + 2) < 9) { c8 = square.getCellFromCoord(row - 1, column + 2); cell8 = square.getPositionWithArg(c8); Square s = (Square) board.getComponent(c8); if (s.getComponentCount() > 0) { Piece p = (Piece) s.getComponent(0); if (p.getColor() != color) { moveList.add(cell8); squareList.add(s); } } else { moveList.add(cell8); squareList.add(s); } } }