コード例 #1
0
        public void Build(IMaze maze)
        {
            for (int y = 0; y < maze.Height; y++)
            {
                for (int x = 0; x < maze.Width; x++)
                {
                    maze[y, x].SetNeighbor(new Wall(), Direction.Left);
                    maze[y, x].SetNeighbor(new Wall(), Direction.Up);
                    if (x != 0)
                    {
                        maze[y, x - 1].SetNeighbor(maze[y, x][Direction.Left], Direction.Right);
                    }

                    if (x == maze.Width - 1)
                    {
                        maze[y, x].SetNeighbor(new Wall(), Direction.Right);
                    }

                    if (y != 0)
                    {
                        maze[y - 1, x].SetNeighbor(maze[y, x][Direction.Up], Direction.Down);
                    }

                    if (y == maze.Height - 1)
                    {
                        maze[y, x].SetNeighbor(new Wall(), Direction.Down);
                    }
                }
            }
        }
コード例 #2
0
        public static string Serialize2D(IMaze maze)
        {
            Debug.Assert(maze.Dimensions.Dimensionality == 2);

            var sb = new StringBuilder();

            for (int y = 0; y <= maze.Dimensions[1]; ++y)
            {
                for (int x = 0; x < maze.Dimensions[0]; ++x)
                {
                    sb.Append(corners[Labyrinth2D.Render.IntersectionType(maze, x, y)]);
                    sb.Append(maze[x, y][1] ? '─' : ' ');
                }
                sb.Append(corners[Labyrinth2D.Render.IntersectionType(maze, maze.Dimensions[0], y)]);
                if (y < maze.Dimensions[1])
                {
                    sb.Append('\n');
                }
            }

            if (EndpointsReversed(maze))
            {
                sb.Append('\n').Append(reverseEndpoints);
            }

            return(sb.ToString());
        }
コード例 #3
0
        /// <summary>
        /// Checks if there exists a solution by the name the client requested.
        ///     if so, it is fetched and sent to him.
        /// Otherwise, the model attempts the fetch the maze to solve.
        ///     if the maze does not exist, the function exists.
        ///     if the maze exists a solution is generated and sent to the client.
        /// </summary>
        /// <param name="from">the client that sent the command.</param>
        /// <param name="commandParsed">The parsed command.</param>
        public override void Execute(object from, string[] commandParsed)
        {
            string name        = commandParsed[1];
            int    type        = int.Parse(commandParsed[2]);
            int    commandType = 2;

            // check if there exists a solution
            string reply = model.GetMazeSolution(name);

            if (reply != null)
            {
                model.CompletedTask(from, new View.MessageEventArgs(reply));
                return;
            }

            // otherwise try to fetch the maze and generate a solution
            IMaze maze = model.GetMaze(name);

            if (maze == null)
            {
                return;
            }

            // maze exists but without a solution
            MazeSolverFactory solver = new MazeSolverFactory((WayToSolve)type);

            maze.SolveMaze(solver);
            string solution = maze.SolutionToString();

            // build reply
            reply = BuildReply(maze, name, solution, commandType);
            model.AddMazeSolution(name, reply);
            model.CompletedTask(from, new View.MessageEventArgs(reply));
        }
コード例 #4
0
        public void StartStrategy(IAlgorythm algorythm, IPacMan pacMan, IMaze maze, IGhost ghost, Position start)
        {
            algorythm.From.X = ghost._position.X;
            algorythm.From.Y = ghost._position.Y;
            algorythm.To.X   = start.X;
            algorythm.To.Y   = start.Y;

            algorythm.Execute();
            List <Location> route = algorythm.ResultPath;

            foreach (var step in route.ToList())
            {
                if (ghost._position.X + 1 == step.X)
                {
                    ghost.direction = SidesToMove.Right;
                }

                if (ghost._position.X - 1 == step.X)
                {
                    ghost.direction = SidesToMove.Left;
                }

                if (ghost._position.Y - 1 == step.Y)
                {
                    ghost.direction = SidesToMove.Up;
                }

                if (ghost._position.Y + 1 == step.Y)
                {
                    ghost.direction = SidesToMove.Down;
                }
            }
        }
