diff options
Diffstat (limited to 'src/LivingVillage.Desktop.Tests/MapGenTests.fs')
| -rw-r--r-- | src/LivingVillage.Desktop.Tests/MapGenTests.fs | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/LivingVillage.Desktop.Tests/MapGenTests.fs b/src/LivingVillage.Desktop.Tests/MapGenTests.fs index f426a8a..6486dd7 100644 --- a/src/LivingVillage.Desktop.Tests/MapGenTests.fs +++ b/src/LivingVillage.Desktop.Tests/MapGenTests.fs @@ -298,6 +298,53 @@ type MapGenTests () = Assert.AreEqual<int64>(6042052L, checksum (MapGen.generateWithSize 64 48 (uint64 4242))) Assert.AreEqual<int64>(1284656962L, checksum (MapGen.generateWithSize 256 192 (uint64 4242))) + // ---- P26:河岸装饰(护岸石垒/芦苇/垂柳)仅大图、落在岸格且不挡通行 ---- + + [<TestMethod>] + member _.RiverDecorationsOnlyEnabledOnLargeMaps () = + Assert.IsFalse((MapGen.paramsForSize 64 48 (uint64 1)).RiverDecorations) + Assert.IsFalse((MapGen.paramsForSize 256 192 (uint64 1)).RiverDecorations) + Assert.IsTrue((MapGen.paramsForSize 512 384 (uint64 1)).RiverDecorations) + Assert.AreEqual<int>(0, (MapGen.generateWithSize 64 48 (uint64 4242)).Decorations.Length) + Assert.AreEqual<int>(0, (MapGen.generateWithSize 256 192 (uint64 4242)).Decorations.Length) + + [<TestMethod>] + member _.RiverbankDecorationsSitOnBanksAndNeverBlockPathsOrBridges () = + let map = MapGen.generateWithSize 512 384 (uint64 4242) + Assert.IsTrue(map.Decorations.Length > 0, "512x384 must place riverbank decorations") + let pathSet = System.Collections.Generic.HashSet<int>(map.Paths |> List.map (fun (x, y) -> y * map.Width + x)) + let bridgeSet = System.Collections.Generic.HashSet<int>(map.Bridges |> List.map (fun (x, y) -> y * map.Width + x)) + let water x y = map.Tiles.[y * map.Width + x] = int MapGen.GroundTile.Water + let inCore x y = x >= map.Core.MinX && x <= map.Core.MaxX && y >= map.Core.MinY && y <= map.Core.MaxY + for decoration in map.Decorations do + let footprint = + match decoration.Kind with + | MapGen.Willow -> [ decoration.Y; decoration.Y + 1 ] + | _ -> [ decoration.Y ] + for y in footprint do + let i = y * map.Width + decoration.X + Assert.AreNotEqual<int>(int MapGen.GroundTile.Water, map.Tiles.[i], "decoration must sit on land") + Assert.IsFalse(pathSet.Contains i, "decoration must not block a path tile") + Assert.IsFalse(bridgeSet.Contains i, "decoration must not block a bridge tile") + Assert.IsFalse(inCore decoration.X y, "decoration must stay outside the core") + // Bank adjacency: at least one footprint tile must touch the river orthogonally. + let touchesWater = + footprint + |> List.exists (fun y -> + [ (decoration.X + 1, y); (decoration.X - 1, y); (decoration.X, y + 1); (decoration.X, y - 1) ] + |> List.exists (fun (nx, ny) -> + nx >= 0 && nx < map.Width && ny >= 0 && ny < map.Height && water nx ny)) + Assert.IsTrue(touchesWater, "decoration must line the riverbank, not float inland") + + [<TestMethod>] + member _.LargeMapRiverDecorationsAreDeterministic () = + let a = MapGen.generateWithSize 512 384 (uint64 4242) + let b = MapGen.generateWithSize 512 384 (uint64 4242) + Assert.IsTrue(a.Decorations = b.Decorations) + Assert.AreEqual<string>(MapGen.serialize a, MapGen.serialize b) + let c = MapGen.generateWithSize 512 384 (uint64 7) + Assert.AreNotEqual<string>(MapGen.serialize a, MapGen.serialize c) + [<TestMethod>] member _.VisibleRangeClampsAtLegacyMapEdges () = let x0, y0, x1, y1 = MapGen.visibleTileRange 64 48 0 0 2048 1536 |
