Moteur : chances de gagner le match (table de gnubg), export SGF d'un match entier
Commande mwc d'engine-cli et engine_match_chances_of : chances au score (getMEAtScore) et conversion d'une équité (eq2mwc), comparées à gnubg de bureau. Export d'un match entier en SGF, relu par gnubg (load match). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
ee661661fd
commit
f9b8663afb
@@ -391,6 +391,53 @@ def level_cube(case, name):
|
||||
}
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
# Chances de gagner le match (analyses.json, « chances ») : la table d'équité
|
||||
# de match de gnubg au score du Match ID, et la conversion d'une équité
|
||||
# normalisée en chances de gagner le match (eq2mwc), avec le coût d'une
|
||||
# erreur des statistiques de match (updateStatcontext, analysis.c :
|
||||
# « eq2mwc(rSkill, &ci) - eq2mwc(0.0f, &ci) »).
|
||||
|
||||
START_POSITION = "4HPwATDgc/ABMA"
|
||||
|
||||
|
||||
def single(x):
|
||||
"""x arrondi en simple précision, comme le calcul de gnubg en float."""
|
||||
return struct.unpack("<f", struct.pack("<f", x))[0]
|
||||
|
||||
|
||||
def met_at_score(ci):
|
||||
"""getMEAtScore de gnubg (matchequity.c) pour le joueur au trait : une
|
||||
lecture de la table que gnubg donne (gnubg.met), sans autre calcul.
|
||||
Avant ou pendant la partie Crawford, la table d'avant Crawford ; après,
|
||||
la table d'après Crawford du joueur qui mène."""
|
||||
length = ci["matchto"]
|
||||
table = gnubg.met(length)
|
||||
away0 = length - ci["score"][0] - 1
|
||||
away1 = length - ci["score"][1] - 1
|
||||
if not ci["crawford"] and (away0 == 0 or away1 == 0):
|
||||
me0 = single(1.0 - table[2][away1]) if away0 == 0 else table[1][away0]
|
||||
else:
|
||||
me0 = table[0][away0][away1]
|
||||
return me0 if ci["move"] == 0 else single(1.0 - me0)
|
||||
|
||||
|
||||
def match_chances(case):
|
||||
gnubg.command("set gnubgid %s:%s" % (START_POSITION, case["match_id"]))
|
||||
if gnubg.matchid() != case["match_id"]:
|
||||
raise SystemExit("%s : gnubg relit %s" % (case["id"], gnubg.matchid()))
|
||||
ci = cube_info()
|
||||
zero = gnubg.eq2mwc(0.0, ci)
|
||||
return {
|
||||
"at_score": f32(met_at_score(ci)),
|
||||
"equities": [
|
||||
{"equity": equity, "mwc": f32(gnubg.eq2mwc(equity, ci)),
|
||||
"loss": f32(single(gnubg.eq2mwc(equity, ci) - zero))}
|
||||
for equity in case["equities"]
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
def write_analysis(out_dir, result):
|
||||
with open(os.path.join(out_dir, result["id"] + ".json"), "w", encoding="utf-8") as f:
|
||||
json.dump(result, f, ensure_ascii=False, indent=2)
|
||||
@@ -408,10 +455,12 @@ def generate_analyses(commit):
|
||||
gnubg.command("set display off")
|
||||
gnubg.command("set automatic game off")
|
||||
gnubg.command("set automatic roll off")
|
||||
for kind in ("moves", "cubes", "levels"):
|
||||
for kind in ("moves", "cubes", "levels", "chances"):
|
||||
for case in cases[kind]:
|
||||
result = dict(case, type=kind[:-1], gnubg_commit=commit, met=MET)
|
||||
if kind == "moves":
|
||||
if kind == "chances":
|
||||
result.update(match_chances(case))
|
||||
elif kind == "moves":
|
||||
result["plies"] = {}
|
||||
for ply in PLIES:
|
||||
result["plies"][str(ply)], result["luck"] = analyse_move(case, ply)
|
||||
|
||||
Reference in New Issue
Block a user