コード例 #5
0
		private static IEnumerable<Point> GetNeighbours(Point from, IMaze maze)
		{
			return new[] { new Size(1, 0), new Size(-1, 0), new Size(0, 1), new Size(0, -1) }
				.Select(shift => from + shift)
				.Where(maze.InsideMaze)
				.Where(maze.IsFree);
		}
コード例 #6
0
        private static void MapUnlinkedCellDistance(IMaze maze, Dictionary <Cell, int> map, out Cell farthestCell)
        {
            var distance             = 0;
            var farthestCellDistance = 0;

            farthestCell = maze.AllCells.First();

            var cellsToCheck = new[] { farthestCell };

            while (cellsToCheck.Any())
            {
                var nextCellsToCheck = new List <Cell>();
                foreach (var cell in cellsToCheck)
                {
                    if (map.ContainsKey(cell))
                    {
                        continue;
                    }

                    map.Add(cell, distance);
                    nextCellsToCheck.AddRange(cell.CellWalls.Select(x => x.GetOtherCell(cell)));

                    if (distance > farthestCellDistance)
                    {
                        farthestCell         = cell;
                        farthestCellDistance = distance;
                    }
                }

                cellsToCheck = nextCellsToCheck.ToArray();
                distance++;
            }
        }
コード例 #7
0
ファイル: MazeController.cs プロジェクト: VladKachenya/Maze
 public MazeController(IMazeToCharConverter mazeToCharConverter, IHero hero, IMazeBuilder builder)
 {
     _mazeToCharConverter = mazeToCharConverter;
     _hero   = hero;
     _maze   = builder.ConstrainMaze(10, 15);
     _engine = new Processor(hero, _maze);
 }
コード例 #8
0
        public WalkerWithHandOnWall(IMaze maze, IHand hand)
        {
            Maze           = maze;
            BodyLocation   = Maze.GetStartLocation();
            AtExitLocation = false;
            Hand           = hand;
            PathsTaken     = new List <IPath>();

            Dictionary <Direction, IBuildingBlock> buildingBlocksAroundBodyLocation = Maze.GetNeighboringBuildingBlocks(BodyLocation);

            FaceDirection = (from kvp in buildingBlocksAroundBodyLocation
                             where kvp.Value.GetBuildingBlockType() == BuildingBlockType.Path
                             select kvp.Key).FirstOrDefault();

            Console.WriteLine(string.Format("Start: Face Direction {0}", FaceDirection.ToString()));

            PutHandOnWall(buildingBlocksAroundBodyLocation);

            if (HandLocation == null)
            {
                throw new Exception("Not able to touch the wall.");
            }

            Console.WriteLine(string.Format("Start: Hand Location {0},{1}", HandLocation.GetLatitude().GetIdentifier().ToString(), HandLocation.GetLongitude().GetIdentifier().ToString()));
            Console.WriteLine(string.Format("Start: Body Location {0},{1}", BodyLocation.GetLatitude().GetIdentifier().ToString(), BodyLocation.GetLongitude().GetIdentifier().ToString()));
        }
コード例 #9
0
        public void Build(IMaze maze)
        {
            var           startCell   = maze[0, 0];
            var           currentCell = startCell;
            Stack <IRoom> cells       = new Stack <IRoom>();

            do
            {
                var neighbors = GetAllSealedNeighbors(currentCell, maze);
                if (neighbors.Count != 0)
                {
                    var nextCell = GetRandomCell(neighbors);
                    BrokeWall(currentCell, nextCell);
                    cells.Push(currentCell);
                    currentCell = nextCell;
                }
                else if (cells.Count != 0)
                {
                    currentCell = cells.Pop();
                }
                else
                {
                    return;
                }
            } while (true);
        }
