Files
gplan-2/game/smoke/experiment_density.gd
T

69 lines
2.6 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# VERTICAL SLICE - NOT FOR PRODUCTION
# 一次性实验:不同 mine_density 下的 R₀ 占比 / 幸存雷数 / 残余挖掘量 / 推理率——为切片临时调参提供数据。
extends SceneTree
func _initialize() -> void:
var db = load("res://core/config_db.gd").new()
db.load_tables("res://data/tables", true)
var board_generator = load("res://core/board_generator.gd").new()
print("=== 密度实验(L1 10×10 target0.88 / L2 12×12 target0.90,各 8 种子)===")
print("d\t|M|/N\tR₀\tR₀/|S|\t残余挖掘\tinf\tatt")
for d in [0.22, 0.25, 0.28, 0.30, 0.33]:
for cfg in [[10, 10, 0.88, 50], [12, 12, 0.90, 60]]:
var w: int = cfg[0]
var h: int = cfg[1]
var t: float = cfg[2]
var ms: int = cfg[3]
var agg := {"m": 0, "r0": 0, "rem": 0, "inf": 0.0, "att": 0, "n": 0}
for s in range(8):
var row := {
"level_index": 1, "node_depth": 0, "board_width": w, "board_height": h,
"mine_density": d, "inferability_target": t, "solver_rules": "single_subset",
"min_safe_count": ms, "max_gen_attempts": 16,
"board_type": "dungeon",
}
_patch_row(row, d)
var params := _params_from(row)
var rg := RandomNumberGenerator.new()
rg.seed = 1000 + s
var b = board_generator.generate(1, 0, rg, _db(db, row))
if b == null:
continue
agg.m += b.mines.size()
agg.r0 += int(b.metrics.r0_count)
agg.rem += b.safe_cells().size() - int(b.metrics.r0_count)
agg.inf += float(b.metrics.inferability)
agg.att += int(b.metrics.attempts_used)
agg.n += 1
if agg.n > 0:
var n := float(agg.n)
var n_placed: int = int(round(d * float(w * h - 9)))
print("%.2f %dx%d\t%d/%d\t%d\t%.2f\t%d\t%.3f\t%.1f" % [d, w, h, int(agg.m / n + 0.5), n_placed, int(agg.r0 / n + 0.5), agg.r0 / n / (w * h - int(agg.m / n + 0.5)), int(agg.rem / n + 0.5), agg.inf / n, agg.att / n])
quit(0)
# --- 简易 db 替身:只供给本实验的行 ---
var _row_override: Dictionary = {}
func _patch_row(row: Dictionary, _d: float) -> void:
_row_override = row
func _params_from(row: Dictionary) -> Dictionary:
return {
"L": 1, "D": 0, "w": int(row.board_width), "h": int(row.board_height),
"density": float(row.mine_density), "target": float(row.inferability_target),
"solver_rules": "single_subset", "min_safe": int(row.min_safe_count),
"max_attempts": int(row.max_gen_attempts), "board_type": "dungeon",
}
class FakeDB:
var row: Dictionary
func resolve_board_gen(_L: int, _D: int) -> Dictionary:
return row
func status_effect_row(_id: String) -> Dictionary:
return {}
func _db(_real, row: Dictionary):
var f := FakeDB.new()
f.row = row
return f