Moteur : abandon proposé, réponse de l'ordinateur comme gnubg de bureau
Porte dans engine.c la décision de gnubg 1.08.003 (play.c l. 951-975 et 1074-1097, rollout.c l. 1754-1815), l'expose par engine.h et engine-cli (commande resign), et ajoute sept abandons de référence comparés à gnubg de bureau (make reference). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
da9845466b
commit
e98497e5b1
+41
-1
@@ -50,6 +50,12 @@
|
||||
* no_double ou double (joueur au trait),
|
||||
* take ou pass (son adversaire)
|
||||
* luck POSITION_ID MATCH_ID DÉS chance du jet pour le joueur au trait
|
||||
* resign POSITION_ID MATCH_ID abandon du joueur au trait, avant de
|
||||
* lancer les dés : pour une partie
|
||||
* simple, un gammon et un backgammon,
|
||||
* choix proposé, points concédés et
|
||||
* réponse de l'ordinateur (comme gnubg
|
||||
* de bureau)
|
||||
*
|
||||
* --ply : niveau de gnubg, de 0 (défaut) à 4 (meilleur coup comme « hint »,
|
||||
* analyses comme l'analyse de partie de gnubg).
|
||||
@@ -83,7 +89,7 @@
|
||||
|
||||
/* Liste des commandes, pour les messages d'erreur. */
|
||||
#define COMMANDS "bestmove, moves, legal, cube, eval, position, halfmoves, matchid, reference, " \
|
||||
"levels, analysemove, analysecube, luck, double, take ou aftergame"
|
||||
"levels, analysemove, analysecube, luck, resign, double, take ou aftergame"
|
||||
|
||||
/* Coups gardés dans le classement de la commande reference (comme hint). */
|
||||
#define REFERENCE_MAX_MOVES 10
|
||||
@@ -776,6 +782,38 @@ run_luck_command(const options *opt)
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
/* Genres d'abandon, dans l'ordre d'engine_resignation.options. */
|
||||
static const char *const resign_kind_names[] = { "single", "gammon", "backgammon" };
|
||||
|
||||
/* resign : l'abandon du joueur au trait (voir engine_resignation_of). */
|
||||
static int
|
||||
run_resign_command(const options *opt)
|
||||
{
|
||||
const char *position_id = opt->args[0], *match_id = opt->args[1];
|
||||
engine_resignation r;
|
||||
engine_status status;
|
||||
int i;
|
||||
|
||||
if (opt->arg_count != 2)
|
||||
return usage_error("arguments attendus : POSITION_ID MATCH_ID");
|
||||
status = engine_resignation_of(position_id, match_id, &r);
|
||||
if (status != ENGINE_OK)
|
||||
return print_engine_error(status);
|
||||
printf("{\"position_id\": \"%s\", \"match_id\": \"%s\", \"probabilities\": ",
|
||||
position_id, match_id);
|
||||
print_probabilities(r.probabilities);
|
||||
printf(", \"equity_before\": " NUMBER ", \"options\": [", r.equity_before);
|
||||
for (i = 0; i < ENGINE_RESIGN_KINDS; i++) {
|
||||
const engine_resign_option *o = &r.options[i];
|
||||
printf("%s{\"kind\": \"%s\", \"possible\": %s, \"points\": %d, "
|
||||
"\"equity_after\": " NUMBER ", \"accepted\": %s}", i ? ", " : "",
|
||||
resign_kind_names[i], o->possible ? "true" : "false", o->points, o->equity_after,
|
||||
o->accepted ? "true" : "false");
|
||||
}
|
||||
printf("]}\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
/* Dossier « data » à côté du programme. */
|
||||
static char *
|
||||
default_data_dir(const char *program)
|
||||
@@ -886,6 +924,8 @@ main(int argc, char **argv)
|
||||
result = run_analyse_cube_command(&opt);
|
||||
else if (strcmp(opt.command, "luck") == 0)
|
||||
result = run_luck_command(&opt);
|
||||
else if (strcmp(opt.command, "resign") == 0)
|
||||
result = run_resign_command(&opt);
|
||||
else
|
||||
result = usage_error("commande inconnue : " COMMANDS);
|
||||
|
||||
|
||||
@@ -838,6 +838,82 @@ engine_match_after_game(const char *match_id, int winner, int points,
|
||||
return ENGINE_OK;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- Abandon */
|
||||
|
||||
/*
|
||||
* Réglages de l'évaluation d'un abandon : ecResign de gnubg
|
||||
* (get_eq_before_resign, play.c l. 953), 0 pli sans videau, sans bruit.
|
||||
*/
|
||||
static const evalcontext resign_context = {
|
||||
.fCubeful = FALSE, .nPlies = 0, .fUsePrune = FALSE, .fDeterministic = TRUE, .rNoise = 0.0f
|
||||
};
|
||||
|
||||
/* Gain maximal toléré par l'ordinateur pour accepter (max_gain, play.c
|
||||
* l. 1080). */
|
||||
#define RESIGN_MAX_GAIN 1e-6f
|
||||
|
||||
/* Équité de celui qui abandonne après un abandon du genre kind (1 à 3) :
|
||||
* getResignEquities, rollout.c l. 1804-1813. */
|
||||
static float
|
||||
equity_after_resignation(int kind, const cubeinfo *cube)
|
||||
{
|
||||
float output[NUM_OUTPUTS] = { 0, 0, 0, 0, 0 };
|
||||
|
||||
if (kind > 1)
|
||||
output[OUTPUT_LOSEGAMMON] = 1.0f;
|
||||
if (kind > 2)
|
||||
output[OUTPUT_LOSEBACKGAMMON] = 1.0f;
|
||||
return Utility(output, cube);
|
||||
}
|
||||
|
||||
/* Voir engine.h : play.c l. 951-975 et 1074-1097, rollout.c l. 1754-1815. */
|
||||
engine_status
|
||||
engine_resignation_of(const char *position_id, const char *match_id,
|
||||
engine_resignation *resignation)
|
||||
{
|
||||
position pos;
|
||||
float output[NUM_ROLLOUT_OUTPUTS];
|
||||
float previous;
|
||||
engine_status status;
|
||||
int i;
|
||||
|
||||
memset(resignation, 0, sizeof *resignation);
|
||||
status = decode_position(position_id, match_id, &pos);
|
||||
if (status != ENGINE_OK)
|
||||
return status;
|
||||
start_evaluation();
|
||||
|
||||
/* get_eq_before_resign, dés pas encore jetés : asyncMoveDecisionE, soit
|
||||
* GeneralEvaluationE avec ecResign (play.c l. 973, gnubg.c l. 5446). */
|
||||
if (GeneralEvaluationE(output, (ConstTanBoard) pos.board, &pos.cube, &resign_context) < 0)
|
||||
return ENGINE_ERROR_INTERNAL;
|
||||
for (i = 0; i < ENGINE_NUM_PROBABILITIES; i++)
|
||||
resignation->probabilities[i] = output[i];
|
||||
resignation->equity_before = Utility(output, &pos.cube);
|
||||
|
||||
previous = 0.0f;
|
||||
for (i = 0; i < ENGINE_RESIGN_KINDS; i++) {
|
||||
engine_resign_option *option = &resignation->options[i];
|
||||
int kind = i + 1;
|
||||
|
||||
option->equity_after = equity_after_resignation(kind, &pos.cube);
|
||||
option->points = pos.cube.nCube * kind;
|
||||
/* ComputerTurn, play.c l. 1084 : « if (rEqAfter - rEqBefore <
|
||||
* max_gain) » accepte. */
|
||||
option->accepted = option->equity_after - resignation->equity_before < RESIGN_MAX_GAIN;
|
||||
/* getResignation (rollout.c l. 1767-1789) : un gammon ou un
|
||||
* backgammon n'a de sens que s'il peut arriver (probabilité non
|
||||
* nulle) et qu'il coûte plus que le genre d'en dessous. */
|
||||
if (kind == 1)
|
||||
option->possible = 1;
|
||||
else
|
||||
option->possible = option->equity_after < previous
|
||||
&& output[kind == 2 ? OUTPUT_LOSEGAMMON : OUTPUT_LOSEBACKGAMMON] > 0.0f;
|
||||
previous = option->equity_after;
|
||||
}
|
||||
return ENGINE_OK;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- Analyse d'une décision de videau */
|
||||
|
||||
/* Le plus petit de deux nombres. */
|
||||
|
||||
@@ -452,6 +452,55 @@ typedef struct {
|
||||
engine_status engine_match_after_game(const char *match_id, int winner, int points,
|
||||
engine_match_after *after);
|
||||
|
||||
/* ------------------------------------------------------------- Abandon */
|
||||
|
||||
/*
|
||||
* Abandon (resign) : le joueur au trait, avant de lancer les dés, propose de
|
||||
* perdre tout de suite une partie simple (1), un gammon (2) ou un
|
||||
* backgammon (3). L'ordinateur, son adversaire, accepte ou refuse comme
|
||||
* gnubg de bureau (ComputerTurn, play.c l. 1074-1097, avec
|
||||
* get_eq_before_resign, play.c l. 951-975, et getResignEquities, rollout.c
|
||||
* l. 1800-1815) :
|
||||
* - la position est évaluée à 0 pli, sans videau, sans bruit (ecResign),
|
||||
* du point de vue de celui qui abandonne ;
|
||||
* - son équité « avant » est Utility de cette évaluation, son équité
|
||||
* « après » Utility d'une défaite certaine du genre proposé (en match,
|
||||
* avec les prix des gammons de la table d'équité ; en partie libre, avec
|
||||
* la règle Jacoby si le videau est au centre) ;
|
||||
* - l'ordinateur accepte si l'abandon ne lui coûte rien :
|
||||
* après - avant < 1e-6 (max_gain).
|
||||
* Points concédés (play.c l. 381, MOVE_RESIGN) : la valeur du videau fois
|
||||
* le genre.
|
||||
*
|
||||
* Choix proposés (possible) : la partie simple toujours ; un gammon ou un
|
||||
* backgammon seulement s'il change le résultat (son équité « après » est
|
||||
* plus basse que celle du genre d'en dessous : pas en partie libre avec la
|
||||
* règle Jacoby et le videau au centre, ni en match quand le gammon ne
|
||||
* rapporte rien de plus) et s'il peut encore arriver (probabilité non nulle
|
||||
* dans l'évaluation), comme les tests de getResignation (rollout.c
|
||||
* l. 1754-1796), qui décide si l'ordinateur abandonne lui-même.
|
||||
*/
|
||||
#define ENGINE_RESIGN_KINDS 3
|
||||
|
||||
typedef struct {
|
||||
int possible; /* ce choix est proposé (voir ci-dessus) */
|
||||
int points; /* points concédés : videau fois le genre */
|
||||
float equity_after; /* équité de celui qui abandonne, après */
|
||||
int accepted; /* l'ordinateur accepte */
|
||||
} engine_resign_option;
|
||||
|
||||
typedef struct {
|
||||
float probabilities[ENGINE_NUM_PROBABILITIES]; /* 0 pli, sans videau, vu
|
||||
* de celui qui abandonne */
|
||||
float equity_before; /* son équité si la partie continue (Utility) */
|
||||
engine_resign_option options[ENGINE_RESIGN_KINDS]; /* simple, gammon,
|
||||
* backgammon */
|
||||
} engine_resignation;
|
||||
|
||||
/* L'abandon du joueur au trait, avant de lancer les dés, pour chaque genre. */
|
||||
engine_status engine_resignation_of(const char *position_id, const char *match_id,
|
||||
engine_resignation *resignation);
|
||||
|
||||
/* ------------------------------------------------------------- Analyse */
|
||||
|
||||
/* Appréciation de gnubg pour une perte d'équité (0 ou négative). */
|
||||
|
||||
@@ -234,7 +234,7 @@ décision, puis l'analyse. Rien n'est calculé dans le script : les valeurs
|
||||
viennent des enregistrements de la partie analysée et des statistiques que
|
||||
gnubg en tire.
|
||||
|
||||
`analyses.json` a trois listes :
|
||||
`analyses.json` a quatre listes :
|
||||
|
||||
- `moves` : `position_id`, `match_id`, `dice` et `played`, le coup joué en
|
||||
notation de gnubg (`null` : le meilleur coup selon gnubg, pour les cas qui
|
||||
@@ -243,10 +243,12 @@ gnubg en tire.
|
||||
`no_double` ou `double` pour le joueur au trait, `take` ou `pass` pour son
|
||||
adversaire ;
|
||||
- `levels` : `position_id`, `match_id` et `dice` (`null` : décision de
|
||||
videau).
|
||||
videau) ;
|
||||
- `resigns` : `position_id` et `match_id` (sans dés) d'une position où le
|
||||
joueur au trait propose d'abandonner, avant de lancer les dés.
|
||||
|
||||
Un fichier de résultat reprend le cas, avec `type` (`move`, `cube` ou
|
||||
`level`), `gnubg_commit` et `met`, puis, aux niveaux d'analyse 0 et 2 plis
|
||||
Un fichier de résultat reprend le cas, avec `type` (`move`, `cube`,
|
||||
`level` ou `resign`), `gnubg_commit` et `met`, puis, aux niveaux d'analyse 0 et 2 plis
|
||||
(clés de `plies`, réglages prédéfinis de gnubg sans bruit, filtre
|
||||
« Normal ») :
|
||||
|
||||
@@ -273,7 +275,14 @@ Un fichier de résultat reprend le cas, avec `type` (`move`, `cube` ou
|
||||
(3 et 4 plis sont trop lents pour la suite de tests), `plies` et `noise`
|
||||
(réglages de gnubg), puis `move`, le coup que joue l'ordinateur de gnubg
|
||||
réglé à ce niveau (commande « play »), ou la décision de videau de gnubg
|
||||
avec ces réglages, bruit compris.
|
||||
avec ces réglages, bruit compris ;
|
||||
- **abandon** (`resign`, sans niveaux : gnubg décide toujours à 0 pli sans
|
||||
videau) : `probabilities`, l'évaluation que gnubg fait pour décider
|
||||
(`ecResign` de `play.c` : 0 pli, sans videau ni bruit, vue de celui qui
|
||||
abandonne), puis `resignations`, pour `single`, `gammon` et `backgammon` :
|
||||
la réponse de l'ordinateur de gnubg à la commande « resign » du joueur au
|
||||
trait (`accepted`) et, s'il accepte, les points qu'il gagne (`points`,
|
||||
sinon `null`).
|
||||
|
||||
Deux précautions, faute de quoi gnubg donne des valeurs qui dépendent de ce
|
||||
qu'il a calculé avant :
|
||||
@@ -351,7 +360,12 @@ Pour chaque analyse (`engine-cli analysemove`, `analysecube`, `luck`, et
|
||||
- appréciation (`skill`) et chance (`rating`) identiques, sauf si la valeur
|
||||
de gnubg est à moins de la tolérance d'un seuil (remarque) ;
|
||||
- niveaux : mêmes réglages que gnubg (`engine-cli levels`), même coup choisi,
|
||||
ou même décision de videau et équités à la tolérance près.
|
||||
ou même décision de videau et équités à la tolérance près ;
|
||||
- abandon (`engine-cli resign`) : les cinq probabilités à la tolérance près,
|
||||
la même réponse pour chaque genre (sauf cas limite : l'équité de celui qui
|
||||
abandonne, avant et après, à moins de la tolérance l'une de l'autre,
|
||||
remarque) et les mêmes points. Mesure du 2026-11-13 : écart maximal
|
||||
4,5e-5 sur les sept abandons.
|
||||
|
||||
Le rapport donne, pour chaque écart hors critères, la position et le niveau,
|
||||
le champ, la valeur attendue (gnubg), la valeur obtenue (moteur) et l'écart ;
|
||||
|
||||
@@ -279,5 +279,49 @@
|
||||
"match_id": "cAkAAAAAAAAA",
|
||||
"dice": null
|
||||
}
|
||||
],
|
||||
"resigns": [
|
||||
{
|
||||
"id": "resign-gammon-likely",
|
||||
"description": "Partie libre, videau à 2 chez l'adversaire, attaque subie (gammon perdu à 49 %) : le simple est refusé, le gammon accepté.",
|
||||
"position_id": "sp2DBwDgOfgAaA",
|
||||
"match_id": "EQEAAAAAAAAA"
|
||||
},
|
||||
{
|
||||
"id": "resign-jacoby",
|
||||
"description": "Même position, videau au centre, règle Jacoby : le gammon ne compte pas, le simple est accepté.",
|
||||
"position_id": "sp2DBwDgOfgAaA",
|
||||
"match_id": "MAEAAAAAAAAA"
|
||||
},
|
||||
{
|
||||
"id": "resign-single-accepted",
|
||||
"description": "Partie libre, videau à 2 chez l'adversaire, attaque subie avec moins de gammons (36 %) : le simple est accepté.",
|
||||
"position_id": "tF2DBwDgc/ABUA",
|
||||
"match_id": "EQEAAAAAAAAA"
|
||||
},
|
||||
{
|
||||
"id": "resign-race-small-gammon",
|
||||
"description": "Course perdue, gammon perdu à 0,2 %, videau à 2 : même ce petit risque fait refuser le simple ; le gammon est accepté.",
|
||||
"position_id": "770DAABwd3cAAA",
|
||||
"match_id": "EQEAAAAAAAAA"
|
||||
},
|
||||
{
|
||||
"id": "resign-match-7",
|
||||
"description": "Match en 7 points, 0 à 0, attaque subie : le simple est refusé, le gammon accepté.",
|
||||
"position_id": "sp2DBwDgOfgAaA",
|
||||
"match_id": "MAHgAAAAAAAE"
|
||||
},
|
||||
{
|
||||
"id": "resign-match-post-crawford",
|
||||
"description": "Match en 7 points, 2 à 6 après la partie Crawford : l'adversaire n'a besoin que d'un point, le simple est accepté.",
|
||||
"position_id": "sp2DBwDgOfgAaA",
|
||||
"match_id": "MAHgACAAMAAE"
|
||||
},
|
||||
{
|
||||
"id": "resign-match-cube",
|
||||
"description": "Match en 7 points, 2 à 4, videau à 2 chez l'adversaire : le simple (2 points) est accepté ; le gammon suffit à finir le match.",
|
||||
"position_id": "sp2DBwDgOfgAaA",
|
||||
"match_id": "EQHgACAAIAAE"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"id": "resign-gammon-likely",
|
||||
"description": "Partie libre, videau à 2 chez l'adversaire, attaque subie (gammon perdu à 49 %) : le simple est refusé, le gammon accepté.",
|
||||
"position_id": "sp2DBwDgOfgAaA",
|
||||
"match_id": "EQEAAAAAAAAA",
|
||||
"type": "resign",
|
||||
"gnubg_commit": "14b67984737ded0f6de43d63dcb789f729d9b06b",
|
||||
"met": "Kazaross-XG2",
|
||||
"probabilities": {
|
||||
"win": 0.23634239,
|
||||
"win_gammon": 0.030146752,
|
||||
"win_backgammon": 0.00046920424,
|
||||
"lose_gammon": 0.48970115,
|
||||
"lose_backgammon": 0.03487766
|
||||
},
|
||||
"resignations": {
|
||||
"single": {
|
||||
"accepted": false,
|
||||
"points": null
|
||||
},
|
||||
"gammon": {
|
||||
"accepted": true,
|
||||
"points": 4
|
||||
},
|
||||
"backgammon": {
|
||||
"accepted": true,
|
||||
"points": 6
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"id": "resign-jacoby",
|
||||
"description": "Même position, videau au centre, règle Jacoby : le gammon ne compte pas, le simple est accepté.",
|
||||
"position_id": "sp2DBwDgOfgAaA",
|
||||
"match_id": "MAEAAAAAAAAA",
|
||||
"type": "resign",
|
||||
"gnubg_commit": "14b67984737ded0f6de43d63dcb789f729d9b06b",
|
||||
"met": "Kazaross-XG2",
|
||||
"probabilities": {
|
||||
"win": 0.23634239,
|
||||
"win_gammon": 0.030146752,
|
||||
"win_backgammon": 0.00046920424,
|
||||
"lose_gammon": 0.48970115,
|
||||
"lose_backgammon": 0.03487766
|
||||
},
|
||||
"resignations": {
|
||||
"single": {
|
||||
"accepted": true,
|
||||
"points": 1
|
||||
},
|
||||
"gammon": {
|
||||
"accepted": true,
|
||||
"points": 2
|
||||
},
|
||||
"backgammon": {
|
||||
"accepted": true,
|
||||
"points": 3
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"id": "resign-match-7",
|
||||
"description": "Match en 7 points, 0 à 0, attaque subie : le simple est refusé, le gammon accepté.",
|
||||
"position_id": "sp2DBwDgOfgAaA",
|
||||
"match_id": "MAHgAAAAAAAE",
|
||||
"type": "resign",
|
||||
"gnubg_commit": "14b67984737ded0f6de43d63dcb789f729d9b06b",
|
||||
"met": "Kazaross-XG2",
|
||||
"probabilities": {
|
||||
"win": 0.23634239,
|
||||
"win_gammon": 0.030146752,
|
||||
"win_backgammon": 0.00046920424,
|
||||
"lose_gammon": 0.48970115,
|
||||
"lose_backgammon": 0.03487766
|
||||
},
|
||||
"resignations": {
|
||||
"single": {
|
||||
"accepted": false,
|
||||
"points": null
|
||||
},
|
||||
"gammon": {
|
||||
"accepted": true,
|
||||
"points": 2
|
||||
},
|
||||
"backgammon": {
|
||||
"accepted": true,
|
||||
"points": 3
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"id": "resign-match-cube",
|
||||
"description": "Match en 7 points, 2 à 4, videau à 2 chez l'adversaire : le simple (2 points) est accepté ; le gammon suffit à finir le match.",
|
||||
"position_id": "sp2DBwDgOfgAaA",
|
||||
"match_id": "EQHgACAAIAAE",
|
||||
"type": "resign",
|
||||
"gnubg_commit": "14b67984737ded0f6de43d63dcb789f729d9b06b",
|
||||
"met": "Kazaross-XG2",
|
||||
"probabilities": {
|
||||
"win": 0.23634239,
|
||||
"win_gammon": 0.030146752,
|
||||
"win_backgammon": 0.00046920424,
|
||||
"lose_gammon": 0.48970115,
|
||||
"lose_backgammon": 0.03487766
|
||||
},
|
||||
"resignations": {
|
||||
"single": {
|
||||
"accepted": true,
|
||||
"points": 2
|
||||
},
|
||||
"gammon": {
|
||||
"accepted": true,
|
||||
"points": 4
|
||||
},
|
||||
"backgammon": {
|
||||
"accepted": true,
|
||||
"points": 6
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"id": "resign-match-post-crawford",
|
||||
"description": "Match en 7 points, 2 à 6 après la partie Crawford : l'adversaire n'a besoin que d'un point, le simple est accepté.",
|
||||
"position_id": "sp2DBwDgOfgAaA",
|
||||
"match_id": "MAHgACAAMAAE",
|
||||
"type": "resign",
|
||||
"gnubg_commit": "14b67984737ded0f6de43d63dcb789f729d9b06b",
|
||||
"met": "Kazaross-XG2",
|
||||
"probabilities": {
|
||||
"win": 0.23634239,
|
||||
"win_gammon": 0.030146752,
|
||||
"win_backgammon": 0.00046920424,
|
||||
"lose_gammon": 0.48970115,
|
||||
"lose_backgammon": 0.03487766
|
||||
},
|
||||
"resignations": {
|
||||
"single": {
|
||||
"accepted": true,
|
||||
"points": 1
|
||||
},
|
||||
"gammon": {
|
||||
"accepted": true,
|
||||
"points": 2
|
||||
},
|
||||
"backgammon": {
|
||||
"accepted": true,
|
||||
"points": 3
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"id": "resign-race-small-gammon",
|
||||
"description": "Course perdue, gammon perdu à 0,2 %, videau à 2 : même ce petit risque fait refuser le simple ; le gammon est accepté.",
|
||||
"position_id": "770DAABwd3cAAA",
|
||||
"match_id": "EQEAAAAAAAAA",
|
||||
"type": "resign",
|
||||
"gnubg_commit": "14b67984737ded0f6de43d63dcb789f729d9b06b",
|
||||
"met": "Kazaross-XG2",
|
||||
"probabilities": {
|
||||
"win": 5.9479167e-05,
|
||||
"win_gammon": 0.0,
|
||||
"win_backgammon": 0.0,
|
||||
"lose_gammon": 0.0018951668,
|
||||
"lose_backgammon": 0.0
|
||||
},
|
||||
"resignations": {
|
||||
"single": {
|
||||
"accepted": false,
|
||||
"points": null
|
||||
},
|
||||
"gammon": {
|
||||
"accepted": true,
|
||||
"points": 4
|
||||
},
|
||||
"backgammon": {
|
||||
"accepted": true,
|
||||
"points": 6
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"id": "resign-single-accepted",
|
||||
"description": "Partie libre, videau à 2 chez l'adversaire, attaque subie avec moins de gammons (36 %) : le simple est accepté.",
|
||||
"position_id": "tF2DBwDgc/ABUA",
|
||||
"match_id": "EQEAAAAAAAAA",
|
||||
"type": "resign",
|
||||
"gnubg_commit": "14b67984737ded0f6de43d63dcb789f729d9b06b",
|
||||
"met": "Kazaross-XG2",
|
||||
"probabilities": {
|
||||
"win": 0.23261039,
|
||||
"win_gammon": 0.038808223,
|
||||
"win_backgammon": 0.0009525986,
|
||||
"lose_gammon": 0.36128312,
|
||||
"lose_backgammon": 0.015526686
|
||||
},
|
||||
"resignations": {
|
||||
"single": {
|
||||
"accepted": true,
|
||||
"points": 2
|
||||
},
|
||||
"gammon": {
|
||||
"accepted": true,
|
||||
"points": 4
|
||||
},
|
||||
"backgammon": {
|
||||
"accepted": true,
|
||||
"points": 6
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -269,6 +269,30 @@ def compare_levels(report, cli, case, settings):
|
||||
compare_cube(report, where, expected, actual)
|
||||
|
||||
|
||||
def compare_resign(report, cli, case):
|
||||
"""Abandon : même évaluation, et pour chaque genre la même réponse de
|
||||
l'ordinateur et les mêmes points. Une réponse différente n'est qu'une
|
||||
remarque si l'équité du joueur qui abandonne, avant et après, ne se
|
||||
sépare que de moins que la tolérance (cas limite)."""
|
||||
actual = run_cli(cli, ["resign", case["position_id"], case["match_id"]])
|
||||
where = "%s abandon" % case["id"]
|
||||
compare_probabilities(report, where, case["probabilities"], actual["probabilities"])
|
||||
options = {o["kind"]: o for o in actual["options"]}
|
||||
for kind, expected in sorted(case["resignations"].items()):
|
||||
option = options[kind]
|
||||
here = "%s %s" % (where, kind)
|
||||
if expected["accepted"] != option["accepted"]:
|
||||
margin = option["equity_after"] - actual["equity_before"]
|
||||
if abs(margin) <= report.tolerance:
|
||||
report.notes.append("%s : %s pour gnubg, %s pour le moteur ; écart avant/après "
|
||||
"%.2e, cas limite" % (here, expected["accepted"],
|
||||
option["accepted"], margin))
|
||||
else:
|
||||
report.same(here, "accepted", expected["accepted"], option["accepted"])
|
||||
if expected["accepted"]:
|
||||
report.same(here, "points", expected["points"], option["points"])
|
||||
|
||||
|
||||
def compare_analyses(report, cli, folder):
|
||||
"""Compare toutes les analyses ; renvoie leur nombre."""
|
||||
settings = {level["name"]: level for level in run_cli(cli, ["levels"])["levels"]}
|
||||
@@ -280,6 +304,8 @@ def compare_analyses(report, cli, folder):
|
||||
compare_move_analysis(report, cli, case)
|
||||
elif case["type"] == "cube":
|
||||
compare_cube_analysis(report, cli, case)
|
||||
elif case["type"] == "resign":
|
||||
compare_resign(report, cli, case)
|
||||
else:
|
||||
compare_levels(report, cli, case, settings)
|
||||
return len(paths)
|
||||
|
||||
@@ -391,6 +391,41 @@ def level_cube(case, name):
|
||||
}
|
||||
|
||||
|
||||
# Genres d'abandon, dans l'ordre de gnubg (fResigned 1 à 3) et noms de la
|
||||
# commande « resign ».
|
||||
RESIGN_KINDS = ("single", "gammon", "backgammon")
|
||||
|
||||
# Réglages de l'évaluation d'un abandon : ecResign de gnubg
|
||||
# (get_eq_before_resign, play.c), 0 pli sans videau ni bruit.
|
||||
RESIGN_CONTEXT = {"cubeful": 0, "plies": 0, "deterministic": 1, "prune": 0, "noise": 0.0}
|
||||
|
||||
|
||||
def resign(case, kind):
|
||||
"""Le joueur au trait propose d'abandonner ; son adversaire, joué par
|
||||
gnubg, accepte ou refuse aussitôt (ComputerTurn, play.c). Accepté, la
|
||||
partie est finie par abandon, avec les points gagnés."""
|
||||
start_game(case)
|
||||
turn = gnubg.posinfo()["turn"]
|
||||
gnubg.command("set player %d gnubg" % (1 - turn))
|
||||
gnubg.command("resign " + kind)
|
||||
info = gnubg.match(analysis=0, boards=0, statistics=0, verbose=0)["games"][-1]["info"]
|
||||
gnubg.command("set player %d human" % (1 - turn))
|
||||
accepted = info.get("winner") is not None
|
||||
if accepted and not info.get("resigned"):
|
||||
raise SystemExit("%s : partie finie sans abandon" % case["id"])
|
||||
return {"accepted": accepted, "points": info["points-won"] if accepted else None}
|
||||
|
||||
|
||||
def resign_case(case):
|
||||
"""L'évaluation de gnubg pour l'abandon, et sa réponse à chaque genre."""
|
||||
start_game(case)
|
||||
r = gnubg.evaluate(gnubg.board(), cube_info(), RESIGN_CONTEXT)
|
||||
return {
|
||||
"probabilities": probabilities(r[:5]),
|
||||
"resignations": {kind: resign(case, kind) for kind in RESIGN_KINDS},
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
@@ -425,6 +460,10 @@ def generate_analyses(commit):
|
||||
level.update(level_move(case, name) if case["dice"] else level_cube(case, name))
|
||||
result["levels"][name] = level
|
||||
write_analysis(out_dir, result)
|
||||
for case in cases["resigns"]:
|
||||
result = dict(case, type="resign", gnubg_commit=commit, met=MET)
|
||||
result.update(resign_case(case))
|
||||
write_analysis(out_dir, result)
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
@@ -331,6 +331,33 @@ attendre_erreur usage double "$depart" "$libre_j0"
|
||||
= "$($cli luck "$milieu" "$milieu_mid" 46 | sed 's/"dice": \[[0-9], [0-9]\]//')" ] \
|
||||
|| echouer "luck : l'ordre des dés change la chance"
|
||||
|
||||
# Abandon (la concordance avec gnubg est dans tests/test_engine_reference.sh) :
|
||||
# à la position de départ, partie libre avec la règle Jacoby, seule la partie
|
||||
# simple est proposée ; videau à 2, les trois choix, avec les points
|
||||
# doublés ; en course perdue sans risque de gammon, seule la partie simple,
|
||||
# acceptée.
|
||||
grep -qF '{"kind": "single", "possible": true, "points": 1' \
|
||||
<<<"$($cli resign "$depart" "$libre_j0")" || echouer "resign au départ : simple proposé"
|
||||
grep -qF '{"kind": "gammon", "possible": false' \
|
||||
<<<"$($cli resign "$depart" "$libre_j0")" || echouer "resign au départ : gammon (Jacoby)"
|
||||
videau2="$(valeur match_id "$($cli matchid 2 1)")"
|
||||
sortie="$($cli resign "$depart" "$videau2")"
|
||||
grep -qF '{"kind": "gammon", "possible": true, "points": 4' <<<"$sortie" \
|
||||
|| echouer "resign videau à 2 : gammon proposé, 4 points : $sortie"
|
||||
grep -qF '"kind": "single", "possible": true, "points": 2, "equity_after": -1, "accepted": true' \
|
||||
<<<"$sortie" || echouer "resign au départ, videau à 2 : simple accepté : $sortie"
|
||||
sortie="$($cli resign "$perdue" "$videau2")"
|
||||
grep -qF '"kind": "single", "possible": true, "points": 2, "equity_after": -1, "accepted": true' \
|
||||
<<<"$sortie" || echouer "resign en course perdue : simple accepté : $sortie"
|
||||
grep -qF '"kind": "gammon", "possible": false' <<<"$sortie" \
|
||||
|| echouer "resign en course perdue : gammon impossible : $sortie"
|
||||
# Course gagnée : le joueur au trait ne peut plus perdre de gammon, le
|
||||
# gammon n'est pas proposé.
|
||||
sortie="$($cli resign "$course" "$videau2")"
|
||||
grep -qF '"kind": "gammon", "possible": false' <<<"$sortie" \
|
||||
|| echouer "resign en course gagnée : gammon impossible : $sortie"
|
||||
attendre_erreur usage resign "$depart"
|
||||
|
||||
if [ "$echecs" -gt 0 ]; then
|
||||
echo " $echecs vérification(s) du moteur en échec."
|
||||
exit 1
|
||||
|
||||
@@ -143,10 +143,16 @@ elif .type == "level" then
|
||||
(if (.levels | length) > 0 and all(.levels[]; (.plies | nombre) and (.noise | nombre)
|
||||
and ((.move | type) == "string" or (.decision | type) == "string"))
|
||||
then empty else "niveaux incomplets" end)
|
||||
elif .type == "resign" then
|
||||
(if (.resignations | keys) == ["backgammon", "gammon", "single"]
|
||||
and (.probabilities | keys | length) == 5
|
||||
and all(.resignations[]; (.accepted | type) == "boolean"
|
||||
and (if .accepted then (.points | nombre) else .points == null end))
|
||||
then empty else "abandon incomplet" end)
|
||||
else "type inconnu" end
|
||||
JQ
|
||||
|
||||
mapfile -t analyses < <(jq -r '(.moves + .cubes + .levels)[].id' analyses.json)
|
||||
mapfile -t analyses < <(jq -r '(.moves + .cubes + .levels + .resigns)[].id' analyses.json)
|
||||
doublons="$(printf '%s\n' "${analyses[@]}" "${ids[@]}" | sort | uniq -d | paste -sd' ' -)"
|
||||
[ -z "$doublons" ] || signaler "analyses.json : identifiants en double : $doublons"
|
||||
for id in "${analyses[@]}"; do
|
||||
|
||||
Reference in New Issue
Block a user