void Start()
    {
        // A*
        bFSearch = new BFSearch(width, height, depth, nodeSize, origin);

        // Create main camera
        Vector3 position = new Vector3(width * -6, height * 18, depth * -6);

        Instantiate(cam, position, cam.transform.rotation);

        grid = bFSearch.GetGrid();

        // Add walls manually
        //bFSearch.GetNode(2, 2, 2).SetWalkable(!bFSearch.GetNode(2, 2, 2).isWalkable);

        // Draw walls
        DrawWalls();

        // Create visual nodes
        stepVisual.Setup(grid);

        // Show goal node
        Object.Instantiate(goalObject, grid.GetPosition(goalX, goalY, goalZ) + new Vector3(5, 5, 5), new Quaternion());
        Object.Instantiate(goalObject, grid.GetPosition(startX, startY, startZ) + new Vector3(5, 5, 5), new Quaternion());
    }
예제 #2
0
        public List <string> Get(string destination)
        {
            // run the search and return list
            BFSearch search = new BFSearch();

            return(search.goTo(destination));
        }
예제 #3
0
        public void BFSearchWorksCorrectly()
        {
            //Arrange
            var tree  = new Tree <int>();
            int count = 0;

            for (int i = 0; i < 10; i++)
            {
                var node = new Tree <int> .TreeNode(count);

                count++;
                tree.Add(node);
                for (int j = 0; j < 10; j++)
                {
                    var child = new Tree <int> .TreeNode(count);

                    count++;
                    tree.Add(child, node);
                    for (int k = 0; k < 10; k++)
                    {
                        var newChild = new Tree <int> .TreeNode(count);

                        count++;
                        tree.Add(newChild, child);
                        for (int f = 0; f < 20; f++)
                        {
                            var lastChild = new Tree <int> .TreeNode(count);

                            count++;
                            tree.Add(lastChild, newChild);
                        }
                    }
                }
            }

            //Act
            var search = new BFSearch <int>();
            var result = search.BreadthFirstSearch(tree.Root);
            var actual = new List <int>();

            foreach (var item in tree)
            {
                actual.Add(item);
            }

            //Assert
            CollectionAssert.AreEqual(result, actual);
        }
예제 #4
0
	public IEnumerator Solve(){

		BFSearch searcher = new BFSearch(state_);
		
		List<Move> moveList = searcher.GetMoveList(searcher.GetTerminalNode());

		foreach(Move move in moveList){

			SwapPiece(move);

			//delay the moves to visualise the solving
			yield return new WaitForSeconds(0.2f);
			//yield return null;
		}

	}
예제 #5
0
        public static IList <BFSearch.Cell> CreateRouteOf(this Vehicle vehicle, int pointCount, Point startPoint, BFSearch.Cell excludeCell = null)
        {
            var startCell = vehicle.GetCurrentCell(startPoint);

            var terminateIndex = vehicle.Self.NextWaypointIndex;
            var terminateCell  = vehicle.GetCellByIndex(terminateIndex);

            var route = (List <BFSearch.Cell>) new BFSearch(vehicle, startCell, terminateCell).Search(excludeCell: excludeCell);

            while (route.Count < pointCount)
            {
                startCell = terminateCell;
                terminateIndex++;

                terminateCell = vehicle.GetCellByIndex(terminateIndex);

                var nextRoute = new BFSearch(vehicle, startCell, terminateCell).Search(excludeCell: excludeCell);

                route.AddRange(nextRoute);
            }

            return(route);
        }
예제 #6
0
        private bool ThereIsNoObstaclesForThrow(double angle, double distanceTo, Point carPoint)
        {
            bool result     = true;
            var  stepLength = Game.TrackTileMargin * 1.5D;
            var  steps      = Convert.ToInt32(Math.Floor(distanceTo / stepLength));
            var  startCell  = this.GetCurrentCell(Self.CurrentPoint());

            var route = new BFSearch(this, startCell, this.GetCurrentCell(carPoint)).Search();
            var index = 0;

            for (var i = 0; i < steps; i++)
            {
                var nx = Self.X + (i + 1) * stepLength * Math.Cos(angle);
                var ny = Self.Y + (i + 1) * stepLength * Math.Sin(angle);

                var cell = this.GetCurrentCell(new Point(nx, ny));

                var currentIndex = route.IndexOf(cell);

                if (currentIndex == -1 && !startCell.Equals(cell))
                {
                    result = false;
                    break;
                }

                if (currentIndex - index > 1)
                {
                    result = false;
                    break;
                }

                index = currentIndex;
            }

            return(result);
        }
