コード例 #1
0
ファイル: PathFind.cs プロジェクト: fenixnix/Fractals
        static public void BStarStep(NLocate src, NLocate dst, NMap map, List <int> bufferIndex, NPathNode pathList)
        {
            if (src.Equals(dst))
            {
                Console.WriteLine("FindPath with B*");
                GPath = new List <NLocate>(pathList.GetPath());
                return;
            }
            var dstLoc = src.NearLocTo(dst);

            if (!map.Alive(dstLoc))
            {
                bufferIndex.Add(dstLoc.ToIndex(map));
                BStarStep(dstLoc, dst, map, bufferIndex, pathList.AddChild(dstLoc.X, dstLoc.Y));
            }
            else
            {
                foreach (var l in src.Branch(dstLoc))
                {
                    if (!bufferIndex.Contains(l.ToIndex(map.Width)) && !map.Alive(l))
                    {
                        bufferIndex.Add(l.ToIndex(map));
                        BStarStep(l, dst, map, bufferIndex, pathList.AddChild(l.X, l.Y));
                    }
                }
            }
        }
コード例 #2
0
ファイル: NLocate.cs プロジェクト: fenixnix/Fractals
        public static void SelfTest()
        {
            var loc    = new NLocate(10, 10);
            var revLoc = loc.Reverse(new NLocate(11, 10));

            Console.WriteLine("Reverse:" + revLoc.x + "," + revLoc.y);

            var branch = loc.Branch(new NLocate(11, 10));

            foreach (var b in branch)
            {
                Console.WriteLine("Branch:" + b.x + "," + b.y);
            }

            NMap map  = new NMap(20, 20);
            var  rect = new NLocate(9, 9).Square(5);

            map.SetBlock(rect, 255);
            Console.WriteLine(map.Print());

            map = new NMap(20, 20);
            var diam = new NLocate(9, 9).Diamond(5);

            map.SetBlock(diam, 255);
            Console.WriteLine(map.Print());

            map = new NMap(20, 20);
            var circle = new NLocate(9, 9).Circle(5);

            map.SetBlock(circle, 255);
            Console.WriteLine(map.Print());

            map = new NMap(20, 20);
            var line = new NLocate(9, 9).LineTo(new NLocate(19, 0));

            map.SetBlock(line, 255);
            Console.WriteLine(map.Print());
        }