예제 #1
0
        public void ShortestPath(int x, int y)
        {
            Point point1 = new Point(this.PositionX, this.PositionY);
            Point point2 = new Point(x, y);

            PositionX = x * 5;
            PositionY = y * 5;

            if (point1 != point2)
            {
                PathCalculator path     = new PathCalculator(iBlade.map.TilesArray);
                List <Tile>    tilelist = new List <Tile>();

                tilelist = path.FindShortestPath(point1, point2);

                foreach (Tile t in tilelist)
                {
                    this.PointList.Add(t.Pixel);
                }
            }
            else
            {
                Console.WriteLine("The AGV doesn't have to move");
            }
            iBlade.Status = true;
        }
예제 #2
0
        public void AttackClosestEnemyTankToOwnBase(GameState currGameState, Tank killerTank, Tank targetTank,
                                                    TankActionSet actionSet, bool[] moveChosenByTankNumber)
        {
            MobileState killerTankState = currGameState.GetMobileState(killerTank.Index);

            if (killerTankState.IsActive)
            {
                MobileState enemyTankState = currGameState.GetMobileState(targetTank.Index);
                if (enemyTankState.IsActive)
                {
                    DirectionalMatrix <DistanceCalculation> attackMatrix
                        = currGameState.CalculationCache.GetIncomingAttackMatrixForTankByTankIndex(targetTank.Index);
                    if (attackMatrix != null)
                    {
                        DistanceCalculation attackCalculation = attackMatrix[killerTankState.Dir, killerTankState.Pos];
                        TankAction[]        tankActions
                            = PathCalculator.GetTankActionsOnIncomingShortestPath(attackMatrix, killerTankState, enemyTankState.Pos,
                                                                                  currGameState.CalculationCache.FiringLinesForTanksMatrix, keepMovingCloserOnFiringLastBullet: true);
                        if (tankActions.Length > 0)
                        {
                            actionSet.Actions[killerTank.Number]      = tankActions[0];
                            moveChosenByTankNumber[killerTank.Number] = true;
                        }
                    }
                }
            }
        }
예제 #3
0
        public void ParentPathCalculatorTest()
        {
            _pathCalculator = new PathCalculator(new FileSystemAccess());
            var result = _pathCalculator.CalculateParentPath(new FullPath(@"c:\a\b\c\d\pom.xml"), "../pom.xml");

            Assert.That(result.Value, Is.EqualTo(@"c:\a\b\c\pom.xml"));
        }
예제 #4
0
        /// <summary>
        /// Calculates the subpath inside a single path.
        /// Two consecutive control points at the same location indicates a subpath in osu.
        /// </summary>
        List <Vector2> CalculateSubpath(Vector2[] subPoints)
        {
            switch (PathType)
            {
            case PathType.Linear:
                return(PathCalculator.ApproximateLinear(subPoints));

            case PathType.PerfectCurve:
                // Perfect curve types must only have 3 points.
                if (points.Length != 3 || subPoints.Length != 3)
                {
                    break;
                }
                var subPath = PathCalculator.ApproximateCircularArc(subPoints);
                // If somehow not applicable, just break
                if (subPath.Count == 0)
                {
                    break;
                }
                return(subPath);

            case PathType.Catmull:
                return(PathCalculator.CalculateCatmull(subPoints));
            }
            return(PathCalculator.CalculateBezier(subPoints));
        }
예제 #5
0
    /// <summary>
    /// Check if the destination can be reached
    /// </summary>
    /// <param name="_position">destination to reach</param>
    /// <returns>if the destination can be reached</returns>
    public bool CheckDestination(Vector3 _position)
    {
        if (CustomNavMeshManager.Triangles == null || CustomNavMeshManager.Triangles.Count == 0)
        {
            Debug.LogWarning("Triangles Not found. Must build the navmesh for the scene");
            return(false);
        }
        if (isMoving)
        {
            StopAllCoroutines();
        }
        pathState = CalculatingState.Calculating;
        bool _canBeReached = PathCalculator.CalculatePath(OffsetPosition, _position, currentPath, CustomNavMeshManager.Triangles);

        if (_canBeReached)
        {
            pathState = CalculatingState.Ready;
            StopAllCoroutines();
            StartCoroutine(FollowPath());
        }
        else
        {
            pathState = CalculatingState.Waiting;
        }
        return(_canBeReached);
    }
