コード例 #1
0
 protected override void PollChaseTarget()
 {
     currentTargetPosition =
         LevelGridController.TaxiCabDistance(gridPosition, playerController.gridPosition) > 8
             ? playerController.gridPosition //is further than 8 tiles away from pacman, target him
             : bottomLeftMapBound;           //is closer than 8 tiles away from pacman,
     //go to bottom left corner
 }
コード例 #2
0
        private Direction GetBestTurn(Vector2Int initialPosition,
                                      Vector2Int goalPosition,
                                      bool[] viableTurns,
                                      Direction originDirection)
        {
            Direction bestTurn;

            for (int i = 0; i < 4; i++)
            {
                _neighborHeuristics[i] = DEFAULT_DISTANCE_MAX;
            }

            void ThreadStart()
            {
                for (int i = 0; i < viableTurns.Length; i++)
                {
                    bool isDirectionValid = viableTurns[i] &&
                                            (Direction)i != originDirection;
                    if (isDirectionValid)
                    {
                        _neighborHeuristics[i] = LevelGridController.TaxiCabDistance(
                            initialPosition + DirectionToVector2Int(i),
                            goalPosition);
                    }
                }

                bestTurn = (Direction)FindSmallestNumberIndex(_neighborHeuristics);
            }

            //Toggle these two blocks to toggle multithreading:

            ThreadStart();

            // Thread pathFindThread = new Thread(ThreadStart);
            // pathFindThread.Start();
            return(bestTurn);
        }