コード例 #1
0
        /// <summary>
        ///     converts the position list to direction list
        /// </summary>
        /// <param name="sol">The sol.</param>
        /// <returns></returns>
        private Stack <Direction> ToDirections(ISolution <Position> sol)
        {
            List <Direction> directions = new List <Direction>(sol.Count() - 1);
            Position         last       = sol.Get().Data;

            foreach (State <Position> state in sol)
            {
                Position next    = state.Data;
                int      nextRow = next.Row;
                int      nextCol = next.Col;
                int      lastRow = last.Row;
                int      lastCol = last.Col;

                if (nextRow > lastRow)
                {
                    directions.Add(Direction.Down);
                }
                else if (nextRow < lastRow)
                {
                    directions.Add(Direction.Up);
                }
                else if (nextCol < lastCol)
                {
                    directions.Add(Direction.Left);
                }
                else
                {
                    directions.Add(Direction.Right);
                }
                last = next;
            }
            return(new Stack <Direction>(directions));
        }