コード例 #10
0
ファイル: MazeFactory.cs プロジェクト: onesixtyfourth/Mazes
        public void DrawMaze(IMaze maze, IDrawMazes draw)
        {
            _ = maze ?? throw new ArgumentNullException(nameof(maze));
            _ = draw ?? throw new ArgumentNullException(nameof(draw));

            draw.DrawMaze(maze);
        }
コード例 #11
0
        public void Given_A_Maze_Is_Created_When_Coordinates_Are_Provided_For_Start_Then_The_Value_S_Should_Be_Returned()
        {
            this.maze = new core.Maze(mazeGridGenerator);
            var value = maze.DisplayCellValue(new Position(3, 11));

            value.Should().Be("S");
        }
コード例 #12
0
        public void Carve(IMaze maze)
        {
            _ = maze ?? throw new ArgumentNullException(nameof(maze));

            var stack = new Stack <Cell>();

            stack.Push(maze.Grid[random.Next(maze.Grid.Count)]);

            while (stack.Count > 0)
            {
                var unvisited =
                    maze.GetNeighbours(stack.Peek()).
                    Where(c => !c.Connected.Any()).
                    ToList();

                if (unvisited.Any())
                {
                    var next = unvisited[random.Next(unvisited.Count())];
                    maze.ConnectCells(stack.Peek(), next);
                    stack.Push(next);
                }
                else
                {
                    stack.Pop();
                }
            }
        }
コード例 #13
0
        public void CreateMazeControls(IMaze maze)
        {
            this.SuspendLayout();
            Rows.Clear();
            var rowControls = CreateRowControls(maze);
            List <ObservationSpaceRow> rows = new List <ObservationSpaceRow>();

            foreach (var row in rowControls)
            {
                rows.Add(row);
                Rows.Add(row);
                row.Dock = DockStyle.Top;
            }

            this.Controls.Clear();

            this.Controls.AddRange(rows.ToArray());

            for (int i = rows.Count - 1; i >= 0; i--)
            {
                rows[i].SendToBack();
            }

            this.ResumeLayout();
        }
コード例 #14
0
ファイル: Dijkstra.cs プロジェクト: onesixtyfourth/Mazes
        public IList <int> Solve(IMaze maze, Cell start)
        {
            _ = maze ?? throw new ArgumentNullException(nameof(maze));
            _ = start ?? throw new ArgumentNullException(nameof(start));

            Distances = Enumerable.Repeat(UNVISITED, maze.Size).ToList();
            var currentDistance = Distances[maze.Grid.IndexOf(start)] = 0;

            var frontier = maze.GetConnectedCells(new List <Cell>()
            {
                start
            });

            while (Distances.Contains(UNVISITED))
            {
                foreach (Cell cell in frontier)
                {
                    var index = maze.Grid.IndexOf(cell);
                    if (Distances[maze.Grid.IndexOf(cell)] == UNVISITED)
                    {
                        Distances[index] = currentDistance + 1;
                    }
                }

                currentDistance++;
                frontier = maze.GetConnectedCells(frontier.ToList());
            }

            return(Distances);
        }
コード例 #15
0
        public void StartStrategy(IAlgorythm algorythm, IPacMan pacMan, IMaze maze, IGhost ghost, Position start)
        {
            algorythm.From.X = ghost._position.X;
            algorythm.From.Y = ghost._position.Y;
            algorythm.To.X   = maze.BottomRightCorner.X;
            algorythm.To.Y   = maze.BottomRightCorner.Y;
            algorythm.Execute();
            List <Location> rightCornerBottom = algorythm.ResultPath;

            foreach (var i in rightCornerBottom)
            {
                if (ghost._position.X + 1 == i.X)
                {
                    ghost.direction = SidesToMove.Right;
                }

                else if (ghost._position.X - 1 == i.X)
                {
                    ghost.direction = SidesToMove.Left;
                }

                else if (ghost._position.Y - 1 == i.Y)
                {
                    ghost.direction = SidesToMove.Up;
                }

                else if (ghost._position.Y + 1 == i.Y)
                {
                    ghost.direction = SidesToMove.Down;
                }
            }
        }
コード例 #16
0
        public void Initialize()
        {
            _maze  = new Maze();
            _lines = new string[]
            { "XXXXXXXXXXXXXXX",
              "X             X",
              "X XXXXXXXXXXX X",
              "X XS        X X",
              "X XXXXXXXXX X X",
              "X XXXXXXXXX X X",
              "X XXXX      X X",
              "X XXXX XXXX X X",
              "X XXXX XXXX X X",
              "X X    XXXXXX X",
              "X X XXXXXXXXX X",
              "X X XXXXXXXXX X",
              "X X         X X",
              "X XXXXXXXXX   X",
              "XFXXXXXXXXXXXXX" };

            _drawMovementsOnMaz = new Mock <DrawExplorerMovementsOnMaze>().Object;

            _maze.CreateMazeMap(_lines);
            _autoExplorer = new AutoExplorer(_maze, _drawMovementsOnMaz);
            _explorer     = _autoExplorer as IExplorer;
        }
コード例 #17
0
        private static void ConnectAlongXAxis(IMaze maze, Graph graph, IReadOnlyList <List <Node> > nodes)
        {
            for (var y = 1; y < maze.Height - 1; y++)
            {
                var  prevX    = 1;
                Node prevNode = null;
                for (var x = 1; x < maze.Width - 1; x++)
                {
                    if (maze.IsWall(x, y))
                    {
                        prevNode = null;
                        prevX    = x;
                        continue;
                    }
                    var node = nodes[y][x];
                    if (node == null)
                    {
                        continue;
                    }
                    if (prevNode != null)
                    {
                        var distance = x - prevX;
                        graph.Nodes[node].Add(new Edge {
                            Node = prevNode, Weight = distance
                        });
                        graph.Nodes[prevNode].Add(new Edge {
                            Node = node, Weight = distance
                        });
//                        Console.WriteLine($"Connecting nodes ({prevNode.Name}) and ({node.Name}) with distance {distance}");
                    }
                    prevNode = node;
                    prevX    = x;
                }
            }
        }
コード例 #18
0
 public MazeIntegrationTests()
 {
     mazeSize = 2;
     mi       = new MazeIntegration();
     maze     = new MockMazeFactoryAllForests().Create(null, MazeType.VerySimpleMaze, mazeSize);
     mi.Maze  = maze;
 }
コード例 #19
0
ファイル: GrowingTree.cs プロジェクト: onesixtyfourth/Mazes
        public void Carve(IMaze maze)
        {
            _ = maze ?? throw new ArgumentNullException(nameof(maze));

            active.Add(maze.Grid[random.Next(maze.Grid.Count)]);

            while (active.Any())
            {
                var current    = active[random.Next(active.Count)];
                var neighbours = maze.GetNeighbours(current).
                                 Where(c => !c.Connected.Any()).
                                 ToList();

                if (neighbours.Any())
                {
                    var next = Selector(neighbours);
                    maze.ConnectCells(current, next);
                    active.Add(next);
                }
                else
                {
                    active.Remove(current);
                }
            }
        }
コード例 #20
0
        /// <summary>
        /// Solves the maze.
        /// </summary>
        /// <param name="maze">The maze.</param>
        /// <returns>a list of mazePositions that represent the path
        /// that completed the given Maze
        /// </returns>
        internal List <MazePosition> SolveMaze(IMaze maze)
        {
            List <MazePosition>             solution = new List <MazePosition>();
            PathSearchResult <MazePosition> result;

            switch (this.way)
            {
            case WayToSolve.BFS:
                result = new BFS <MazePosition>().Search(new SearchableMaze(maze));
                break;

            case WayToSolve.DFS:
                result = new DFS <MazePosition>().Search(new SearchableMaze(maze));
                break;

            default:
                return(null);
            }
            // from States List to MazePositions List
            for (int i = 0; i < result.GetPathLenght(); i++)
            {
                solution.Add(result[i].TState);
            }
            return(solution);
        }
