Fusion de main (analyse du match, 1l) ; l'abandon passe en version 4 des événements
La version 3 est celle de main (identifiant de match) ; l'abandon prend la version 4, avec la migration des versions 1, 2 et 3 testée. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+52
-1
@@ -70,10 +70,61 @@ def check(path):
|
||||
return errors
|
||||
|
||||
|
||||
def check_game_records(records, expected, where):
|
||||
"""Avance dans la partie courante de gnubg enregistrement par
|
||||
enregistrement : après chaque coup, sa position doit être celle du
|
||||
journal."""
|
||||
gnubg.command("first move")
|
||||
after = []
|
||||
for record in records:
|
||||
gnubg.command("next")
|
||||
if record["action"] == "move":
|
||||
after.append(gnubg.positionid())
|
||||
errors = []
|
||||
if len(after) != len(expected["after"]):
|
||||
errors.append("%s%d coups lus, %d attendus" % (where, len(after), len(expected["after"])))
|
||||
for i, (got, want) in enumerate(zip(after, expected["after"])):
|
||||
if got != want:
|
||||
errors.append("%saprès le coup %d : gnubg %s, journal %s" % (where, i + 1, got, want))
|
||||
break
|
||||
return errors
|
||||
|
||||
|
||||
def check_match(path):
|
||||
"""Un match entier (étape 1l) : gnubg charge le fichier (load match),
|
||||
y trouve la longueur du match, et pour chaque partie, dans l'ordre, le
|
||||
score avant elle, les positions après chaque coup et le résultat."""
|
||||
with open(path[:-4] + ".json") as f:
|
||||
expected = json.load(f)
|
||||
gnubg.command("load match " + path)
|
||||
match = gnubg.match(analysis=0, boards=0, statistics=0, verbose=0)
|
||||
games = match["games"]
|
||||
errors = []
|
||||
if match["match-info"].get("match-length") != expected["length"]:
|
||||
errors.append("longueur : gnubg %s" % match["match-info"])
|
||||
if len(games) != len(expected["games"]):
|
||||
return errors + ["%d parties lues, %d attendues" % (len(games), len(expected["games"]))]
|
||||
gnubg.command("first game")
|
||||
for index, (game, want) in enumerate(zip(games, expected["games"])):
|
||||
where = "partie %d : " % (index + 1)
|
||||
if index > 0:
|
||||
gnubg.command("next game")
|
||||
info = game["info"]
|
||||
score = (info.get("score-X"), info.get("score-O"))
|
||||
if score != (want["score"]["computer"], want["score"]["player"]):
|
||||
errors.append("%sscore avant la partie : gnubg %s, journal %s" % (where, score, want["score"]))
|
||||
errors += check_game_records(list(game["game"]), want, where)
|
||||
result = want["result"]
|
||||
winner = "O" if result["winner"] == "player" else "X"
|
||||
if (info.get("winner"), info.get("points-won")) != (winner, result["points"]):
|
||||
errors.append("%srésultat : gnubg %s, journal %s" % (where, info, result))
|
||||
return errors
|
||||
|
||||
|
||||
failures = 0
|
||||
paths = sorted(glob.glob(os.path.join(FOLDER, "*.sgf")))
|
||||
for path in paths:
|
||||
errors = check(path)
|
||||
errors = check_match(path) if os.path.basename(path).startswith("match-") else check(path)
|
||||
name = os.path.basename(path)
|
||||
if errors:
|
||||
failures += 1
|
||||
|
||||
Reference in New Issue
Block a user