mirror of
https://github.com/StewBC/cc65-Chess.git
synced 2026-11-24 18:23:54 +00:00
The old engine was weak for one structural reason. cpu_ScorePieceSubTree
looked like minimax but had a branching factor of one: at each level it
followed only the single reply a static heuristic ranked first, so it
evaluated one predicted line per root move and never saw a refutation the
heuristic missed. Two things compounded it - the root considered only one
move per piece, and the scoring functions returned move desirability rather
than position value, which is not a quantity minimax can validly accumulate
across plies.
What replaces it:
engine.c 0x88 board, make/unmake against a per-ply state stack, legal
move generation, and attack queries by ray-cast. The stored
attack database is gone - eng_IsAttacked walks outwards from a
square instead of rebuilding 64 squares' worth of state after
every trial move.
eval.c material and piece-square tables as a pure position value,
kept as a running total updated incrementally by make/unmake.
search.c iterative-deepening negamax with alpha-beta, MVV-LVA and killer
ordering, and a quiescence search over captures.
board.c becomes the adapter between engine and display; plat.h and the 0-63
tile numbering are untouched, so no platform file needed editing - including
the three that cannot be built here.
Verified: perft exact on all five reference positions to depth 5, and to
depth 6 on the two that publish one. Against the engine it replaces, at that
engine's strongest setting: 6 wins, 0 losses.
Smaller than what it replaces despite doing far more - 31129 bytes total on
the c64 at optspeed against 31543 for the two engines' worth of machinery it
supersedes, and 514 bytes less RAM. All five buildable targets fit.
tests/ carries the harness this was developed against: perft, a game fuzzer,
castling scenarios, an internal match runner, on-target C64 benchmarks, and
a UCI adapter for playing external engines. It stops being gitignored here -
the exclusion was scaffolding added during the rework to keep git status
quiet, and the harness is the evidence for everything above.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
84 lines
2.3 KiB
C
84 lines
2.3 KiB
C
/*
|
|
* c64skill.c
|
|
* cc65 Chess - test support
|
|
*
|
|
* What each skill level actually costs per move on a stock C64, playing a
|
|
* real game rather than searching the opening position. Reads gcSearchSkill
|
|
* directly, so it measures what ships.
|
|
*
|
|
* Prints one summary line a level instead of one line a move: fewer numbers
|
|
* to read off a screenshot is fewer numbers to read wrong. "full" is the
|
|
* count of moves that actually reached the level's advertised depth - a level
|
|
* that rarely reaches its own depth is mistuned, which is exactly how the
|
|
* previous table went wrong.
|
|
*
|
|
* Build:
|
|
* cl65 -t c64 -Oris -I../src -o c64skill.prg \
|
|
* ../src/engine.c ../src/eval.c ../src/search.c c64skill.c
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <time.h>
|
|
#include "types.h"
|
|
#include "engine.h"
|
|
#include "eval.h"
|
|
#include "search.h"
|
|
|
|
// Only levels 1 and 2 have a time target, so only they are measured - and they
|
|
// are measured 20 plies deep, because the first few moves are not the game.
|
|
// Sampling the opening is exactly how the previous numbers came out a quarter
|
|
// too cheap
|
|
static const char sc_plies[2] = { 20, 20 };
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
int main(void)
|
|
{
|
|
char lev;
|
|
|
|
printf("skill cost per move, real game\n");
|
|
|
|
for(lev = 0; lev < 2; ++lev)
|
|
{
|
|
t_engUndo undo;
|
|
char side = SIDE_WHITE, ply, full = 0;
|
|
unsigned long sum = 0, worst = 0, best = 65535ul, nodes = 0;
|
|
|
|
eng_SetStartPosition();
|
|
|
|
for(ply = 0; ply < sc_plies[lev]; ++ply)
|
|
{
|
|
t_searchResult result;
|
|
clock_t start;
|
|
unsigned long taken;
|
|
|
|
start = clock();
|
|
search_Best(side, gcSearchSkill[lev].m_depth,
|
|
gcSearchSkill[lev].m_nodes, &result);
|
|
taken = (unsigned long)(clock() - start);
|
|
|
|
sum += taken;
|
|
nodes += result.m_nodes;
|
|
if(taken > worst) worst = taken;
|
|
if(taken < best) best = taken;
|
|
if(result.m_depth >= gcSearchSkill[lev].m_depth) ++full;
|
|
|
|
if(!result.m_haveMove)
|
|
break;
|
|
|
|
eng_Make(&result.m_move, &undo);
|
|
side = 1 - side;
|
|
}
|
|
|
|
// jiffies are 1/60 s on NTSC, which is what vice-run.sh uses
|
|
printf("L%u d=%u mean=%lu lo=%lu hi=%lu full=%u/%u\n",
|
|
(unsigned)(lev + 1), (unsigned)gcSearchSkill[lev].m_depth,
|
|
sum / ply, best, worst, (unsigned)full, (unsigned)ply);
|
|
printf(" mean nodes %lu\n", nodes / ply);
|
|
}
|
|
|
|
printf("done.\n");
|
|
|
|
for(;;)
|
|
;
|
|
}
|