Esempio n. 1
0
        public static int GetManhattanDistance(Hero hero1, Hero hero2)
        {
            uint key = (uint)((hero1.Dimensions >> Hero.PositionX) | (hero2.Dimensions << (16 - Hero.PositionX)));
            byte distance;

            lock (locker)
            {
                if (!ManhattanDistance.TryGetValue(key, out distance))
                {
                    distance = (byte)(Math.Abs(hero1.X - hero2.X) + Math.Abs(hero1.Y - hero2.Y));
                    ManhattanDistance[key] = distance;
                }
            }
            return(distance);
        }
Esempio n. 2
0
        public static int GetManhattanDistance(Tile tile0, Tile tile1)
        {
            uint key = (uint)((tile0.Dimensions >> Hero.PositionX) | (tile1.Dimensions << (16 - Hero.PositionX)));

            byte distance;

            lock (locker)
            {
                if (!ManhattanDistance.TryGetValue(key, out distance))
                {
                    distance = (byte)(Math.Abs(tile0.X - tile1.X) + Math.Abs(tile0.Y - tile1.Y));
                    ManhattanDistance[key] = distance;
                }
            }
            return(distance);
        }