コード例 #1
0
 // Use this for initialization
 public CalculateState(TreasureFinderController tfc)
 {
     tFC        = tfc;
     _actor     = tFC.GetComponent <IActor> ();
     pathFinder = GameObject.Find("Pathfinding").GetComponent <Pathfinding>();
     grid       = GameObject.Find("Grid").GetComponent <Grid> ();
 }
コード例 #2
0
 public CheckAvailability(Dictionary <string, object> db, GridNode goal)
 {
     //dB = db;
     tfc          = db ["TFC"] as TreasureFinderController;
     pf           = tfc.pathfinder;
     tfc.GoalNode = goal;
     available    = pf.CheckAvailability(tfc.grid.PostoNode(new Vector2(tfc.transform.position.x, tfc.transform.position.y)), goal);
 }
コード例 #3
0
ファイル: TreasureFind.cs プロジェクト: MilkTicc/AI-Projects
//		private GridNode RedKey;
//		private GridNode GreenKey;
//		private GridNode BlueKey;


        private TreasureFinderController CreateTFActor()
        {
            TreasureFinderController newTFActor = Instantiate <TreasureFinderController> (tfcPrefab);

            newTFActor.GetComponent <NewActor> ().Position = grid.RCtoPosition(grid.tFCSpawnPos);
            newTFActor.gameObject.name = "Treasure Finder ";
            newTFActor.transform.SetParent(transform);
            newTFActor.gameObject.SetActive(true);
            newTFActor.haveRedKey   = false;
            newTFActor.haveGreenKey = false;
            newTFActor.haveBlueKey  = false;
            newTFActor.haveTreasure = false;
            return(newTFActor);
        }
コード例 #4
0
ファイル: TreasureFind.cs プロジェクト: MilkTicc/AI-Projects
        void ToggleTreasureFind()
        {
            if (!treasureFind)
            {
                tfc = CreateTFActor();
            }

            if (treasureFind)
            {
                Destroy(tfc.gameObject);
                DrawObjects();
                CloseDoors();
            }
            treasureFind = !treasureFind;
            debugging    = false;
        }
コード例 #5
0
ファイル: MoveTo.cs プロジェクト: MilkTicc/AI-Projects
        //Image image;

        public MoveTo(Dictionary <string, object> db, string goal, Image asd)
        {
            dB    = db;
            tfc   = db ["TFC"] as TreasureFinderController;
            pf    = tfc.pathfinder;
            image = asd;
            if (goal == "GK")
            {
                Goal = dB ["GKNode"] as GridNode;
            }
            else if (goal == "GD")
            {
                Goal = dB ["GDNode"] as GridNode;
            }
            else if (goal == "RK")
            {
                Goal = dB ["RKNode"] as GridNode;
            }
            else if (goal == "RD")
            {
                Goal = dB ["RDNode"] as GridNode;
            }
            else if (goal == "BK")
            {
                Goal = dB ["BKNode"] as GridNode;
            }
            else if (goal == "BD")
            {
                Goal = dB ["BDNode"] as GridNode;
            }
            else if (goal == "TS")
            {
                Goal = dB ["TSNode"] as GridNode;
            }
            Path = null;
            name = "MoveTo" + goal;
        }
コード例 #6
0
 // Use this for initialization
 public HappyState(TreasureFinderController tfc)
 {
     tFC = tfc;
 }