예제 #7
0
    void SetupBFSearch()
    {
        bFSearch = new BFSearch(width, height, depth, nodeSize, origin);

        bFSearchGrid = bFSearch.GetGrid();

        // Add walls manually
        bFSearch.GetNode(2, 2, 0).SetWalkable(!bFSearch.GetNode(2, 2, 0).isWalkable);
        bFSearch.GetNode(2, 3, 0).SetWalkable(!bFSearch.GetNode(2, 3, 0).isWalkable);
        bFSearch.GetNode(2, 4, 0).SetWalkable(!bFSearch.GetNode(2, 4, 0).isWalkable);
        bFSearch.GetNode(3, 4, 0).SetWalkable(!bFSearch.GetNode(3, 4, 0).isWalkable);
        bFSearch.GetNode(4, 4, 0).SetWalkable(!bFSearch.GetNode(4, 4, 0).isWalkable);
        bFSearch.GetNode(5, 4, 0).SetWalkable(!bFSearch.GetNode(5, 4, 0).isWalkable);
        bFSearch.GetNode(6, 4, 0).SetWalkable(!bFSearch.GetNode(6, 4, 0).isWalkable);
        bFSearch.GetNode(6, 3, 0).SetWalkable(!bFSearch.GetNode(6, 3, 0).isWalkable);
        bFSearch.GetNode(6, 2, 0).SetWalkable(!bFSearch.GetNode(6, 2, 0).isWalkable);
        bFSearch.GetNode(1, 9, 0).SetWalkable(!bFSearch.GetNode(1, 9, 0).isWalkable);
        bFSearch.GetNode(1, 8, 0).SetWalkable(!bFSearch.GetNode(1, 8, 0).isWalkable);
        bFSearch.GetNode(3, 7, 0).SetWalkable(!bFSearch.GetNode(3, 7, 0).isWalkable);
        bFSearch.GetNode(4, 7, 0).SetWalkable(!bFSearch.GetNode(4, 7, 0).isWalkable);
        bFSearch.GetNode(5, 7, 0).SetWalkable(!bFSearch.GetNode(5, 7, 0).isWalkable);
        bFSearch.GetNode(6, 7, 0).SetWalkable(!bFSearch.GetNode(6, 7, 0).isWalkable);
        bFSearch.GetNode(7, 7, 0).SetWalkable(!bFSearch.GetNode(7, 7, 0).isWalkable);
        bFSearch.GetNode(8, 7, 0).SetWalkable(!bFSearch.GetNode(8, 7, 0).isWalkable);

        // Add weighted tiles manually
        bFSearch.GetNode(0, 4, 0).SetWeighted(!bFSearch.GetNode(0, 4, 0).isWeighted);
        bFSearch.GetNode(1, 4, 0).SetWeighted(!bFSearch.GetNode(1, 4, 0).isWeighted);

        // Draw walls
        for (int x = 0; x < bFSearchGrid.GetWidth(); x++)
        {
            for (int y = 0; y < bFSearchGrid.GetHeight(); y++)
            {
                for (int z = 0; z < bFSearchGrid.GetDepth(); z++)
                {
                    Node node = bFSearchGrid.GetGridObject(x, y, z);

                    // If the node is not walkable draw a wall
                    if (!node.isWalkable)
                    {
                        Object.Instantiate(wallObject, bFSearchGrid.GetPosition(x, y, z) + new Vector3(5, 5, 5), new Quaternion());
                    }

                    if (node.isWeighted)
                    {
                        Object.Instantiate(weightedObject, bFSearchGrid.GetPosition(x, y, z) + new Vector3(5, 5, 5), new Quaternion());
                    }
                }
            }
        }

        // Create visual nodes
        stepVisual.Setup(bFSearchGrid);

        // Show goal node
        Object.Instantiate(goalObject, bFSearchGrid.GetPosition(goalX, goalY, goalZ) + new Vector3(5, 5, 5), new Quaternion());
        Object.Instantiate(goalObject, bFSearchGrid.GetPosition(startX, startY, startZ) + new Vector3(5, 5, 5), new Quaternion());

        currentAlgorithm = "bFSearch";
    }
예제 #8
0
		public Node(PuzzleState s, BFSearch bfs){
			parent_ = null;
			searcher_ = bfs;
			state_ = s;
			expansions_ = 1;
		}