summaryrefslogtreecommitdiff
path: root/src/LivingVillage.Desktop/MapGen.fs
diff options
context:
space:
mode:
Diffstat (limited to 'src/LivingVillage.Desktop/MapGen.fs')
-rw-r--r--src/LivingVillage.Desktop/MapGen.fs24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/LivingVillage.Desktop/MapGen.fs b/src/LivingVillage.Desktop/MapGen.fs
index c59e6bd..7c7059a 100644
--- a/src/LivingVillage.Desktop/MapGen.fs
+++ b/src/LivingVillage.Desktop/MapGen.fs
@@ -312,6 +312,30 @@ module MapGen =
let generateWithSize (width: int) (height: int) (seed: uint64) : Result =
generate { defaultParams seed with Width = width; Height = height }
+ /// 生成结果的确定性序列化(同 seed 逐字节一致),供回归测试与跨机核对。
+ let serialize (map: Result) : string =
+ let builder = System.Text.StringBuilder()
+ builder.Append(map.Width).Append('x').Append(map.Height).Append('|').Append(map.Seed).Append('|') |> ignore
+ for code in map.Tiles do
+ builder.Append(code).Append(',') |> ignore
+ builder.Append('|') |> ignore
+ for river in map.Rivers do
+ builder.Append(river.CenterY).Append('*').Append(river.Width).Append(';') |> ignore
+ builder.Append('|') |> ignore
+ for (x, y) in map.Bridges do
+ builder.Append(x).Append(':').Append(y).Append(';') |> ignore
+ builder.Append('|') |> ignore
+ for (x, y) in map.Paths do
+ builder.Append(x).Append(':').Append(y).Append(';') |> ignore
+ builder.Append('|') |> ignore
+ for building in map.Buildings do
+ builder
+ .Append(building.Left).Append(':').Append(building.Top).Append(':')
+ .Append(building.Width).Append(':').Append(building.Height).Append(':')
+ .Append(building.DoorX).Append(':').Append(building.DoorY).Append(';')
+ |> ignore
+ builder.ToString()
+
/// 可行走判定:非水,或位于桥面上(桥面仍标记为水但可通行)。
let isWalkable (map: Result) (x: int) (y: int) : bool =
if x < 0 || x >= map.Width || y < 0 || y >= map.Height then