コード例 #21
0
ファイル: FinishCell.cs プロジェクト: AGoravskiy/Maze
 public override bool TryToStep(IMaze maze)
 {
     //maze = new Maze(maze.Width + 2, maze.Height + 2);
     //var gen = new MazeGenerator(maze.Width, maze.Height);
     //maze = gen.GetMaze();
     return(true);
 }
コード例 #22
0
 public Blinky(PacMan pacman, IMaze map, Position position) : base(pacman, map, position)
 {
     aStar         = new AStar(this, pacman, map);
     this.pacman   = pacman;
     Map           = map;
     this.position = position;
 }
コード例 #23
0
        /// <summary>
        /// The main BFS algorithm. Returns list of solution path nodes using backtracking method.
        /// </summary>
        /// <param name="maze"></param>
        /// <param name="imagePath"></param>
        public IEnumerable <MazeNode> Search(IMaze maze, string imagePath)
        {
            Queue <MazeNode> queue = new Queue <MazeNode>(); // Maintains unexplored nodes.
            MazeNode         start = maze.Start;             // The starting node (first red pixel)

            start.State = NodeState.Queued;                  // Start node goes into the queue first.
            queue.Enqueue(start);
            start.Parent = null;

            while (queue.Count > 0)
            {
                MazeNode currNode = queue.Dequeue();
                if (maze.IsTarget(currNode))
                {
                    var outPath = GetMazePath(maze, currNode); // Get path points
                    Console.WriteLine("Solution found!");
                    Console.WriteLine("Nodes visited: {0}", counter);
                    return(outPath);
                }
                foreach (MazeNode adjNode in maze.GetAdjacentNodes(currNode))
                {
                    if (adjNode.State != NodeState.NotVisited)
                    {
                        continue;
                    }
                    adjNode.Parent = currNode;         // Assign parent node for backtracking
                    adjNode.State  = NodeState.Queued; // Add node to queue
                    queue.Enqueue(adjNode);
                }
                currNode.State = NodeState.Visited; // Mark visited nodes to avoid infinite loop
                counter++;
            }
            return(Enumerable.Empty <MazeNode>());
        }
コード例 #24
0
ファイル: MazeDrawer.cs プロジェクト: AlonUriah/MazeProject
        /// <summary>
        /// Draws a given IMaze
        /// </summary>
        /// <param name="maze">A maze to draw</param>
        public void DrawMaze(IMaze maze)
        {
            int      height = maze.Rows;
            int      width  = maze.Cols;
            Position init   = maze.InitialPos;
            Position goal   = maze.GoalPos;
            CellType currentCell;
            var      currentPosition = new Position();

            for (int i = height - 1; i >= 0; i--)
            {
                for (int j = 0; j < width; j++)
                {
                    currentCell         = maze[i, j];
                    currentPosition.Row = i;
                    currentPosition.Col = j;

                    if (currentCell == CellType.Free && !currentPosition.Equals(init) && !(currentPosition.Equals(goal)))
                    {
                        Console.Write("{0}", FreeSymbol);
                    }
                    else if (currentCell == CellType.Free)
                    {
                        Console.Write("{0}", currentPosition.Equals(init) ? StartSymbol : EndSymbol);
                    }
                    else
                    {
                        Console.Write("{0}", WallSymbol);
                    }
                }
                Console.WriteLine();
            }
        }