예제 #6
0
        public TankAction[] GetTankActionsFromTankToAttackTankAtPointAlongDirectionOfMovement(
            int playerIndex, int tankNumber, Point targetPoint, Direction finalMovementDir,
            EdgeOffset[] edgeOffsets, bool keepMovingCloserOnFiringLastBullet)
        {
            Tank                           tank                      = Game.Current.Players[playerIndex].Tanks[tankNumber];
            MobileState                    tankState                 = GameState.GetMobileState(tank.Index);
            TurnCalculationCache           turnCalcCache             = Game.Current.Turns[GameState.Tick].CalculationCache;
            Cell                           targetCell                = turnCalcCache.CellMatrix[targetPoint];
            FiringLineMatrix               firingLinesForTanksMatrix = GameState.CalculationCache.FiringLinesForTanksMatrix;
            AttackTargetDistanceCalculator attackCalculator          = new AttackTargetDistanceCalculator(
                ElementType.TANK, firingLinesForTanksMatrix, GameState.CalculationCache, turnCalcCache);

            attackCalculator.MovementDirections = new Direction[] { finalMovementDir };
            attackCalculator.EdgeOffsets        = edgeOffsets;
            CombinedMovementAndFiringDistanceCalculation combinedDistCalc
                = attackCalculator.GetShortestAttackDistanceFromCurrentTankPosition(tank.Index,
                                                                                    targetCell);

            return(PathCalculator.GetTanksActionsOnOutgoingShortestAttackPathFromCurrentTankPosition(
                       tank.Index, combinedDistCalc, GameState.CalculationCache, keepMovingCloserOnFiringLastBullet));

            /* was:
             * DirectionalMatrix<DistanceCalculation> incomingDistanceMatrix
             *  = attackCalculator.CalculateMatrixOfShortestDistancesToTargetCell(targetCell);
             * DistanceCalculation distanceCalc = incomingDistanceMatrix[tankState];
             * return PathCalculator.GetTankActionsOnIncomingShortestPath(incomingDistanceMatrix, tankState.Dir, tankState.Pos.X, tankState.Pos.Y,
             *  targetPoint.X, targetPoint.Y, firingLinesForTanksMatrix, keepMovingCloserOnFiringLastBullet);
             */
        }
예제 #7
0
        public TankAction[] GetActionsToReachLineOfFireDefencePointByIncomingAttackDirection(
            int playerIndex, int tankNumber, Direction finalIncomingDirectionOfAttack)
        {
            Player      player    = Game.Current.Players[playerIndex];
            Tank        tank      = player.Tanks[tankNumber];
            MobileState tankState = GetTankState(playerIndex, tankNumber);

            if (tankState.IsActive)  // TODO: Check if locked in a firefight also
            {
                DirectionalMatrix <DistanceCalculation> distanceMatrix
                    = GameState.CalculationCache.GetDistanceMatrixFromTankByTankIndex(tank.Index);
                Direction defenceDir = finalIncomingDirectionOfAttack.GetOpposite();
                if (defenceDir == Direction.NONE)
                {
                    defenceDir = Direction.RIGHT;
                }
                int startPosOffsetFromBase = Constants.TANK_OUTER_EDGE_OFFSET;
                int endPosOffsetFromBase   = startPosOffsetFromBase + MAX_POINTS_TO_TRY_FOR_DEFENCE_POS;
                for (int offsetSize = startPosOffsetFromBase; offsetSize < endPosOffsetFromBase; offsetSize++)
                {
                    Point defencePos = player.Base.Pos + defenceDir.GetOffset(offsetSize);
                    DistanceCalculation tankDefenceCalc = distanceMatrix[defenceDir, defencePos];
                    if (tankDefenceCalc.CodedDistance == 0)
                    {
                        // This defence point can't be reached, try further away
                        continue;
                    }
                    return(PathCalculator.GetTankActionsOnOutgoingShortestPath(distanceMatrix, defenceDir, defencePos));
                }
            }
            return(new TankAction[0]);
        }
예제 #8
0
        public static void Main()
        {
            calc = new PathCalculator(Input.inputSequence);
            var res = calc.run();

            Console.WriteLine("Result " + res);
            Console.ReadLine();
        }
예제 #9
0
        public void Run4()
        {
            _pathCalculator = new PathCalculator("R8, R4, R4, R8");

            var res = _pathCalculator.run();

            Assert.AreEqual(4, res);
        }
예제 #10
0
        public void Run3()
        {
            _pathCalculator = new PathCalculator("R5, L5, R5, R3");

            var res = _pathCalculator.run();

            Assert.AreEqual(12, res);
        }
예제 #11
0
        public void Run2()
        {
            _pathCalculator = new PathCalculator("R2, R2, R2");

            var res = _pathCalculator.run();

            Assert.AreEqual(2, res);
        }
예제 #12
0
        public void Run1()
        {
            _pathCalculator = new PathCalculator("R2, L3");

            var res = _pathCalculator.run();

            Assert.AreEqual(5, res);
        }
예제 #13
0
        public TankAction[] GetTankActionsToMoveToPoint(int playerIndex, int tankNumber,
                                                        Direction directionAtDestination, Point destination)
        {
            Tank tank = Game.Current.Players[playerIndex].Tanks[tankNumber];
            DirectionalMatrix <DistanceCalculation> distanceMatrix
                = GameState.CalculationCache.GetDistanceMatrixFromTankByTankIndex(tank.Index);

            return(PathCalculator.GetTankActionsOnOutgoingShortestPath(distanceMatrix, directionAtDestination, destination));
        }
예제 #14
0
        private static void Main(string[] args)
        {
            var input =
                "R1, L3, R5, R5, R5, L4, R5, R1, R2, L1, L1, R5, R1, L3, L5, L2, R4, L1, R4, R5, L3, R5, L1, R3, L5, R1, L2, R1, L5, L1, R1, R4, R1, L1, L3, R3, R5, L3, R4, L4, R5, L5, L1, L2, R4, R3, R3, L185, R3, R4, L5, L4, R48, R1, R2, L1, R1, L4, L4, R77, R5, L2, R192, R2, R5, L4, L5, L3, R2, L4, R1, L5, R5, R4, R1, R2, L3, R4, R4, L2, L4, L3, R5, R4, L2, L1, L3, R1, R5, R5, R2, L5, L2, L3, L4, R2, R1, L4, L1, R1, R5, R3, R3, R4, L1, L4, R1, L2, R3, L3, L2, L1, L2, L2, L1, L2, R3, R1, L4, R1, L1, L4, R1, L2, L5, R3, L5, L2, L2, L3, R1, L4, R1, R1, R2, L1, L4, L4, R2, R2, R2, R2, R5, R1, L1, L4, L5, R2, R4, L3, L5, R2, R3, L4, L1, R2, R3, R5, L2, L3, R3, R1, R3";
            var pathCalculator = new PathCalculator();

            Console.WriteLine(pathCalculator.CalculateDistanceBetweenStartAndFinish(input));
            Console.WriteLine(pathCalculator.GetFirstDuplicatedPosition());
        }
예제 #15
0
    private void Awake()
    {
        pathRefreshWaitForSeconds = new WaitForSeconds(basePathRefreshTime);

        pathSegmentGetter = new PathSegmentGetter();
        brushPool         = new BrushPool(brushPrefab, brushPoolSize);
        pathCalculator    = new PathCalculator();

        drawingCanvas.Init();
    }
예제 #16
0
 private void Tick()
 {
     if (incomingRequests.Count > 0 && !bIsThreadLocked)
     {
         PathRequest    toProccess     = incomingRequests.Dequeue();
         PathCalculator pathCalculator = new PathCalculator(toProccess);
         Thread         thread         = new Thread(pathCalculator.StartPathfinding);
         bIsThreadLocked = true;
         thread.Start();
     }
 }
예제 #17
0
        public TankAction[] GetTankActionsFromTankToAttackTank(int playerIndex, int tankNumber, int targetTankNumber)
        {
            Tank        targetTank      = Game.Current.Players[1 - playerIndex].Tanks[targetTankNumber];
            MobileState targetTankState = GetTankState(1 - playerIndex, targetTankNumber);
            DirectionalMatrix <DistanceCalculation> distanceMatrix
                = GameState.CalculationCache.GetIncomingAttackMatrixForTankByTankIndex(targetTank.Index);
            MobileState attackingTankState = GetTankState(playerIndex, tankNumber);

            return(PathCalculator.GetTankActionsOnIncomingShortestPath(distanceMatrix,
                                                                       attackingTankState, targetTankState.Pos, GameState.CalculationCache.FiringLinesForTanksMatrix,
                                                                       keepMovingCloserOnFiringLastBullet: false));
        }
예제 #18
0
        protected override void ChooseMoves()
        {
            GameState     currGameState = Game.Current.CurrentTurn.GameState;
            TankActionSet actionSet     = new TankActionSet(YourPlayerIndex, currGameState.Tick);

            for (int tankNumber = 0; tankNumber < Constants.TANKS_PER_PLAYER; tankNumber++)
            {
                Tank        tank      = You.Tanks[tankNumber];
                MobileState tankState = currGameState.GetMobileState(tank.Index);
                if (!tankState.IsActive)
                {
                    continue;
                }

                int midX = currGameState.Walls.Width / 2;
                int midY = currGameState.Walls.Height / 2;

                int       targetX;
                int       targetY;
                Direction direction;

                if (tankState.Pos.X > midX)
                {
                    targetX = currGameState.Walls.Width - Constants.SEGMENT_SIZE;
                }
                else
                {
                    targetX = Constants.SEGMENT_SIZE;
                }

                if (tankState.Pos.Y > midY)
                {
                    targetY   = currGameState.Walls.Height - Constants.SEGMENT_SIZE;
                    direction = Direction.UP;
                }
                else
                {
                    targetY   = Constants.SEGMENT_SIZE;
                    direction = Direction.DOWN;
                }

                DirectionalMatrix <DistanceCalculation> distancesFromTank
                    = currGameState.CalculationCache.GetDistanceMatrixFromTankByTankIndex(tank.Index);
                TankAction[] tankActions = PathCalculator.GetTankActionsOnOutgoingShortestPath(
                    distancesFromTank, direction, targetX, targetY);
                if (tankActions.Length > 0)
                {
                    actionSet.Actions[tank.Number] = tankActions[0];
                }
            }

            Coordinator.SetBestMoveSoFar(actionSet);
        }
예제 #19
0
 public static void CalculateHCostIfNeeded(Grid grid, Node node)
 {
     if (node.HCost != int.MaxValue)
     {
         return;
     }
     else
     {
         node.HCost = PathCalculator.GetHCost(grid, node);
         return;
     }
 }
예제 #20
0
        // this method uses the PathCalculator class to calculate the shortest path between 2 points and saves the path into a list
        // the put that list in the agv object
        private async void ShortestPathAsync(int x, int y)
        {
            while (wh.AGVList[0].PointList.Count != 0)
            {
                await Task.Delay(3000);
            }
            Point          point1 = new Point(wh.AGVList[0].PositionX, wh.AGVList[0].PositionY);
            Point          point2 = new Point(x, y);
            PathCalculator path   = new PathCalculator(point1, point2);

            path.CalculatePath();
            wh.AGVList[0].PointList = path.GetPointList();
        }
예제 #21
0
    public void Init(Transform startT, Transform endT, Transform look, float time)
    {
        start      = startT;
        end        = endT;
        duration   = time;
        lookTarget = look;

        path = new NavMeshPath();
        var result = NavMesh.CalculatePath(startT.position, endT.position, NavMesh.AllAreas, path);

        pathCalculator = new PathCalculator(path, time);
        ready          = true;
    }
예제 #22
0
        static void Main(string[] args)
        {
            var inputHelper = new InputHelper(Console.WriteLine, Console.ReadLine);

            var numberOfStations = inputHelper.GetNumberOfStations();
            var stations         = inputHelper.GetPimpStations(numberOfStations);

            var pathCalculator = new PathCalculator();

            var startIndex = pathCalculator.GetStartPumpStationIndex(stations);

            Console.WriteLine(startIndex);
            Console.ReadLine();
        }
예제 #23
0
        public void DrawLine(int x1, int y1, int x2, int y2, bool drawFirstDot = false)
        {
            PathCalculator           lineCalc = new PathCalculator();
            List <Tuple <int, int> > dotList  = lineCalc.CalculateLinePath(x1, y1, x2, y2);

            if (drawFirstDot)
            {
                DrawDot(dotList[0].Item1, dotList[0].Item2);
            }

            for (int i = 1; i < dotList.Count; i++)
            {
                DrawBorder(dotList[i].Item1, dotList[i].Item2);
            }
        }
예제 #24
0
        static void Main(string[] args)
        {
            var dataFiles = FileWorker.GetDataFileNames();
            int i         = 0;

            foreach (var file in dataFiles)
            {
                i++;
                var dataset = FileWorker.ReadDataset(file);
                var mixes   = TopologyConstructor.CreateTopology(dataset);
                PathCalculator.CalculatePaths(mixes);
                FileWorker.WriteResults(mixes, file.Substring(file.LastIndexOf("\\")));
                Console.WriteLine($@"{i} files already processed");
            }
        }
예제 #25
0
 private void OnCreationFinished(List <Tile> generatedTiles)
 {
     interactableTiles.Clear();
     allTiles.Clear();
     for (int i = 0; i < generatedTiles.Count; i++)
     {
         if (generatedTiles[i].TileFace != TileFaces.Empty)
         {
             generatedTiles[i].View.OnTileClicked += OnTileClicked;
             interactableTiles.Add(generatedTiles[i]);
         }
     }
     allTiles.AddRange(generatedTiles);
     currentHint = PathCalculator.GetValidPathPair(interactableTiles);
 }
예제 #26
0
        /* TODO: Allow easy comparison across actions...
         * public int[] GetAttackDistanceOfTankToEnemyBasePerTankAction(int playerIndex, int tankNumber)
         * {
         *  MobileState tankState = GetTankState(playerIndex, tankNumber);
         *  int[] attackDistancesByTankAction = new int[Constants.TANK_ACTION_COUNT];
         *  foreach (TankAction tankAction in TankHelper.TankActions)
         *  {
         *      if (tankState.IsActive)
         *      {
         *
         *
         *          DirectionalMatrix<DistanceCalculation> attackDistanceMatrix
         *              = GameState.CalculationCache.GetIncomingDistanceMatrixForBase(1 - playerIndex);
         *          return attackDistanceMatrix[tankState].Distance;
         *      }
         *      return Constants.UNREACHABLE_DISTANCE;
         *  }
         *  return attackDistancesByTankAction;
         * }
         */

        public TankAction[] GetActionsToAttackEnemyBase(int playerIndex, int tankNumber)
        {
            MobileState tankState = GetTankState(playerIndex, tankNumber);

            if (tankState.IsActive)
            {
                Base             enemyBase        = GetEnemyBase(playerIndex);
                FiringLineMatrix firingLineMatrix = GameState.CalculationCache.FiringLinesForPointsMatrix;
                DirectionalMatrix <DistanceCalculation> attackDistanceMatrix
                    = GameState.CalculationCache.GetIncomingDistanceMatrixForBase(1 - playerIndex);
                return(PathCalculator.GetTankActionsOnIncomingShortestPath(attackDistanceMatrix, tankState,
                                                                           enemyBase.Pos, firingLineMatrix, keepMovingCloserOnFiringLastBullet: true));
            }
            return(NoTankActions);
        }
예제 #27
0
        public void Initialize()
        {
            _system = new Mock <IFileSystemAccess>();

            const string baseDir = @"c:\a\b\";

            _system.Setup(s => s.Normalize(Path)).Returns(Path);
            _system.Setup(s => s.GetDirectoryName(Source)).Returns(baseDir);

            _system.Setup(s => s.Combine(baseDir, Path)).Returns(Target);
            _system.Setup(s => s.Combine(Target, PathCalculator.ProjectFilePattern)).Returns(FileTarget);

            _system.Setup(s => s.GetFullPath(It.IsAny <string>())).Returns((string s) => s);

            _pathCalculator = new PathCalculator(_system.Object);
        }
예제 #28
0
        private void Update()
        {
            GameObject playerGO = GameObject.FindGameObjectWithTag("Player");

            if (playerGO == null)
            {
                return;
            }
            startingPoint = playerGO.transform;


            Vector2Int goalCoords  = level.transformer.ScreenToTile(Input.mousePosition);
            Vector2Int startCoords = level.transformer.WorldToTile(startingPoint.transform.position);

            List <Vector2Int> route = PathCalculator.FindPath(level, startCoords, goalCoords);

            DrawRoute(route);
        }
예제 #29
0
        public void ShortestPath(int x, int y)
        {
            Point point1 = new Point(wh.AGVList[0].PositionX, wh.AGVList[0].PositionY);
            Point point2 = new Point(x, y);
            //Map map = new Map();
            //map.CreateMap("map", iBlade.wh.Width, iBlade.wh.Height);
            PathCalculator path   = new PathCalculator(iBlade.map.TilesArray);
            List <Tile>    mylist = new List <Tile>();

            mylist = path.FindShortestPath(point1, point2);
            foreach (var item in mylist)
            {
                wh.AGVList[0].PointList.Add(item.Location);
            }
            wh.AGVList[0].PositionX = mylist[mylist.Count - 1].Location.X;
            wh.AGVList[0].PositionY = mylist[mylist.Count - 1].Location.Y;
            iBlade.Status           = true;
        }
예제 #30
0
 private void CheckWinLoseConditions()
 {
     if (interactableTiles.Count == 0)
     {
         currentLevel.gameWon = true;
         UiView.ShowGameSummary(true, currentLevel.CurrentHighscore);
     }
     else
     {
         if (!IsHintValid())
         {
             currentHint = PathCalculator.GetValidPathPair(interactableTiles);
             if (currentHint == null)
             {
                 UiView.ShowGameSummary(false, currentLevel.CurrentHighscore);
             }
         }
     }
 }