Beispiel #1
0
        public static bool SolveMaze(IMazeWalker entity, Point mazeFinish)
        {
            bool endOfMazeReached = false;

            while (!endOfMazeReached)
            {
                bool couldMoveForward = entity.MoveForward();

                if (!couldMoveForward)
                {
                    entity.TurnRight();
                }
                else
                {
                    if (entity.CanSeeLeftTurning())
                    {
                        entity.TurnLeft();
                    }
                }

                endOfMazeReached = Equals(entity.CurrentPosition, mazeFinish);
                entity.DumpState();
            }

            return(true);
        }
Beispiel #2
0
 public AStarPather(IMazeWalker walker, twinrect?bounds = null)
 {
     this.walkers    = new IMazeWalker[bounds.HasValue ? 2 : 1];
     this.walkers[0] = walker;
     if (bounds.HasValue)
     {
         this.walkers[1] = new MazeWalkerLambda((a, b) => { return(bounds.Value.Contains(b)?0:int.MaxValue); });
     }
 }
Beispiel #3
0
        static async Task Main(string[] args)
        {
            ServiceCollection serviceCollection = ConfigureServices();

            var             services   = serviceCollection.BuildServiceProvider();
            IPonyAPIClient  ponyAPI    = services.GetRequiredService <IPonyAPIClient>();
            IMazeFactory    factory    = services.GetRequiredService <IMazeFactory>();
            IMazePathfinder pathfinder = services.GetRequiredService <IMazePathfinder>();
            IMazeWalker     walker     = services.GetRequiredService <IMazeWalker>();

            Maze maze = null;

            while (maze is null)
            {
                Console.WriteLine("Enter a maze GUID or press enter for a new maze:");
                string input = Console.ReadLine();
                if (input != "")
                {
                    if (Guid.TryParse(input, out Guid mazeId))
                    {
                        maze = await factory.FromID(mazeId);
                    }
                    else
                    {
                        Console.WriteLine("Could not parse mazeId");
                    }
                }
                else
                {
                    maze = await factory.Create();

                    Console.WriteLine($"Maze ID {maze.MazeId} created.");
                }
            }
            Console.WriteLine(await ponyAPI.GetVisualMaze(maze.MazeId));

            Path ponyPath = pathfinder.Solve(maze);

            Console.WriteLine("Here's the ideal path of the pony, let's see it in action:");
            Console.WriteLine(ponyPath);
            await walker.Walk(ponyPath);

            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();

            services.Dispose();
        }
Beispiel #4
0
 public bool AtFinish(IMazeWalker walker)
 {
     return(Finish.X == walker.CurrentPosition.X && Finish.Y == walker.CurrentPosition.Y);
 }
 public void Dump(IMazeWalker walker)
 {
     Console.WriteLine(_mazeDumper.Dump(_maze, walker.CurrentPosition));
 }
 public void Dump(IMazeWalker walker)
 {
     Console.WriteLine(walker.CurrentPosition.ToString());
 }
Beispiel #7
0
 public MazeWalkerAdapter(IMazeWalker impl)
 {
     _impl = impl;
 }