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 boolean moveValid(Square candidateSquare) { if (piece == 0) { setListForKing(); } if (piece == 1) { setListForQueen(); } if (piece == 2) { moveList.clear(); setListForRook(); } if (piece == 3) { setListForKnight(); } if (piece == 4) { setListForBishop(); } if (piece == 5) { setListForPawn(); } if (moveList.contains(candidateSquare.getPosition())) { return true; } return false; }
public boolean queensideClear() { boolean[] flags = ChessGameDemo.getFlags(); int row = square.getRow(); int column = square.getColumn(); if ((row == 1) && (flags[0] || flags[4])) { return false; } if ((row == 8) && (flags[2] || flags[5])) { return false; } if (((row == 1) && (column == 5)) || ((row == 8) && (column == 5))) { for (int i = 1; i < 4; i++) { int r = row; int c = column - i; int cell = square.getCellFromCoord(r, c); Square sq = (Square) board.getComponent(cell); if ((sq.getComponentCount() == 1) || (r < 1)) { return false; } else if (color == 1) { if ((board.getBlackCheckList()).contains(sq.getPosition())) { return false; } } else { if ((board.getWhiteCheckList()).contains(sq.getPosition())) { return false; } } } return true; } return false; }
public String getLetter() { switch (piece) { case 0: return "K"; case 1: return "Q"; case 2: return "R"; case 3: return "N"; case 4: return "B"; default: return ((square.getPosition()).substring(0, 1)); } }
public BearSweeper() { super("BearSweeper"); Container contentPane = getContentPane(); panel = new DrawingPanel(); contentPane.add(panel, BorderLayout.CENTER); timerOn = true; time = 0; timer = new Timer(100, new TimerEventHandler()); Square.loadGraphics(); addMenus(); newGame(); timer.start(); // Loads and plays background music in a loop backgroundMusic = Applet.newAudioClip(getCompleteURL("background.wav")); backgroundMusic.loop(); } // Constructor
private void setAttacksForPawn() { moveList.clear(); squareList.clear(); if (color == 1) { int row = square.getRow(); int column = square.getColumn(); int cell1 = square.getCellFromCoord(row + 1, column + 1); int cell2 = square.getCellFromCoord(row + 1, column - 1); String c1 = square.getPositionWithArg(cell1); String c2 = square.getPositionWithArg(cell2); if ((column + 1) < 9) { moveList.add(c1); } if ((column - 1) > 0) { moveList.add(c2); } } if (color == 0) { int row = square.getRow(); int column = square.getColumn(); int cell_1 = square.getCellFromCoord(row - 1, column + 1); int cell_2 = square.getCellFromCoord(row - 1, column - 1); String c1 = square.getPositionWithArg(cell_1); String c2 = square.getPositionWithArg(cell_2); if ((column + 1) < 9) { moveList.add(c1); } if ((column - 1) > 0) { moveList.add(c2); } } }
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); } } }
private void setListForRook() { int row = square.getRow(); int column = square.getColumn(); L1: for (int i = 1; i < 8; i++) { int r = row; int c = column + i; int cell = square.getCellFromCoord(r, c); Square sq = (Square) board.getComponent(cell); if (c < 9) { if (sq.getComponentCount() == 0) { moveList.add(sq.getPositionWithArg(cell)); squareList.add(sq); } else { if (((Piece) sq.getComponent(0)).getColor() != color) { moveList.add(sq.getPositionWithArg(cell)); squareList.add(sq); } break L1; } } } L2: for (int i = 1; i < 8; i++) { int r = row; int c = column - i; int cell = square.getCellFromCoord(r, c); Square sq = (Square) board.getComponent(cell); if (c > 0) { if (sq.getComponentCount() == 0) { moveList.add(sq.getPositionWithArg(cell)); squareList.add(sq); } else { if (((Piece) sq.getComponent(0)).getColor() != color) { moveList.add(sq.getPositionWithArg(cell)); squareList.add(sq); } break L2; } } } L3: for (int i = 1; i < 8; i++) { int r = row - i; int c = column; int cell = square.getCellFromCoord(r, c); Square sq = (Square) board.getComponent(cell); if (r > 0) { if (sq.getComponentCount() == 0) { moveList.add(sq.getPositionWithArg(cell)); squareList.add(sq); } else { if (((Piece) sq.getComponent(0)).getColor() != color) { moveList.add(sq.getPositionWithArg(cell)); squareList.add(sq); } break L3; } } } L4: for (int i = 1; i < 8; i++) { int r = row + i; int c = column; int cell = square.getCellFromCoord(r, c); Square sq = (Square) board.getComponent(cell); if (r < 9) { if (sq.getComponentCount() == 0) { moveList.add(sq.getPositionWithArg(cell)); squareList.add(sq); } else { if (((Piece) sq.getComponent(0)).getColor() != color) { moveList.add(sq.getPositionWithArg(cell)); squareList.add(sq); } break L4; } } } }
private void setListForPawn() { moveList.clear(); if (color == 1) { int row = square.getRow(); int column = square.getColumn(); int cell1 = square.getCellFromCoord(row + 1, column); int cell2 = square.getCellFromCoord(row + 2, column); int cell3 = square.getCellFromCoord(row + 1, column + 1); int cell4 = square.getCellFromCoord(row + 1, column - 1); Square s1 = (Square) board.getComponent(cell1); Square s2 = (Square) board.getComponent(cell2); Square s3 = (Square) board.getComponent(cell3); Square s4 = (Square) board.getComponent(cell4); if (s1.getComponentCount() == 0) { moveList.add(s1.getPosition()); squareList.add(s1); } if (s2.getComponentCount() == 0) { moveList.add(s2.getPosition()); squareList.add(s2); } if ((s3.getComponentCount() == 1) && ((Piece) s3.getComponent(0)).getColor() == 0) { moveList.add(s3.getPosition()); squareList.add(s3); } if ((s4.getComponentCount() == 1) && ((Piece) s4.getComponent(0)).getColor() == 0) { moveList.add(s4.getPosition()); squareList.add(s4); } } if (color == 0) { int row = square.getRow(); int column = square.getColumn(); int cell1 = square.getCellFromCoord(row - 1, column); int cell2 = square.getCellFromCoord(row - 2, column); int cell3 = square.getCellFromCoord(row - 1, column + 1); int cell4 = square.getCellFromCoord(row - 1, column - 1); Square s1 = (Square) board.getComponent(cell1); Square s2 = (Square) board.getComponent(cell2); Square s3 = (Square) board.getComponent(cell3); Square s4 = (Square) board.getComponent(cell4); if (s1.getComponentCount() == 0) { moveList.add(s1.getPosition()); squareList.add(s1); } if (s2.getComponentCount() == 0) { moveList.add(s2.getPosition()); squareList.add(s2); } if ((s3.getComponentCount() == 1) && ((Piece) s3.getComponent(0)).getColor() == 1) { moveList.add(s3.getPosition()); squareList.add(s3); } if ((s4.getComponentCount() == 1) && ((Piece) s4.getComponent(0)).getColor() == 1) { moveList.add(s4.getPosition()); squareList.add(s4); } } }
// Cascade Algorithm public void cascade(Square square) { Queue<Square> queueOfSquares = new LinkedList<Square>(); queueOfSquares.add(square); while (!queueOfSquares.isEmpty()) { Square next = queueOfSquares.remove(); next.reveal(); if (square.isBear()) { gameOver(); } else if (next.adjacentBears > 0) { } else if (!next.isFlag) { next.reveal(); Square nextBeside; if (next.col - 1 > -1 && next.row - 1 > -1) { nextBeside = board[next.row - 1][next.col - 1]; if (!nextBeside.isReveal()) queueOfSquares.add(nextBeside); } if (next.row - 1 > -1) { nextBeside = board[next.row - 1][next.col]; if (!nextBeside.isReveal()) queueOfSquares.add(nextBeside); } if (next.col + 1 < length && next.row - 1 < -1) { nextBeside = board[next.row - 1][next.col + 1]; if (!nextBeside.isReveal()) queueOfSquares.add(nextBeside); } if (next.col - 1 > -1) { nextBeside = board[next.row][next.col - 1]; if (!nextBeside.isReveal()) queueOfSquares.add(nextBeside); } if (next.col + 1 < length) { nextBeside = board[next.row][next.col + 1]; if (!nextBeside.isReveal()) queueOfSquares.add(nextBeside); } if (next.col - 1 > -1 && next.row + 1 < length) { nextBeside = board[next.row + 1][next.col - 1]; if (!nextBeside.isReveal()) queueOfSquares.add(nextBeside); } if (next.row + 1 < length) { nextBeside = board[next.row + 1][next.col]; if (!nextBeside.isReveal()) queueOfSquares.add(nextBeside); } if (next.col + 1 < length && next.row + 1 < length) { nextBeside = board[next.row + 1][next.col + 1]; if (!nextBeside.isReveal()) queueOfSquares.add(nextBeside); } } } }