コード例 #7
0
        public KeyValuePair <List <GridNode>, List <GridNode> > PathFindTheOne(TreasureFinderController PFActor)
        {
            PFActor.StartNode           = grid.PostoNode(PFActor._actor.Position);
            PFActor.StartNode.CostSoFar = 0;
            PFActor.StartNode.Heu       = heuristic(PFActor.StartNode, PFActor.GoalNode);
            Open.Clear();
            Closed.Clear();
            Open.Enqueue(0, PFActor.StartNode);
            List <GridNode> thePath     = new List <GridNode> ();
            List <GridNode> checkedNode = new List <GridNode> ();

            while (true)
            {
                GridNode currentNode = Open.DequeueValue();

                if (currentNode == PFActor.GoalNode)
                {
                    Closed.Clear();
                    while (Open.IsEmpty == false)
                    {
                        Open.DequeueValue().SetPathStatus(GridNode.PathStatus._wasInOpen);
                    }
                    GridNode fromnode = PFActor.GoalNode;
                    while (fromnode != PFActor.StartNode)
                    {
                        fromnode.SetPathStatus(GridNode.PathStatus.isOnPath);
                        //fromnode.DrawPath (PFActor.DrawPath);
                        thePath.Add(fromnode);
                        fromnode = fromnode.prevNode;
                    }

                    PFActor.StartNode.SetPathStatus(GridNode.PathStatus.isOnPath);

                    thePath.Add(PFActor.StartNode);
                    return(new KeyValuePair <List <GridNode>, List <GridNode> > (thePath, checkedNode));
                    //break;
                }

                Closed.Add(currentNode);
                //Debug.Log(PFActor.toDoor);
                foreach (GridNode nextNode in currentNode.Neighbors)
                {
                    if (nextNode._NodeStatus == GridNode.NodeStatus.blocked)
                    {
                        continue;
                    }

                    if (TreasureFind.ShutDoor.Contains(nextNode) && nextNode != PFActor.GoalNode)
                    {
                        continue;
                    }


                    nextNode.SetPathStatus(GridNode.PathStatus._checked);

                    checkedNode.Add(nextNode);
                    int cost_so_far = heuristic(nextNode, currentNode) * nextNode.Cost + currentNode.CostSoFar;
                    int heu         = heuristic(nextNode, PFActor.GoalNode);
                    if (nextNode.CostSoFar == 0 && nextNode != PFActor.StartNode)
                    {
                        nextNode.CostSoFar = cost_so_far;
                    }
                    if (nextNode.Heu == 0 && nextNode != PFActor.StartNode)
                    {
                        nextNode.Heu = heu;
                    }


                    if (inOpen(nextNode).Value != null && cost_so_far + heu < inOpen(nextNode).Key)
                    {
                        Open.Remove(inOpen(nextNode));
                        Open.Enqueue(cost_so_far + heu, nextNode);
                        nextNode.CostSoFar = cost_so_far;
                        nextNode.Heu       = heu;
                        nextNode.prevNode  = currentNode;
                    }


                    if (inOpen(nextNode).Value == null && !Closed.Contains(nextNode))
                    {
                        Open.Enqueue(cost_so_far + heu, nextNode);
                        nextNode.prevNode = currentNode;
                    }

                    nextNode.SetText((nextNode.CostSoFar + nextNode.Heu).ToString());
                    nextNode._text.gameObject.SetActive(true);
                    //if (nextNode != PFActor.GoalNode && nextNode != PFActor.StartNode) {
                    //}
                }
                if (Open.IsEmpty && currentNode != PFActor.GoalNode)
                {
                    List <GridNode> emptyList = new List <GridNode> ();
                    emptyList.Add(PFActor.StartNode);
                    return(new KeyValuePair <List <GridNode>, List <GridNode> >(emptyList, null));
                }
            }
        }
コード例 #8
0
ファイル: Pathfinding.cs プロジェクト: MilkTicc/AI-Projects
        public bool CheckAvailability(TreasureFinderController tfc, GridNode tarNode, bool notDoor)
        {
            GridNode StartNode = grid.PostoNode(new Vector2(tfc.transform.position.x, tfc.transform.position.y));

            StartNode.CostSoFar = 0;
            StartNode.Heu       = heuristic(StartNode, tarNode);
            Open.Clear();
            Closed.Clear();
            Open.Enqueue(0, StartNode);

            while (true)
            {
                GridNode currentNode = Open.DequeueValue();
                if (currentNode == tarNode)
                {
                    Closed.Clear();
                    return(true);
                }

                Closed.Add(currentNode);

                foreach (GridNode nextNode in currentNode.Neighbors)
                {
                    if (nextNode._NodeStatus == GridNode.NodeStatus.blocked)
                    {
                        continue;
                    }

                    if (TreasureFind.ShutDoor.Contains(nextNode) && notDoor)
                    {
                        continue;
                    }

                    int cost_so_far = heuristic(nextNode, currentNode) * nextNode.Cost + currentNode.CostSoFar;
                    int heu         = heuristic(nextNode, tarNode);
                    if (nextNode.CostSoFar == 0)
                    {
                        nextNode.CostSoFar = cost_so_far;
                    }
                    if (nextNode.Heu == 0)
                    {
                        nextNode.Heu = heu;
                    }
                    if (inOpen(nextNode).Value != null && cost_so_far + heu < inOpen(nextNode).Key)
                    {
                        Open.Remove(inOpen(nextNode));
                        Open.Enqueue(cost_so_far + heu, nextNode);
                        nextNode.CostSoFar = cost_so_far;
                        nextNode.Heu       = heu;
                    }

                    if (inOpen(nextNode).Value == null && !Closed.Contains(nextNode))
                    {
                        Open.Enqueue(cost_so_far + heu, nextNode);
                    }
                }

                if (Open.IsEmpty && currentNode != tarNode)
                {
                    return(false);
                }
            }
        }
コード例 #9
0
ファイル: SadState.cs プロジェクト: MilkTicc/AI-Projects
 // Use this for initialization
 public SadState(TreasureFinderController tfc)
 {
     tFC = tfc;
 }
コード例 #10
0
ファイル: Happy&Sad.cs プロジェクト: MilkTicc/AI-Projects
 //Image image;
 public Sad(Dictionary <string, object> db, Image asd)
 {
     tfc   = db ["TFC"] as TreasureFinderController;
     image = asd;
 }
コード例 #11
0
 // Use this for initialization
 public TestState(TreasureFinderController tfc)
 {
     tFC = tfc;
     Debug.Log("test start");
 }