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>
67 lines
1.8 KiB
C
67 lines
1.8 KiB
C
/*
|
|
* c64level1.c
|
|
* cc65 Chess - test support
|
|
*
|
|
* c64search.c times the *opening* position, on the stated grounds that it is
|
|
* the conservative case. That assumption is worth checking: after both sides
|
|
* develop, the piece count has not dropped but the lines have opened, so the
|
|
* generator has more to do and quiescence has more captures to chase. If the
|
|
* early middlegame is slower than the opening, every budget derived from the
|
|
* opening is optimistic and the skill-level times are understated.
|
|
*
|
|
* So this plays a real game at the level 1 setting - depth 2, 500 nodes, both
|
|
* sides - and prints the time for each move as it goes. That is exactly what
|
|
* someone sitting in front of the game experiences.
|
|
*
|
|
* Build:
|
|
* cl65 -t c64 -Oris -I../src -o c64level1.prg \
|
|
* ../src/engine.c ../src/eval.c ../src/search.c c64level1.c
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <time.h>
|
|
#include "types.h"
|
|
#include "engine.h"
|
|
#include "eval.h"
|
|
#include "search.h"
|
|
|
|
#define PLIES 18
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
int main(void)
|
|
{
|
|
t_engUndo undo;
|
|
char side = SIDE_WHITE, ply;
|
|
|
|
printf("level 1: d=%u n=%u\n",
|
|
(unsigned)gcSearchSkill[0].m_depth, gcSearchSkill[0].m_nodes);
|
|
|
|
eng_SetStartPosition();
|
|
|
|
for(ply = 0; ply < PLIES; ++ply)
|
|
{
|
|
t_searchResult result;
|
|
clock_t start, taken;
|
|
|
|
start = clock();
|
|
search_Best(side, gcSearchSkill[0].m_depth, gcSearchSkill[0].m_nodes, &result);
|
|
taken = clock() - start;
|
|
|
|
// move number as a player counts it, then jiffies and nodes actually spent
|
|
printf("%u%c t=%lu n=%u\n",
|
|
(unsigned)((ply >> 1) + 1), (side == SIDE_WHITE) ? 'w' : 'b',
|
|
(unsigned long)taken, result.m_nodes);
|
|
|
|
if(!result.m_haveMove)
|
|
break;
|
|
|
|
eng_Make(&result.m_move, &undo);
|
|
side = 1 - side;
|
|
}
|
|
|
|
printf("done.\n");
|
|
|
|
for(;;)
|
|
;
|
|
}
|