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:
Pierre MARTIN
2026-11-13 00:37:19 +01:00
co-authored by Claude Opus 5.5
parent da9845466b
commit e98497e5b1
16 changed files with 539 additions and 8 deletions
+76
View File
@@ -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. */