コード例 #1
0
        public static NMap CaveWallMap(int width, int height, float rate, int holeLeft)//dig map
        {
            NMap map = new NMap(width, height);

            map.Noise(rate);
            CellularAutomata2D rule = new CellularAutomata2D("s45678b5678");

            map = rule.Run(map, 3);
            var blobs = NBlob.Find(map, 255);

            blobs.FillByLeftBlob(map, holeLeft, 0);
            blobs.NoiseConnect(map, 255);

            map = map.InverseVal();
            bool    HorV     = RandomNum.Roll(0.5f);
            NLocate Entrance = new NLocate();
            NLocate Exit     = new NLocate();

            if (HorV)
            {
                Entrance = RandomSelect <NLocate> .Select(new List <NLocate>(map.LeftLocates(0))).Right();

                Exit = RandomSelect <NLocate> .Select(new List <NLocate>(map.RightLocates(0))).Left();
            }
            else
            {
                Entrance = RandomSelect <NLocate> .Select(new List <NLocate>(map.TopLocates(0))).Down();

                Exit = RandomSelect <NLocate> .Select(new List <NLocate>(map.BottomLocates(0))).Up();
            }
            map.SetBlock(Entrance.Square(1), 0);
            map.SetBlock(Exit.Square(1), 0);
            map.SetBlock(Entrance, (byte)DungeonBuilding.Port);
            map.SetBlock(Exit, (byte)DungeonBuilding.Port);

            NLocationRecogition.FindTreasure(map, 3);
            NLocationRecogition.FindDeadEnd(map, 3);

            NLocationRecogition.FindPassage(map, 4);

            return(map);
        }
コード例 #2
0
ファイル: PathFind.cs プロジェクト: fenixnix/Fractals
 static public void SelfTest()
 {
     {
         Console.WriteLine("B* SelfTest:");
         var     map = new NMap(20, 20);
         NLocate loc = new NLocate(10, 5);
         map.SetBlock(loc.Square(4), 255);
         loc = new NLocate(10, 10);
         map.SetBlock(loc.Square(3), 255);
         map.SetBlock(loc.LineTo(new NLocate(10, 17)), 255);
         loc = new NLocate(10, 17);
         map.SetBlock(loc.LineTo(new NLocate(2, 17)), 255);
         Console.WriteLine(map.Print());
         var path = BStar(new NLocate(0, 12), new NLocate(18, 9), map);
         foreach (var p in path)
         {
             map.SetBlock(p, 1);
         }
         Console.WriteLine(map.Print());
     }
     {
         Console.WriteLine("A* SelfTest:");
         var     map = new NMap(20, 20);
         NLocate loc = new NLocate(10, 5);
         map.SetBlock(loc.Square(4), 255);
         loc = new NLocate(10, 10);
         map.SetBlock(loc.Square(3), 255);
         map.SetBlock(loc.LineTo(new NLocate(10, 17)), 255);
         loc = new NLocate(10, 17);
         map.SetBlock(loc.LineTo(new NLocate(2, 17)), 255);
         Console.WriteLine(map.Print());
         var path = AStar(new NLocate(0, 12), new NLocate(18, 9), map);
         foreach (var p in path)
         {
             map.SetBlock(p, 1);
         }
         Console.WriteLine(map.Print());
     }
 }