Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
		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;
		}
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        public int getHeuristicValue(Object state)
        {
            NQueensBoard board = (NQueensBoard)state;

            return(board.getSize() - board.getNumberOfQueensOnBoard());
        }
Ejemplo n.º 5
0
 private bool allQueensPlaced()
 {
     return(board.getNumberOfQueensOnBoard() == board.getSize());
 }