public void NoiseConnectOnce(NMap map, byte val) { NLocate loc1, loc2; FindLocationPair(map, val, out loc1, out loc2); NMove.Noise(map, loc1, loc2, 0, val); }
public static NMap DrunkMazeWallMap(int width, int height) { NMap map = new NMap(width, height, 255); NMove.DrunkardWalk(map, map.Center(), 0); return(map); }
public void Fill(NMap map, byte val) { foreach (var l in Set) { map.SetBlock(l.X, l.Y, val); } }
public void AxisConnectOnce(NMap map, byte val) { NLocate loc1, loc2; FindLocationPair(map, val, out loc1, out loc2); NMove.AxisLine(map, loc1, loc2, val); }
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)); } } } }
static public void FindDoor(NMap map, byte mark) { List <string> types = new List <string>(); types.Add( "000" + "101" + "101"); types.Add( "101" + "101" + "000"); types.Add( "110" + "000" + "110"); types.Add( "011" + "000" + "011"); MatchTypes(map, mark, types); }
static public void Fill(NMap map, byte fillType, int cnt) { for (int i = 0; i < cnt; i++) { FillOnce(map, fillType); } }
public static void DrunkardWalk(NMap map, NLocate start, byte val) { NLocate currentLocation = start; Stack <NLocate> rounte = new Stack <NLocate>(); rounte.Push(start); DrunkWalkItr(map, currentLocation, rounte, val); }
public NMap MirrorXExpendDown() { var res = new NMap(Width, Height + Height); res.SetBlock(0, Height, MirrorX()); res.SetBlock(0, 0, this); return(res); }
public NMap MirrorYExpendRight() { var res = new NMap(Width + Width, Height); res.SetBlock(Width, 0, MirrorY()); res.SetBlock(0, 0, this); return(res); }
public void FillByLeftBlob(NMap map, int cnt = 1, byte val = 255) { while (Blobs.Count > cnt) { Blobs.Sort((x, y) => x.AreaSize().CompareTo(y.AreaSize())); Blobs[0].Fill(map, val); Blobs.RemoveRange(0, 1); } }
public void Draw(NMap map) { byte cnt = 0; foreach (var b in Blobs) { b.Fill(map, cnt); cnt++; } }
public NMap InverseVal() { var res = new NMap(Width, Height); for (int i = 0; i < DataSize(); i++) { res.SetBlock(i, ((byte)(255 - Datas[i]))); } return(res); }
public NMap(NMap map) { Width = map.Width; Height = map.Height; Datas.Clear(); for (int i = 0; i < DataSize(); i++) { Datas.Add(map.GetBlock(i)); } }
public void SetBlock(int x, int y, NMap src) { for (int row = 0; row < src.Height; row++) { for (int col = 0; col < src.Width; col++) { SetBlock(x + col, y + row, src.GetBlock(col, row)); } } }
void FillSmallBlob(NMap map, int lessThan, byte val = 255) { foreach (var blob in Blobs) { if (blob.AreaSize() <= lessThan) { blob.Fill(map, val); } } }
public static NMap MazeWallMap(int width, int height, float rate) { NMap map = new NMap(width, height); map.Noise(rate); CA_Rule rule = new CA_Rule(CAClassicRules.GetClassicRule("Mazectric")); map = rule.Run(map, 3); var blobs = NBlob.Find(map, 0); blobs.NoiseConnect(map, 0); return(map); }
public NMap MirrorX() { var res = new NMap(Width, Height); for (int row = 0; row < Height; row++) { for (int col = 0; col < Width; col++) { res.SetBlock(col, Height - 1 - row, GetBlock(col, row)); } } return(res); }
public static void AxisLine(NMap map, NLocate src, NLocate dst, byte digType) { if (src.Equals(dst)) { return; } int dx = dst.X - src.X; int dy = dst.Y - src.Y; NLocate crossLoc = Math.Abs(dx) > Math.Abs(dy) ? new NLocate(dst.X, src.Y) : new NLocate(src.X, dst.Y); Line(map, src, crossLoc, digType); Line(map, dst, crossLoc, digType); map.SetBlock(crossLoc, digType); }
static public List <NLocate> BStar(NLocate src, NLocate dst, NMap map) { GPath.Clear(); NPathNode rootNode = new NPathNode(src.X, src.Y); List <int> bufferIndex = new List <int>(); //return BStarStep(src, dst, map, bufferIndex, rootNode); if (GPath != null) { return(GPath); } Console.WriteLine("Fail to Find Path!!!"); return(new List <NLocate>()); }
public static NMap ArenaBlockMap(int width, int height, float rate, int holeLeft) { NMap map = new NMap(width, height); map.Noise(rate); CA_Rule rule = new CA_Rule("s45678b5678"); map = rule.Run(map, 3); var blobs = NBlob.Find(map, 255); blobs.FillByLeftBlob(map, holeLeft, 0); blobs = NBlob.Find(map, 0); blobs.NoiseConnect(map, 0); return(map); }
static public void MatchCountAround(NMap map, byte valid, byte mark, int cnt) { for (int row = 0; row < map.Height; row++) { for (int col = 0; col < map.Width; col++) { if (map.CountAround(col, row, valid) == cnt) { ; } { map.SetBlock(col, row, mark); } } } }
static void FloodFillBlob(NMap map, NLocate loc, NLocateSet set, byte valid) { if (!map.WithIn(loc)) { return; } if (map.GetBlock(loc.X, loc.Y) == valid) { map.SetBlock(loc.X, loc.Y, (byte)(255 - valid)); set.Set.Add(loc); foreach (var l in loc.Direction4()) { FloodFillBlob(map, l, set, valid); } } }
public static NBlob Find(NMap map, byte valid) { var res = new NBlob(); var tmp = new NMap(map); for (int i = 0; i < tmp.DataSize(); i++) { if (tmp.GetBlock(i) == valid) { var set = new NLocateSet(); FloodFillBlob(tmp, new NLocate(i % tmp.Width, i / tmp.Width), set, valid); res.Blobs.Add(set); } } return(res); }
private static void MatchTypes(NMap map, byte mark, List <string> types) { for (int row = 0; row < map.Height; row++) { for (int col = 0; col < map.Width; col++) { foreach (var t in types) { if (map.Match(col, row, t)) { map.SetBlock(col, row, mark); } } } } }
static void DrunkWalkItr(NMap map, NLocate currentLoc, Stack <NLocate> rounte, byte val, int step = 1) { if (rounte.Count > map.DataSize() / (4 * step)) { Console.WriteLine("I am awake !!!"); return; } map.SetBlock(currentLoc, val); List <NLocate> locs = new List <NLocate>(); List <NLocate> stepAroundLocs = new List <NLocate>(); stepAroundLocs.Add(new NLocate(currentLoc.X + step, currentLoc.Y)); stepAroundLocs.Add(new NLocate(currentLoc.X - step, currentLoc.Y)); stepAroundLocs.Add(new NLocate(currentLoc.X, currentLoc.Y + step)); stepAroundLocs.Add(new NLocate(currentLoc.X, currentLoc.Y - step)); //Console.WriteLine(map.Print()); foreach (var l in stepAroundLocs) { if ((map.GetBlock(l) != val) && (map.WithIn(l))) { locs.Add(l); } } if (locs.Count > 0) { var dLoc = RandomSelect <NLocate> .Select(locs); Line(map, currentLoc, dLoc, val); rounte.Push(dLoc); DrunkWalkItr(map, dLoc, rounte, val); } else { rounte.Pop(); if (rounte.Count > 0) { DrunkWalkItr(map, rounte.Peek(), rounte, val); } else { Console.WriteLine("no way!!!"); return; } } }
public static void Line(NMap map, NLocate src, NLocate dst, byte digType) { if (src.Equals(dst)) { return; } if (map.WithIn(src)) { map.SetBlock(src.X, src.Y, digType); } List <NLocate> mos = new List <NLocate>(); mos.AddRange(src.Direction4()); mos.Sort((x, y) => x.DistanceTo(dst).CompareTo(y.DistanceTo(dst))); Line(map, mos[0], dst, digType); }
public void Connect(NMap map, byte val, ConnectOnceType connectOnceType) { var cnt = 0; while (Blobs.Count > 1) { connectOnceType(map, val); Blobs = Find(map, val).Blobs; if (cnt > 100) { break; } cnt++; } }
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); }
public void FindLocationPair(NMap map, byte val, out NLocate loc1, out NLocate loc2) { double minVal = double.MaxValue; NLocate minLoc1 = new NLocate(0, 0); NLocate minLoc2 = new NLocate(0, 0); for (int i = 1; i < Blobs.Count; i++) { NLocate tloc1, tloc2; var dis = Blobs[0].DistanceTo(Blobs[i], out tloc1, out tloc2); if (dis < minVal) { minVal = dis; minLoc1 = tloc1; minLoc2 = tloc2; } } loc1 = minLoc1; loc2 = minLoc2; }