Commit 374e58d2 authored by Mahmoud Aglan's avatar Mahmoud Aglan

fix: remove isStalemate API call (doubled request count), reduce max to 60

The isStalemate() called the Stockfish API on every move just to check
if the opponent had legal moves — doubling API calls from 80 to 160 per
game. Now relies on the API returning no best_move as game-over signal.
Differentiates checkmate vs stalemate by eval magnitude.

Also reduced max moves from 80 to 60 — bot games at these levels
should resolve well before that.
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 2ab774d7
......@@ -76,7 +76,7 @@ class BotGamePlayerService
$lastEval = 0.0;
$result = null;
$resultReason = null;
$maxMoves = 80;
$maxMoves = 60;
$sanMoves = [];
while ($moveCount < $maxMoves) {
......@@ -89,12 +89,14 @@ class BotGamePlayerService
]);
if ($response['status'] !== 200 || empty($response['body']['best_move'])) {
if ($sideToMove === 'w') {
$result = 'black_wins';
$eval = abs($response['body']['evaluation'] ?? 0);
if ($eval > 50) {
$result = ($sideToMove === 'w') ? 'black_wins' : 'white_wins';
$resultReason = 'checkmate';
} else {
$result = 'white_wins';
$result = 'stalemate';
$resultReason = 'stalemate';
}
$resultReason = 'checkmate';
break;
}
......@@ -142,11 +144,6 @@ class BotGamePlayerService
break;
}
if (self::isStalemate($newFen)) {
$result = 'stalemate';
$resultReason = 'stalemate';
break;
}
}
if ($result === null && $moveCount >= $maxMoves) {
......@@ -188,15 +185,6 @@ class BotGamePlayerService
return $parts[1] ?? 'w';
}
private static function isStalemate(string $fen): bool
{
$response = ApiProxy::stockfish('POST', '/api/chess/move', [
'fen' => $fen,
'bot_id' => 'grandmaster',
]);
return $response['status'] !== 200 || empty($response['body']['best_move']);
}
private static function uciToSan(string $fen, string $uciMove): string
{
$from = substr($uciMove, 0, 2);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment