Example #1
0
        private AstarDecoratorValues GetPossibilityAt(int x, int z)
        {
            KeyValuePair <int, int> key = new KeyValuePair <int, int>(x, z);

            if (!AllPossibilities.ContainsKey(key))
            {
                return(null);
            }
            return(AllPossibilities[key]);
        }
Example #2
0
        private AstarDecoratorValues ContinuePathFinding(AstarDecoratorValues currentPosition, int startX, int startZ, int destinationX, int destinationZ)
        {
            IEnumerable <AstarDecoratorValues> astarSteps = DiscoverPossibleStepsArround(currentPosition, startX, startZ, destinationX, destinationZ);

            foreach (var astarStep in astarSteps)
            {
                var similarPossibility = GetPossibilityAt(astarStep.PossibleStep.X, astarStep.PossibleStep.Z);

                KeyValuePair <int, int> key = new KeyValuePair <int, int>(astarStep.PossibleStep.X, astarStep.PossibleStep.Z);

                if (AllPossibilities.ContainsKey(key))
                {
                    var older = AllPossibilities[key];
                    if (older.FCost > astarStep.FCost)
                    {
                        AllPossibilities[key] = astarStep;
                    }
                }
                else
                {
                    AllPossibilities[key] = astarStep;
                }

                if (similarPossibility != null && similarPossibility.AlreadyChecked)
                {
                    astarStep.AlreadyChecked = similarPossibility.AlreadyChecked;
                }
            }

            AstarDecoratorValues nextPossibility = GetNextPossibility();

            if (nextPossibility != null)
            {
                if (nextPossibility.HCost == 0)
                {
                    return(nextPossibility);
                }
            }
            return(null);
        }