コード例 #1
0
        public ArrayList DetermineMoveSet(State <Position> state, HashSet <Position> visited)
        {
            ArrayList moves = new ArrayList();

            int x = state.GetData().X;
            int y = state.GetData().Y;

            if (y > 0)
            {
                var up = _maze.GetPosition(x, y - 1);
                if (!visited.Contains(up) && up.Type != Position.CellType.Wall)
                {
                    up.SetDirection("UP; ");
                    moves.Add(up);
                }
            }

            if (x < _maze.Width - 1)
            {
                var right = _maze.GetPosition(x + 1, y);
                if (!visited.Contains(right) && right.Type != Position.CellType.Wall)
                {
                    right.SetDirection("RIGHT; ");
                    moves.Add(right);
                }
            }

            if (y < _maze.Height - 1)
            {
                var down = _maze.GetPosition(x, y + 1);
                if (!visited.Contains(down) && down.Type != Position.CellType.Wall)
                {
                    down.SetDirection("DOWN; ");
                    moves.Add(down);
                }
            }

            if (x > 0)
            {
                var left = _maze.GetPosition(x - 1, y);
                if (!visited.Contains(left) && left.Type != Position.CellType.Wall)
                {
                    left.SetDirection("LEFT; ");
                    moves.Add(left);
                }
            }

            return(moves);
        }
コード例 #2
0
        public void Display()
        {
            for (int y = 0; y < _maze.Height; y++)
            {
                for (int x = 0; x < _maze.Width; x++)
                {
                    switch (_maze.GetPosition(x, y).Type)
                    {
                    case Position.CellType.Empty:
                        Console.Write("*");
                        break;

                    case Position.CellType.Target:
                        Console.Write("T");
                        break;

                    case Position.CellType.Wall:
                        Console.Write("X");
                        break;
                    }
                }
                Console.WriteLine();
            }
        }