mirror of
https://github.com/StewBC/cc65-Chess.git
synced 2026-11-26 09:21:25 +00:00
Three things: the full match result, an on-target benchmark that could
actually measure this term, and the number it produced.
**The match.** 64 games, cc65 Easy against Sargon II level 1, the same
settings as the recorded pre-fix baseline:
pre-fix shipped
W-L-D 10W 19L 35D 27W 20L 17D
score 42.97% 55.47%
fifty-move draws 15 2
conversion 6 of 23 26 of 28
drew still a piece up 15 0
cc65 as White 9W 3L 20D 25W 2L 5D
cc65 as Black 1W 16L 15D 2W 18L 12D
Fifteen games ended still holding a rook against a bare king, and now none.
Twenty White draws became five. Black does not move and should not: a term
that helps finish won positions does nothing for a side that is rarely
winning.
The percentage on its own is not significant - naive 95% intervals are
30.8-55.1% and 43.3-67.6% and they overlap, over 16 to 17 distinct games
rather than 64. The conversion count and the fifty-move column carry the
result because they are categorical outcomes tied to the mechanism. The
colour split is the more interesting number anyway: Sargon scores 75.0%
with White and cc65 now scores 85.9%, so on equal footing cc65 is ahead,
but sixty points between colours is an opening-book gap rather than
first-move advantage. cc65 has a book only as White and four entries deep.
The rest of the deficit is an opening problem, not an endgame one.
**The benchmark.** Neither existing on-target program could price this
term, for the same trap in two forms. c64search.c runs from the opening,
where gePhase is 6400 against the term's bound of 1100 - it cannot execute,
so that benchmark would have reported zero faithfully and uselessly.
c64evasion.c has the right shape, a fixed replay so both builds walk
identical positions, but the wrong positions: it replays a middlegame,
because check evasions cost nothing where nobody is in check. A gated term
needs a replay that spends its time inside the gate.
tests/c64drive.c is c64evasion.c's shape with the positions inverted. It
replays the pre-fix Sargon baseline game that reached king and rook against
a bare king - the defect itself - and searches only from ply 83, where
gePhase first falls to 1100, giving 148 timed searches with the term live
in about two thirds of them. eval.h gained a -DEVAL_MATEDRIVE_ON=0
override so both halves can be the shipping configuration, since
EVAL_TUNING makes every node dearer and a node's cost is what is being
measured - the same shape SEARCH_CHECK_EVASION already had.
**The number.** On a real C64 under VICE, identical positions in both
builds: 43.225 nodes/sec without the term and 42.361 with, so a node is
**2.04% dearer**. Check evasions cost 22.7% by the same method. That is
the cost where the term applies; in a middlegame it is zero, because the
phase test cannot be entered.
Charged at 2%, it still wins: match drive at equal time, 2,940 nodes
against 3,000, comes to 246-238-28 where equal nodes gave 245-240-27. That
makes it the second evaluation term in this project to survive the
equal-time test and the first to survive it comfortably; pawn structure
died there at +2.0 sigma becoming +0.6, and the endgame king table died
there twice.
AGENTS.md gains the line the last two phases earned: every defect that
mattered here was found by playing rather than by measuring, and the reason
is structural - self-play cannot see a weakness both sides share. Three
times now, and the most recent is this term's first version, which passed
every test in tests/ and scored better on the internal conversion metric
than the version that shipped.
Also recorded, because it cost twenty minutes: these benchmarks print their
results and then spin so the screen still holds them, so a run lasts until
-limitcycles fires rather than until the work is done. Size the limit from
the work - 148 level-2 searches need about 3.4e9 cycles.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
156 lines
6.4 KiB
C
156 lines
6.4 KiB
C
/*
|
|
* c64drive.c
|
|
* cc65 Chess - test support
|
|
*
|
|
* What a search node costs on a real C64 with and without the mate drive,
|
|
* which is the one number doc/strength.md 5.1.6 could not measure.
|
|
*
|
|
* This file exists because neither instrument already here can price it.
|
|
* c64search.c runs from the opening position, where gePhase is 6400 against
|
|
* the term's bound of 1100 - it cannot execute, so that benchmark would
|
|
* faithfully report zero. c64evasion.c has the right shape but the wrong
|
|
* positions: it replays a middlegame, because check evasions cost nothing
|
|
* where nobody is in check. The mate drive is the opposite selection
|
|
* problem and needs an ending.
|
|
*
|
|
* The fixed-replay trick is c64evasion.c's and the reason is the same: two
|
|
* builds that pick their own moves diverge at the first disagreement and then
|
|
* measure different positions, which is not a measurement of anything. Every
|
|
* position here is identical in both builds; only the cost of visiting it
|
|
* differs, and nodes per second is the figure because the two builds do not
|
|
* visit the same *number* of nodes from the same position.
|
|
*
|
|
* The game is game 0 of the pre-fix Sargon II baseline - the one that reached
|
|
* king and rook against a bare king on move 66 and drew by the fifty-move
|
|
* rule, which is the defect the term was built for. Searching starts at ply
|
|
* 83, where gePhase first falls to 1100; before that the moves are replayed
|
|
* without being searched, because timing a middlegame this term cannot enter
|
|
* only dilutes the answer. Of the 148 timed plies the term is live in about
|
|
* two thirds, so the figure below is the cost where it applies rather than
|
|
* the cost averaged over a whole game - state it that way when quoting it.
|
|
*
|
|
* Build both halves from the shipping configuration. The tuning build cannot
|
|
* be used: EVAL_TUNING makes every node dearer and a node's cost is the thing
|
|
* being measured.
|
|
* cl65 -t c64 -Oris -I../src -o c64drive-on.prg \
|
|
* ../src/engine.c ../src/eval.c ../src/search.c c64drive.c
|
|
* cl65 -t c64 -Oris -I../src -DEVAL_MATEDRIVE_ON=0 -o c64drive-off.prg \
|
|
* ../src/engine.c ../src/eval.c ../src/search.c c64drive.c
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <time.h>
|
|
#include "types.h"
|
|
#include "engine.h"
|
|
#include "eval.h"
|
|
#include "search.h"
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
// Pre-fix Sargon baseline game 0, stored as 0x88 from/to pairs
|
|
static const char sc_game[] =
|
|
{
|
|
0x63,0x43, 0x06,0x25, 0x71,0x52, 0x01,0x22, 0x76,0x55, 0x13,0x33,
|
|
0x64,0x54, 0x02,0x35, 0x75,0x31, 0x14,0x24, 0x74,0x76, 0x05,0x23,
|
|
0x31,0x22, 0x11,0x22, 0x55,0x34, 0x23,0x34, 0x43,0x34, 0x25,0x46,
|
|
0x73,0x43, 0x22,0x32, 0x43,0x40, 0x03,0x13, 0x40,0x13, 0x04,0x13,
|
|
0x52,0x40, 0x13,0x22, 0x40,0x52, 0x46,0x34, 0x65,0x45, 0x34,0x46,
|
|
0x67,0x57, 0x46,0x25, 0x75,0x65, 0x00,0x01, 0x66,0x46, 0x35,0x44,
|
|
0x45,0x35, 0x24,0x35, 0x46,0x35, 0x07,0x04, 0x52,0x44, 0x04,0x44,
|
|
0x65,0x66, 0x25,0x37, 0x66,0x36, 0x44,0x47, 0x76,0x66, 0x01,0x41,
|
|
0x60,0x50, 0x41,0x42, 0x62,0x52, 0x15,0x25, 0x36,0x46, 0x47,0x46,
|
|
0x57,0x46, 0x42,0x46, 0x66,0x55, 0x46,0x36, 0x54,0x44, 0x36,0x56,
|
|
0x55,0x64, 0x33,0x44, 0x52,0x42, 0x56,0x55, 0x64,0x63, 0x37,0x56,
|
|
0x63,0x62, 0x56,0x35, 0x72,0x63, 0x44,0x54, 0x63,0x52, 0x54,0x64,
|
|
0x61,0x41, 0x35,0x54, 0x62,0x53, 0x54,0x33, 0x53,0x64, 0x55,0x54,
|
|
0x64,0x63, 0x33,0x52, 0x41,0x31, 0x22,0x23, 0x63,0x54, 0x23,0x34,
|
|
0x50,0x40, 0x16,0x26, 0x40,0x30, 0x25,0x35, 0x30,0x20, 0x35,0x45,
|
|
0x54,0x53, 0x52,0x33, 0x42,0x33, 0x34,0x33, 0x70,0x73, 0x32,0x42,
|
|
0x53,0x52, 0x33,0x32, 0x73,0x43, 0x32,0x31, 0x43,0x45, 0x31,0x20,
|
|
0x52,0x42, 0x20,0x21, 0x45,0x15, 0x17,0x37, 0x15,0x25, 0x12,0x22,
|
|
0x25,0x26, 0x10,0x30, 0x26,0x27, 0x30,0x40, 0x27,0x37, 0x40,0x50,
|
|
0x42,0x51, 0x22,0x32, 0x37,0x17, 0x32,0x42, 0x51,0x50, 0x21,0x32,
|
|
0x50,0x61, 0x32,0x43, 0x17,0x13, 0x43,0x32, 0x61,0x52, 0x32,0x22,
|
|
0x13,0x16, 0x22,0x33, 0x16,0x36, 0x33,0x44, 0x52,0x42, 0x44,0x45,
|
|
0x36,0x16, 0x45,0x34, 0x16,0x14, 0x34,0x25, 0x14,0x44, 0x25,0x36,
|
|
0x42,0x43, 0x36,0x35, 0x44,0x14, 0x35,0x45, 0x14,0x15, 0x45,0x36,
|
|
0x43,0x44, 0x36,0x26, 0x15,0x75, 0x26,0x36, 0x44,0x43, 0x36,0x46,
|
|
0x75,0x65, 0x46,0x56, 0x65,0x15, 0x56,0x46, 0x43,0x34, 0x46,0x56,
|
|
0x34,0x44, 0x56,0x46, 0x15,0x16, 0x46,0x37, 0x44,0x43, 0x37,0x27,
|
|
0x16,0x14, 0x27,0x36, 0x43,0x34, 0x36,0x46, 0x34,0x44, 0x46,0x36,
|
|
0x14,0x24, 0x36,0x46, 0x24,0x26, 0x46,0x37, 0x26,0x16, 0x37,0x27,
|
|
0x16,0x13, 0x27,0x36, 0x13,0x23, 0x36,0x46, 0x23,0x33, 0x46,0x56,
|
|
0x33,0x13, 0x56,0x65, 0x13,0x12, 0x65,0x64, 0x12,0x62, 0x64,0x73,
|
|
0x62,0x61, 0x73,0x72, 0x61,0x65, 0x72,0x73, 0x44,0x43, 0x73,0x74,
|
|
0x65,0x62, 0x74,0x73, 0x62,0x61, 0x73,0x72, 0x61,0x64, 0x72,0x73,
|
|
0x43,0x53, 0x73,0x72, 0x64,0x65, 0x72,0x71, 0x65,0x62, 0x71,0x70,
|
|
0x53,0x43, 0x70,0x71, 0x43,0x52, 0x71,0x70, 0x52,0x53, 0x70,0x71,
|
|
0x53,0x63, 0x71,0x70, 0x63,0x54, 0x70,0x71, 0x62,0x63, 0x71,0x72,
|
|
0x54,0x53, 0x72,0x71, 0x53,0x44, 0x71,0x72, 0x44,0x54, 0x72,0x71,
|
|
0x63,0x65, 0x71,0x72, 0x54,0x43, 0x72,0x73, 0x43,0x44, 0x73,0x74,
|
|
0x65,0x61, 0x74,0x73,
|
|
};
|
|
#define GAME_PLIES 230
|
|
#define TIMED_FROM 83
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
int main(void)
|
|
{
|
|
// static, not on the stack: cc65 gives a function 256 bytes of locals and
|
|
// a move list does not fit - the trap AGENTS.md names
|
|
static t_engMove moves[80];
|
|
t_engUndo undo;
|
|
char side = SIDE_WHITE;
|
|
unsigned int ply;
|
|
unsigned long jiffies = 0;
|
|
unsigned long nodes = 0;
|
|
|
|
printf("matedrive=%u\n", (unsigned)EVAL_MATEDRIVE_ON);
|
|
|
|
eng_SetStartPosition();
|
|
|
|
for(ply = 0; ply < GAME_PLIES; ++ply)
|
|
{
|
|
char count, i, from, to;
|
|
|
|
if(ply >= TIMED_FROM)
|
|
{
|
|
t_searchResult result;
|
|
clock_t start, taken;
|
|
|
|
// time a search from this position, then discard its choice
|
|
start = clock();
|
|
search_Best(side, gcSearchSkill[1].m_depth,
|
|
gcSearchSkill[1].m_nodes, &result);
|
|
taken = clock() - start;
|
|
|
|
jiffies += (unsigned long)taken;
|
|
nodes += (unsigned long)result.m_nodes;
|
|
}
|
|
|
|
// and play the scripted move, so both builds stay in step
|
|
from = sc_game[ply << 1];
|
|
to = sc_game[(ply << 1) + 1];
|
|
count = eng_GenMoves(side, moves, 80);
|
|
for(i = 0; i < count; ++i)
|
|
if(moves[i].m_from == from && moves[i].m_to == to)
|
|
{
|
|
eng_Make(&moves[i], &undo);
|
|
break;
|
|
}
|
|
if(i == count)
|
|
{
|
|
printf("desync at ply %u\n", ply);
|
|
break;
|
|
}
|
|
side = 1 - side;
|
|
}
|
|
|
|
// nodes per second, times ten, so the ratio survives integer division
|
|
printf("n=%lu t=%lu nps10=%lu\n", nodes, jiffies,
|
|
jiffies ? (nodes * 600UL) / jiffies : 0UL);
|
|
printf("done.\n");
|
|
|
|
for(;;)
|
|
;
|
|
}
|