private NQueensBoard placeQueenAt(int row, int column, NQueensBoard parentBoard) { NQueensBoard newBoard = new NQueensBoard(parentBoard.getSize()); ArrayList queenPositionsOnParentBoard = parentBoard.getQueenPositions(); queenPositionsOnParentBoard.Add(new XYLocation(row, column)); newBoard.setBoard(queenPositionsOnParentBoard); return(newBoard); }
private NQueensBoard placeQueenAt(int row, int column, NQueensBoard parentBoard) { NQueensBoard newBoard = new NQueensBoard(parentBoard.getSize()); ArrayList queenPositionsOnParentBoard = parentBoard.getQueenPositions(); queenPositionsOnParentBoard.Add(new XYLocation(row, column)); newBoard.setBoard(queenPositionsOnParentBoard); return newBoard; }
public ArrayList getSuccessors(Object state) { ArrayList successors = new ArrayList(); NQueensBoard board = (NQueensBoard)state; int numQueens = board.getNumberOfQueensOnBoard(); int boardSize = board.getSize(); for (int i = 0; i < boardSize; i++) { if (!(board.isSquareUnderAttack(new XYLocation(numQueens, i)))) { NQueensBoard child = placeQueenAt(numQueens, i, board); successors.Add(new Successor("placeQueenAt " + numQueens + " " + i, child)); } } return(successors); }
public int getHeuristicValue(Object state) { NQueensBoard board = (NQueensBoard)state; return(board.getSize() - board.getNumberOfQueensOnBoard()); }
private bool allQueensPlaced() { return(board.getNumberOfQueensOnBoard() == board.getSize()); }