예제 #1
0
        public ArrayList getSuccessors(Object state)
        {
            EightPuzzleBoard board      = (EightPuzzleBoard)state;
            ArrayList        successors = new ArrayList();

            if (board.canMoveGap(EightPuzzleBoard.UP))
            {
                EightPuzzleBoard newBoard = copyOf(board);
                newBoard.moveGapUp();
                successors.Add(new Successor(EightPuzzleBoard.UP, newBoard));
            }
            if (board.canMoveGap(EightPuzzleBoard.DOWN))
            {
                EightPuzzleBoard newBoard = copyOf(board);
                newBoard.moveGapDown();
                successors.Add(new Successor(EightPuzzleBoard.DOWN, newBoard));
            }
            if (board.canMoveGap(EightPuzzleBoard.LEFT))
            {
                EightPuzzleBoard newBoard = copyOf(board);
                newBoard.moveGapLeft();
                successors.Add(new Successor(EightPuzzleBoard.LEFT, newBoard));
            }
            if (board.canMoveGap(EightPuzzleBoard.RIGHT))
            {
                EightPuzzleBoard newBoard = copyOf(board);
                newBoard.moveGapRight();
                successors.Add(new Successor(EightPuzzleBoard.RIGHT, newBoard));
            }
            return(successors);
        }
예제 #2
0
        private EightPuzzleBoard copyOf(EightPuzzleBoard board)
        {
            EightPuzzleBoard newBoard = new EightPuzzleBoard();

            newBoard.setBoard(board.getPositions());
            return(newBoard);
        }
예제 #3
0
        public int getHeuristicValue(Object state)
        {
            EightPuzzleBoard board = (EightPuzzleBoard)state;
            int retVal             = 0;

            for (int i = 1; i < 9; i++)
            {
                XYLocation loc = board.getLocationOf(i);
                retVal += evaluateManhattanDistanceOf(i, loc);
            }
            return(retVal);
        }
예제 #4
0
        private int getNumberOfMisplacedTiles(EightPuzzleBoard board)
        {
            int numberOfMisplacedTiles = 0;

            if (!(board.getLocationOf(0).Equals(new XYLocation(0, 0))))
            {
                numberOfMisplacedTiles++;
            }
            if (!(board.getLocationOf(1).Equals(new XYLocation(0, 1))))
            {
                numberOfMisplacedTiles++;
            }
            if (!(board.getLocationOf(2).Equals(new XYLocation(0, 2))))
            {
                numberOfMisplacedTiles++;
            }
            if (!(board.getLocationOf(3).Equals(new XYLocation(1, 0))))
            {
                numberOfMisplacedTiles++;
            }
            if (!(board.getLocationOf(4).Equals(new XYLocation(1, 1))))
            {
                numberOfMisplacedTiles++;
            }
            if (!(board.getLocationOf(5).Equals(new XYLocation(1, 2))))
            {
                numberOfMisplacedTiles++;
            }
            if (!(board.getLocationOf(6).Equals(new XYLocation(2, 0))))
            {
                numberOfMisplacedTiles++;
            }
            if (!(board.getLocationOf(7).Equals(new XYLocation(2, 1))))
            {
                numberOfMisplacedTiles++;
            }
            if (!(board.getLocationOf(8).Equals(new XYLocation(2, 2))))
            {
                numberOfMisplacedTiles++;
            }
            return(numberOfMisplacedTiles);
        }
		private int getNumberOfMisplacedTiles(EightPuzzleBoard board) 
		{
			int numberOfMisplacedTiles = 0;
			if (!(board.getLocationOf(0).Equals(new XYLocation(0, 0)))) 
			{
				numberOfMisplacedTiles++;
			}
			if (!(board.getLocationOf(1).Equals(new XYLocation(0, 1)))) 
			{
				numberOfMisplacedTiles++;
			}
			if (!(board.getLocationOf(2).Equals(new XYLocation(0, 2)))) 
			{
				numberOfMisplacedTiles++;
			}
			if (!(board.getLocationOf(3).Equals(new XYLocation(1, 0)))) 
			{
				numberOfMisplacedTiles++;
			}
			if (!(board.getLocationOf(4).Equals(new XYLocation(1, 1)))) 
			{
				numberOfMisplacedTiles++;
			}
			if (!(board.getLocationOf(5).Equals(new XYLocation(1, 2)))) 
			{
				numberOfMisplacedTiles++;
			}
			if (!(board.getLocationOf(6).Equals(new XYLocation(2, 0)))) 
			{
				numberOfMisplacedTiles++;
			}
			if (!(board.getLocationOf(7).Equals(new XYLocation(2, 1)))) 
			{
				numberOfMisplacedTiles++;
			}
			if (!(board.getLocationOf(8).Equals(new XYLocation(2, 2)))) 
			{
				numberOfMisplacedTiles++;
			}
			return numberOfMisplacedTiles;
		}
예제 #6
0
        public override bool Equals(Object o)
        {
            if (this == o)
            {
                return(true);
            }
            if ((o == null) || (this.GetType() != o.GetType()))
            {
                return(false);
            }
            EightPuzzleBoard aBoard = (EightPuzzleBoard)o;

            for (int i = 0; i < 8; i++)
            {
                if (this.getPositionOf(i) != aBoard.getPositionOf(i))
                {
                    return(false);
                }
            }
            return(true);
        }
예제 #7
0
        public int getHeuristicValue(Object state)
        {
            EightPuzzleBoard board = (EightPuzzleBoard)state;

            return(getNumberOfMisplacedTiles(board));
        }
예제 #8
0
		private EightPuzzleBoard copyOf(EightPuzzleBoard board) 
		{
			EightPuzzleBoard newBoard = new EightPuzzleBoard();
			newBoard.setBoard(board.getPositions());
			return newBoard;
		}
예제 #9
0
        public bool isGoalState(Object state)
        {
            EightPuzzleBoard board = (EightPuzzleBoard)state;

            return(board.Equals(goal));
        }