/// <summary>
        /// Get the neighbours of a specific state in the maze.
        /// </summary>
        /// <exception cref="Exception">
        /// There could be an exception if we check for a position which is invalid.
        /// </exception>
        /// <param name="s">
        /// The maze that we will return it's neighbours.
        /// </param>
        /// <returns>
        /// A list of states as neighbours.
        /// </returns>
        public List <State <Position> > GetAllPossibleStates(State <Position> s)
        {
            List <State <Position> > neighbors = new List <State <Position> >();
            int i = s.GetState().Row, j = s.GetState().Col;

            /**
             * Position[] locations = new Position[] {
             *  new Position(i - 1, j),
             *  new Position(i, j - 1),
             *  new Position(i, j + 1),
             *  new Position(i + 1, j)
             * };
             * foreach (Position loc in locations)
             * {
             *  try
             *  {
             *      if (maze[loc.Row, loc.Col] == CellType.Free)
             *      {
             *          //neighbors.Add(d.ContainsKey(loc) ? (d[loc]) : (d[loc] = new State<Position>(loc, 1)));
             *          //neighbors.Add(new State<Position>(loc, 1));
             *          neighbors.Add(State<Position>.GetState(loc));
             *      }
             *  }
             *  catch (IndexOutOfRangeException)
             *  {
             *  }
             * }
             */

            // The neighbor on the left
            try
            {
                if (maze[i, j - 1] == CellType.Free)
                {
                    //neighbors.Add(d.ContainsKey(loc) ? (d[loc]) : (d[loc] = new State<Position>(loc, 1)));
                    //neighbors.Add(new State<Position>(loc, 1));
                    neighbors.Add(statePool.GetState(new Position(i, j - 1), 1));
                }
            }
            catch (IndexOutOfRangeException)
            {
            }

            // The neighbor on the right
            try
            {
                if (maze[i, j + 1] == CellType.Free)
                {
                    //neighbors.Add(d.ContainsKey(loc) ? (d[loc]) : (d[loc] = new State<Position>(loc, 1)));
                    //neighbors.Add(new State<Position>(loc, 1));
                    neighbors.Add(statePool.GetState(new Position(i, j + 1), 1));
                }
            }
            catch (IndexOutOfRangeException)
            {
            }

            // The neighbor above
            try
            {
                if (maze[i - 1, j] == CellType.Free)
                {
                    //neighbors.Add(d.ContainsKey(loc) ? (d[loc]) : (d[loc] = new State<Position>(loc, 1)));
                    //neighbors.Add(new State<Position>(loc, 1));
                    neighbors.Add(statePool.GetState(new Position(i - 1, j), 1));
                }
            }
            catch (IndexOutOfRangeException)
            {
            }

            // The neighbor below
            try
            {
                if (maze[i + 1, j] == CellType.Free)
                {
                    //neighbors.Add(d.ContainsKey(loc) ? (d[loc]) : (d[loc] = new State<Position>(loc, 1)));
                    //neighbors.Add(new State<Position>(loc, 1));
                    neighbors.Add(statePool.GetState(new Position(i + 1, j), 1));
                }
            }
            catch (IndexOutOfRangeException)
            {
            }
            return(neighbors);
        }
        public static LoanApplicationState GetState(int value)
        {
            var type = _values.FirstOrDefault(a => a.Value == value);

            return(StatePool.GetState(type.Key));
        }
Exemplo n.º 3
0
 public override LoanApplicationState Cancel()
 {
     return(StatePool.GetState <CancelledState>());
 }
Exemplo n.º 4
0
 public override LoanApplicationState Confirm()
 {
     return(StatePool.GetState <ConfirmedState>());
 }
Exemplo n.º 5
0
 public override LoanApplicationState Reject()
 {
     return(StatePool.GetState <RejectedState>());
 }