コード例 #25
0
ファイル: Blinky.cs プロジェクト: skyhoshi/PacManBlazor
 public Blinky(IGameStats gameStats, IMediator mediator, IMaze maze, IPacMan pacman, IHumanInterfaceParser input) : base(
         gameStats,
         mediator,
         input,
         pacman,
         GhostNickname.Blinky,
         maze,
コード例 #26
0
 public Cell(IMaze parentMaze, int xCoordinate, int zCoordinate)
 {
     this.ParentMaze   = parentMaze;
     this.xCoordinate  = xCoordinate;
     this.zCoordinate  = zCoordinate;
     this.roomFeatures = new List <IRoomFeature>();
 }
コード例 #27
0
 public GhostScatterMover(Ghost ghost, IMaze maze) : base(
         ghost,
         GhostMovementMode.Scatter,
         maze,
         ghost.GetScatterTarget)
 {
 }
コード例 #28
0
ファイル: Explorer.cs プロジェクト: Deeptimayee123/Git_Maze
 public Explorer(IMaze maze, IMazeConsole console)
 {
     _maze           = maze;
     _console        = console;
     CurrentPosition = _maze.GetStartingPositionOfExplorer(Symbol.Start);
     CurrentPosition.PositionHistory = new List <Position>();
 }
コード例 #29
0
 public GUI(IMaze map)
 {
     map        = new Maze();
     this.Score = 0;
     this.Lives = 3;
     this.Level = 0;
 }
コード例 #30
0
        public void Run(IMaze maze)
        {
            if (maze == null)
            {
                throw new ArgumentNullException(nameof(maze));
            }

            // Start with a cell and carve a path through all other cells until every cell has been visited.  Only
            // carve out walls of a cell the first time it is visited.

            var visitedCells = new HashSet <Cell>();
            var allCells     = maze.AllCells;
            var currentCell  = allCells[_random.Next(0, allCells.Count)];

            visitedCells.Add(currentCell);

            while (visitedCells.Count < allCells.Count)
            {
                var walls = currentCell.CellWalls.ToArray();
                var wall  = walls[_random.Next(0, walls.Length)];
                if (!visitedCells.Contains(wall.GetOtherCell(currentCell)))
                {
                    wall.IsPassable = true;
                    visitedCells.Add(wall.GetOtherCell(currentCell));
                }

                currentCell = wall.GetOtherCell(currentCell);
            }
        }
コード例 #31
0
        //returns a list of the nodes adjacent(Top, Bottom, Left, Right) to the passed node in a maze
        List <INode> GetAdjacentNeighborNodes(INode n, IMaze maze)
        {
            if (!maze.MazeGrid.Contains(n))
            {
                throw new Exception("Passed Node does not exist as part of the passed Maze.");
            }
            int[,] adjacentIndexes = new int[, ] {
                { n.XPosition, n.YPosition - 1 }, { n.XPosition + 1, n.YPosition }, { n.XPosition, n.YPosition + 1 }, { n.XPosition - 1, n.YPosition }
            };
            List <INode> neighbors = new List <INode>();

            for (int ii = 0; ii < adjacentIndexes.GetLength(0); ii++)
            {
                INode CurrentNode = maze.MazeGrid.GetNode(adjacentIndexes[ii, 0], adjacentIndexes[ii, 1]);
                if (!UnProcessedNodes.Contains(CurrentNode))
                {
                    continue;
                }
                if (CurrentNode.TypeValue == MazeCellTypeValues.wall)
                {
                    continue;
                }
                neighbors.Add(CurrentNode);
            }
            return(neighbors);
        }
コード例 #32
0
 private static ICell GoOrientation(IMaze maze, Compass direction)
 {
     switch (direction)
     {
         case Compass.North:
             return maze.GoNorth();
         case Compass.East:
             return maze.GoEast();
         case Compass.South:
             return maze.GoSouth();
         default:
             return maze.GoWest();
     }
 }
コード例 #33
0
        public ICell Move(IMaze maze)
        {
            /*
            Add current cell as visited
            Get possible directions
            Get all neighbouring cells that haven't been visited
            If found
                randomly choose one
                push it onto stack
                add to visited
                set as current position
                return cell
            If not that means dead end
                pop next cell from stack
                if no more cells that means we're at the start again and maze is not solvable
                else
                add to visited (should already be there but HashSet means it doesn't matter if it is added again)
                set as current position
                return cell
            */

            var random = new Random(DateTime.Now.Millisecond);
            if (maze.CurrentPosition.IsStart)
            {
                visited.Add(maze.CurrentPosition);
                stack.Push(maze.CurrentPosition);
            }
            var possibleDirections = GetPossibleDirections(maze);
            if (possibleDirections.Any())
            {
                var direction = possibleDirections[random.Next(possibleDirections.Count)];
                var newPosition = GoOrientation(maze, direction);
                stack.Push(newPosition);
                visited.Add(newPosition);
                maze.CurrentPosition = newPosition;
                return newPosition;
            }

            if (stack.Count > 0)
            {
                var previousPosition = stack.Pop();
                visited.Add(previousPosition);
                maze.CurrentPosition = previousPosition;
                return previousPosition;
            }

            return maze.CurrentPosition; // We're back at the start and the maze is not solvable
        }
コード例 #34
0
		public static Point GetNextStepToTarget(Point source, Point target, IMaze maze)
		{
			var queue = new Queue<Point>();
			var used = new HashSet<Point>();
			queue.Enqueue(target);
			used.Add(target);
			while (queue.Any())
			{
				var p = queue.Dequeue();
				foreach (var neighbour in GetNeighbours(p, maze))
				{
					if (used.Contains(neighbour)) continue;
					if (neighbour == source)
						return neighbour;
					queue.Enqueue(neighbour);
					used.Add(neighbour);
				}
			}
			return source;
		}
コード例 #35
0
 private bool HasSouthBeenVisited(IMaze maze)
 {
     return visited.Any(cell => cell.X == maze.CurrentPosition.X && cell.Y == maze.CurrentPosition.Y + 1);
 }
コード例 #36
0
        private List<Compass> GetPossibleDirections(IMaze maze)
        {
            var possibleDirections = new List<Compass>();

            if (!maze.CurrentPosition.HasNorthWall && !HasNorthBeenVisited(maze))
            {
                possibleDirections.Add(Compass.North);
            }
            if (!maze.CurrentPosition.HasEastWall && !HasEastBeenVisited(maze))
            {
                possibleDirections.Add(Compass.East);
            }
            if (!maze.CurrentPosition.HasSouthWall && !HasSouthBeenVisited(maze))
            {
                possibleDirections.Add(Compass.South);
            }
            if (!maze.CurrentPosition.HasWestWall && !HasWestBeenVisited(maze))
            {
                possibleDirections.Add(Compass.West);
            }

            return possibleDirections;
        }
コード例 #37
0
 private bool HasWestBeenVisited(IMaze maze)
 {
     return visited.Any(cell => cell.X == maze.CurrentPosition.X - 1 && cell.Y == maze.CurrentPosition.Y);
 }
コード例 #38
0
 public void Init(IMaze maze, IMouse mouse)
 {
     Mouse = mouse;
     Maze = maze;
     turn = 0;
 }
コード例 #39
0
 public void Init(IMaze maze, IMouse mouse)
 {
     Maze = maze;
     Mouse = mouse;
 }
コード例 #40
0
 private void ReleaseInterfaces()
 {
     Maze = null;
     Mouse = null;
 }
コード例 #41
0
 public void Init()
 {
     var builder = new SimpleMazeBuilder();
     var impl = new Maze(builder);
     watcher = new LogWatcher();
     impl.Subscribe(watcher);
     Maze = impl as IMaze;
     Mouse = impl as IMouse;
 }
コード例 #42
0
 private static void SaveMaze(IMaze maze)
 {
     System.Web.HttpContext.Current.Session["maze"] = maze;
 }
コード例 #43
-1
 public ICell Move(IMaze maze)
 {
     return maze.CurrentPosition;
 }