示例#1
0
        /// <summary>
        /// get goal state (the end of the maze)
        /// </summary>
        /// <returns>The goal state</returns>
        public Astate getGoalState()
        {
            Position goal = maze.getGoalPosition();
            Astate   ans  = new MazeState(null, goal);

            return(ans);
        }
示例#2
0
        /// <summary>
        /// get initial state (the state of the maze)
        /// </summary>
        /// <returns>The initial state</returns>
        public Astate getInitialState()
        {
            Position start = maze.getStartPosition();
            Astate   ans   = new MazeState(null, start);

            return(ans);
        }
示例#3
0
        /// <summary>
        /// in order to find the solution we need to go backwards from the goal position to the start position
        /// </summary>
        /// <param name="v"></param>
        /// <returns></returns>
        private Solution backtrack(Astate v)
        {
            Solution  sol    = new Solution();
            MazeState parent = (MazeState)v;

            while (parent != null)
            {
                sol.addState(parent);
                parent = (MazeState)parent.cameFrom;
            }
            sol.Reverse();
            return(sol);
        }
示例#4
0
        /// <summary>
        /// Returns a List containing all the possible (valid) successors of a gives AState
        /// </summary>
        /// <param name="state"></param>
        /// <returns> List of successors  </returns>
        public List <AState> getAllSuccessors(AState state)
        {
            List <AState> successors = new List <AState>();
            MazeState     mState     = (MazeState)state;
            int           col        = mState.getX();
            int           row        = mState.getY();
            int           floor      = mState.getZ();

            //Right (Col ++)
            if (col + 1 < m_maze3d.getWidth() && m_maze3d.isPath(col + 1, row, floor))
            {
                successors.Add(new MazeState(state, col + 1, row, floor));
            }
            //Left (Col --)
            if (col - 1 >= 0 && m_maze3d.isPath(col - 1, row, floor))
            {
                successors.Add(new MazeState(state, col - 1, row, floor));
            }
            //Up (Row ++)
            if (row + 1 < m_maze3d.getHeight() && m_maze3d.isPath(col, row + 1, floor))
            {
                successors.Add(new MazeState(state, col, row + 1, floor));
            }
            //Down (Row --)
            if (row - 1 >= 0 && m_maze3d.isPath(col, row - 1, floor))
            {
                successors.Add(new MazeState(state, col, row - 1, floor));
            }
            //Ascend (Floor ++)
            if (floor + 1 < m_maze3d.getLevels() && m_maze3d.isPath(col, row, floor + 1))
            {
                successors.Add(new MazeState(state, col, row, floor + 1));
            }
            //Descend (Floor --)
            if (floor - 1 >= 0 && m_maze3d.isPath(col, row, floor - 1))
            {
                successors.Add(new MazeState(state, col, row, floor - 1));
            }
            return(successors);
        }