private void drawChessPattern() { clearBoard(); for (int i = 0; i < getBoardSize(); i++) { for (int j = 0; j < getBoardSize(); j++) { if ((i + j) % 2 == 0) colorSquare(i, j, Color.white); else colorSquare(i, j, Color.black); } } }
/* * returns false if no move has been made previously * * it undo's the previous move */ protected static boolean undoMove() { if (movesStack.size() <= 1) return false; Move currentPos = movesStack.pop(); Move prevPos = movesStack.peek(); if (!tourDraw || !tourRunning) return true; // Undo the current position if ((currentPos.row + currentPos.col) % 2 == 0) colorSquare(currentPos, Color.white); else colorSquare(currentPos, Color.black); if ((prevPos.row + prevPos.col) % 2 == 0) colorSquare(prevPos, Color.white); else colorSquare(prevPos, Color.black); drawKnight(prevPos); // delay(delayTime); return true; }
/** * This function simulates a move of the current knight. * * @param nextPos : Next position of the knight * @return: True if position is legal; false otherwise */ protected static boolean makeMove(Move nextPos) // -----need { if (movesStack.size() >= boardSize * boardSize || !isNextMoveValid(nextPos)) return false; Move currentPos = (!movesStack.empty()) ? movesStack.peek() : null; movesStack.push(nextPos); movesCounter++; updatePerformanceCounter(movesCounter); if (!tourDraw || !tourRunning) return true; if (currentPos != null) { // Draw the number of the last position colorSquare(currentPos, Color.yellow); drawNumber(currentPos, movesStack.size() - 1); } drawKnight(nextPos); // delay(1); return true; }
private static void colorSquare(Move m, Color color) { colorSquare(m.row, m.col, color); }