Ejemplo n.º 1
0
		public bool isGoalState(Object state) 
		{

			board = (NQueensBoard) state;
			return (allQueensPlaced() && allQueenPositionsHaveZeroAttacks(board
				.getQueenPositions()));
		}
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
        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.º 4
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.º 5
0
        public override bool Equals(Object o)
        {
            if (this == o)
            {
                return(true);
            }
            if ((o == null) || (this.GetType() != o.GetType()))
            {
                return(false);
            }
            NQueensBoard aBoard = (NQueensBoard)o;
            bool         retVal = true;
            ArrayList    locs   = getQueenPositions();

            foreach (XYLocation loc in locs)
            {
                if (!(aBoard.queenExistsAt(loc)))
                {
                    retVal = false;
                }
            }
            return(retVal);
        }
Ejemplo n.º 6
0
        public int getHeuristicValue(Object state)
        {
            NQueensBoard board = (NQueensBoard)state;

            return(board.getSize() - board.getNumberOfQueensOnBoard());
        }
Ejemplo n.º 7
0
 public bool isGoalState(Object state)
 {
     board = (NQueensBoard)state;
     return(allQueensPlaced() && allQueenPositionsHaveZeroAttacks(board
                                                                  .getQueenPositions()));
 }