/** Copyright (c) Scott Gasch Module Name: script.c Abstract: Some glue code to support running test scripts and keeping track of test suite results. Author: Scott Gasch (scott.gasch@gmail.com) 18 May 2004 Revision History: $Id: script.c 355 2008-07-01 15:46:43Z scott $ **/ #include "chess.h" // Declared directly instead of #include -- that header #defines // its own INFINITY_SCORE, which collides with ours (chess.h:198, MAX_SHORT) and // would silently change what INFINITY_SCORE means for the rest of this file. extern double pow(double, double); // ---------------------------------------------------------------------- // // Global testsuite position counters // #define SUITE_MAX_SOLUTIONS (4) #define SUITE_MAX_AVOIDS (4) #define SUITE_NUM_HISTOGRAM (8) // // A big struct of counters we want to maintain when running test scripts. // typedef struct _SUITE_COUNTERS { CHAR szId[SMALL_STRING_LEN_CHAR]; ULONG uNumSolutions; MOVE mvSolution[SUITE_MAX_SOLUTIONS]; ULONG uNumAvoids; MOVE mvAvoid[SUITE_MAX_AVOIDS]; ULONG uCorrect; ULONG uIncorrect; ULONG uTotal; UINT64 u64TotalNodeCount; double dCurrentSolutionTime; ULONG uCurrentSolvedPlies; ULONG uSigmaDepth; double dSigmaSolutionTime; double dAverageNps; UINT64 u64TotalBetaCutoffs; UINT64 u64TotalBetaCutoffsOnFirstMove; UINT64 u64TotalCounterMoveTries; UINT64 u64TotalCounterMoveHits; UINT64 u64TotalLeftoverTries; UINT64 u64TotalLeftoverAlpha; UINT64 u64TotalLeftoverFH; UINT64 u64TotalCMEvidenceTries[CM_EVIDENCE_BUCKETS]; UINT64 u64TotalCMEvidenceFH[CM_EVIDENCE_BUCKETS]; // See chess.h's HANG_CP_BUCKETS comment. Same accumulation/print // pattern as u64TotalCMEvidenceTries above -- only meaningful // gathered single-threaded (--cpus 1), same as that one (not // wired into split.c's MP merge). UINT64 u64TotalHangEstimateTries[HANG_CP_BUCKETS]; UINT64 u64TotalHangEstimateFH[HANG_CP_BUCKETS]; // The real comparison baseline for the buckets above -- same // fPruneReduceEligible population, not just fIsLeftoverMove. UINT64 u64TotalEligibleLeftoverTries; UINT64 u64TotalEligibleLeftoverFH; // The "down axis" -- (iAlpha - iEval) calibration. Same population // and comparison baseline as the hang-estimate buckets above. UINT64 u64TotalGapEstimateTries[GAP_CP_BUCKETS]; UINT64 u64TotalGapEstimateFH[GAP_CP_BUCKETS]; // The "late axis" -- this move's own ordinal position calibration. // Same population and comparison baseline as the other two axes. UINT64 u64TotalMoveNumEstimateTries[MOVE_NUM_BUCKETS]; UINT64 u64TotalMoveNumEstimateFH[MOVE_NUM_BUCKETS]; // The "depth axis" -- remaining search depth calibration. Same // population and comparison baseline as the other three axes. UINT64 u64TotalDepthEstimateTries[SEARCH_DEPTH_BUCKETS]; UINT64 u64TotalDepthEstimateFH[SEARCH_DEPTH_BUCKETS]; // Joint 4D table, marginal (uncoarsened) resolution -- reassembled // offline by the bake script via the FOURAXISRAW dump below, never // printed as a human-readable table here (21,780+ shipped cells, // 99,825 at this raw resolution -- far too many lines). UINT64 u64TotalJointTries[SEARCH_DEPTH_BUCKETS][HANG_CP_BUCKETS][GAP_CP_BUCKETS][MOVE_NUM_BUCKETS]; UINT64 u64TotalJointFH[SEARCH_DEPTH_BUCKETS][HANG_CP_BUCKETS][GAP_CP_BUCKETS][MOVE_NUM_BUCKETS]; // Phase 2 -- joint-table-driven graduated LMR calibration (see // search.c's JOINT_EXTRA_TIER*_THOUSANDTHS comment). UINT64 u64TotalJointExtraTries[JOINT_EXTRA_TIER_COUNT]; UINT64 u64TotalJointExtraResearch[JOINT_EXTRA_TIER_COUNT]; UINT64 u64TotalLMPPruned; // Static-nullmove/reverse-futility shortcut firing rate -- diagnostic, // added to compare HOW OFTEN the shortcut fires (not just its // per-decision wrong rate, already measured offline against // FH_REGRESSION_COLLECTION data) between the table and regression // builds on the same suite. Only meaningful single-threaded // (--cpus 1), same caveat as the hang/gap/depth axes above. UINT64 u64TotalQuickNullMoves; UINT64 u64TotalQuickNullMoveSuccess; #ifdef HASHCAP_COLLECTION UINT64 u64TotalHashCapTries[2][2]; UINT64 u64TotalHashCapFH[2][2]; #endif // FH_REGRESSION_COLLECTION needs no g_SuiteCounters fields at all -- // unlike the old FH_TABLE_COLLECTION histogram design, each record is // written straight to its own thread's file as it's produced // (fhcollect.c), so there's no in-process total to accumulate or dump // here. #ifdef JOINT_EXTRA_VERIFY UINT64 u64TotalJointExtraVerifyTries[JOINT_EXTRA_TIER_COUNT][POST_REDUCE_DEPTH_BUCKETS]; UINT64 u64TotalJointExtraVerifySilentMiss[JOINT_EXTRA_TIER_COUNT][POST_REDUCE_DEPTH_BUCKETS]; UINT64 u64TotalJointExtraVerifyNullBailoutSignature[JOINT_EXTRA_TIER_COUNT]; #endif #ifdef TEST_NULL // Null-move precision/recall calibration, summed across every // position in the suite -- see _NullCalibBucketIndex's comment in // search.c. Accumulated the same way as u64TotalCMEvidenceTries // above (per-search counters are copied into g_Options at the end // of each Think() call, then summed in here by _ProcessSuiteLine), // and printed once by _PrintSuiteReport at true end-of-suite -- // deliberately *not* dumped after every position, which would // balloon the logfile (confirmed: 191MB after ~28K of 200K // positions the first time this was tried that way). UINT64 u64TotalNCAttempts[NC_TOTAL_BUCKETS]; UINT64 u64TotalNCNullFH[NC_TOTAL_BUCKETS]; UINT64 u64TotalNCRealFH[NC_TOTAL_BUCKETS]; UINT64 u64TotalNCBothFH[NC_TOTAL_BUCKETS]; UINT64 u64TotalNCNullProbeNodeSum[NC_TOTAL_BUCKETS]; UINT64 u64TotalNCFirstMoveNodeSum[NC_TOTAL_BUCKETS]; UINT64 u64TotalNCRealLoopNodeSum[NC_TOTAL_BUCKETS]; #endif double dSigmaEBF; // sum of per-problem nodes^(1/depth) ULONG uEBFCount; // number of problems with depth > 0 double dAverageTimeToSolution; ULONG uHistogram[SUITE_NUM_HISTOGRAM]; } SUITE_COUNTERS; static SUITE_COUNTERS g_SuiteCounters; static void _ClearSuiteData(void) /** Routine description: Clear data/counters we have for the current test script. Parameters: void Return value: static void **/ { g_SuiteCounters.uNumSolutions = 0; memset(g_SuiteCounters.mvSolution, 0, sizeof(g_SuiteCounters.mvSolution)); g_SuiteCounters.uNumAvoids = 0; memset(g_SuiteCounters.mvAvoid, 0, sizeof(g_SuiteCounters.mvAvoid)); memset(g_SuiteCounters.szId, 0, sizeof(g_SuiteCounters.szId)); g_SuiteCounters.uCurrentSolvedPlies = 0; g_SuiteCounters.dCurrentSolutionTime = 0; } COMMAND(IdCommand) /** Routine description: This function implements the 'id' engine command. Usage: id [optional string] With no agruments, id returns the current position's id tag. With a string argument, id sets the current position's id tag. id tags are useful[?] for naming positions in test suites... Parameters: The COMMAND macro hides four arguments from the input parser: CHAR *szInput : the full line of input ULONG argc : number of argument chunks CHAR *argv[] : array of ptrs to each argument chunk POSITION *pos : a POSITION pointer to operate on Return value: void **/ { CHAR *p; ULONG u; if (argc < 2) { Trace("The current position's id is: \"%s\"\n", g_SuiteCounters.szId); } else { p = szInput; while(*p && !isspace(*p)) { p++; } while(*p && isspace(*p)) { p++; } u = 0; while(*p) { if (!isspace(*p)) { g_SuiteCounters.szId[u] = *p; u++; } if (u > ARRAY_LENGTH(g_SuiteCounters.szId)) { break; } p++; } } } COMMAND(SolutionCommand) /** Routine description: This function implements the 'solution' engine command. Usage: solution [optional move string] With no agruments, solution prints out a list of the "correct solution" move(s) set for the current position. With a move string argument solution sets another move as the correct answer to the current position. The move string can be in ICS or SAN format. When the engine is allowed to search a position it will compare its best move from the search against the solution move(s) for the position and keep track of how many it gets right/wrong and how long it took to solve. A position can have up to three solutions. A position cannot have both solution moves and avoid moves. Parameters: The COMMAND macro hides four arguments from the input parser: CHAR *szInput : the full line of input ULONG argc : number of argument chunks CHAR *argv[] : array of ptrs to each argument chunk POSITION *pos : a POSITION pointer to operate on Return value: void **/ { ULONG u; MOVE mv; if (argc < 2) { Trace("There %s %u solution move%s set:\n", (g_SuiteCounters.uNumSolutions > 1) ? "are" : "is", g_SuiteCounters.uNumSolutions, (g_SuiteCounters.uNumSolutions > 1) ? "s" : ""); for(u = 0; u < g_SuiteCounters.uNumSolutions; u++) { Trace(" %s\n", MoveToSan(g_SuiteCounters.mvSolution[u], pos)); } } else { mv.uMove = 0; switch(LooksLikeMove(argv[1])) { case MOVE_SAN: mv = ParseMoveSan(argv[1], pos); break; case MOVE_ICS: mv = ParseMoveIcs(argv[1], pos); break; case NOT_MOVE: break; } if (mv.uMove == 0) { Trace("Error (bad move): %s\n", argv[1]); return; } if (g_SuiteCounters.uNumSolutions < SUITE_MAX_SOLUTIONS) { g_SuiteCounters.mvSolution[g_SuiteCounters.uNumSolutions] = mv; g_SuiteCounters.uNumSolutions++; } } } COMMAND(AvoidCommand) /** Routine description: This function implements the 'avoid' engine command. Usage: avoid [optional move string] With no agruments, avoid prints out a list of the "don't play this" move(s) set for the current position. With a move string argument, avoid sets another move as the incorrect answer to the current position. The move string can be in ICS or SAN format. When the engine is allowed to search a position it will compare its best move from the search against the avoid move(s) for the position and keep track of how many it gets right/wrong and how long it took to solve. A position can have up to three avoid moves. A position cannot have both solution moves and avoid moves. Parameters: The COMMAND macro hides four arguments from the input parser: CHAR *szInput : the full line of input ULONG argc : number of argument chunks CHAR *argv[] : array of ptrs to each argument chunk POSITION *pos : a POSITION pointer to operate on Return value: void **/ { ULONG u; MOVE mv; if (argc < 2) { Trace("There %s %u avoid move%s set:\n", (g_SuiteCounters.uNumAvoids > 1) ? "are" : "is", g_SuiteCounters.uNumAvoids, (g_SuiteCounters.uNumAvoids > 1) ? "s" : ""); for(u = 0; u < g_SuiteCounters.uNumAvoids; u++) { Trace(" %s\n", MoveToSan(g_SuiteCounters.mvAvoid[u], pos)); } } else { mv.uMove = 0; switch(LooksLikeMove(argv[1])) { case MOVE_SAN: mv = ParseMoveSan(argv[1], pos); break; case MOVE_ICS: mv = ParseMoveIcs(argv[1], pos); break; case NOT_MOVE: break; } if (mv.uMove == 0) { Trace("Error (bad move): %s\n", argv[1]); return; } if (g_SuiteCounters.uNumAvoids < SUITE_MAX_AVOIDS) { g_SuiteCounters.mvAvoid[g_SuiteCounters.uNumAvoids] = mv; g_SuiteCounters.uNumAvoids++; } } } // // Shared by ScriptCommand and EpdCommand: process one already-read // line exactly the way a script file's line is processed -- "go" // triggers a search plus counter accumulation, anything else is // dispatched through the normal command parser. Factored out so // EpdCommand can feed it lines synthesized from a raw EPD record // (setboard/id/solution/avoid/go) instead of lines read verbatim from // a file, without duplicating this logic or its counter bookkeeping. // static void _ProcessSuiteLine(char *szLine, POSITION *pos) { Trace("SCRIPT> %s\n", szLine); if (!STRNCMPI(szLine, "go", 2)) { (void)Think(pos); g_SuiteCounters.u64TotalNodeCount += g_Options.u64NodesSearched; g_SuiteCounters.u64TotalBetaCutoffs += g_Options.u64BetaCutoffs; g_SuiteCounters.u64TotalBetaCutoffsOnFirstMove += g_Options.u64BetaCutoffsOnFirstMove; g_SuiteCounters.u64TotalCounterMoveTries += g_Options.u64CounterMoveTries; g_SuiteCounters.u64TotalCounterMoveHits += g_Options.u64CounterMoveHits; g_SuiteCounters.u64TotalLeftoverTries += g_Options.u64LeftoverTries; g_SuiteCounters.u64TotalLeftoverAlpha += g_Options.u64LeftoverAlpha; g_SuiteCounters.u64TotalLeftoverFH += g_Options.u64LeftoverFH; g_SuiteCounters.u64TotalQuickNullMoves += g_Options.u64QuickNullMoves; g_SuiteCounters.u64TotalQuickNullMoveSuccess += g_Options.u64QuickNullMoveSuccess; #ifdef HASHCAP_COLLECTION { ULONG u2, v2; for (u2 = 0; u2 < 2; u2++) { for (v2 = 0; v2 < 2; v2++) { g_SuiteCounters.u64TotalHashCapTries[u2][v2] += g_Options.u64HashCapTries[u2][v2]; g_SuiteCounters.u64TotalHashCapFH[u2][v2] += g_Options.u64HashCapFH[u2][v2]; } } } #endif { ULONG v; for (v = 0; v < CM_EVIDENCE_BUCKETS; v++) { g_SuiteCounters.u64TotalCMEvidenceTries[v] += g_Options.u64CMEvidenceTries[v]; g_SuiteCounters.u64TotalCMEvidenceFH[v] += g_Options.u64CMEvidenceFH[v]; } for (v = 0; v < HANG_CP_BUCKETS; v++) { g_SuiteCounters.u64TotalHangEstimateTries[v] += g_Options.u64HangEstimateTries[v]; g_SuiteCounters.u64TotalHangEstimateFH[v] += g_Options.u64HangEstimateFH[v]; } g_SuiteCounters.u64TotalEligibleLeftoverTries += g_Options.u64EligibleLeftoverTries; g_SuiteCounters.u64TotalEligibleLeftoverFH += g_Options.u64EligibleLeftoverFH; for (v = 0; v < GAP_CP_BUCKETS; v++) { g_SuiteCounters.u64TotalGapEstimateTries[v] += g_Options.u64GapEstimateTries[v]; g_SuiteCounters.u64TotalGapEstimateFH[v] += g_Options.u64GapEstimateFH[v]; } for (v = 0; v < MOVE_NUM_BUCKETS; v++) { g_SuiteCounters.u64TotalMoveNumEstimateTries[v] += g_Options.u64MoveNumEstimateTries[v]; g_SuiteCounters.u64TotalMoveNumEstimateFH[v] += g_Options.u64MoveNumEstimateFH[v]; } for (v = 0; v < SEARCH_DEPTH_BUCKETS; v++) { g_SuiteCounters.u64TotalDepthEstimateTries[v] += g_Options.u64DepthEstimateTries[v]; g_SuiteCounters.u64TotalDepthEstimateFH[v] += g_Options.u64DepthEstimateFH[v]; } { ULONG a, b, c; for (a = 0; a < SEARCH_DEPTH_BUCKETS; a++) { for (b = 0; b < HANG_CP_BUCKETS; b++) { for (c = 0; c < GAP_CP_BUCKETS; c++) { for (v = 0; v < MOVE_NUM_BUCKETS; v++) { g_SuiteCounters.u64TotalJointTries[a][b][c][v] += g_Options.u64JointTries[a][b][c][v]; g_SuiteCounters.u64TotalJointFH[a][b][c][v] += g_Options.u64JointFH[a][b][c][v]; } } } } } for (v = 0; v < JOINT_EXTRA_TIER_COUNT; v++) { g_SuiteCounters.u64TotalJointExtraTries[v] += g_Options.u64JointExtraTries[v]; g_SuiteCounters.u64TotalJointExtraResearch[v] += g_Options.u64JointExtraResearch[v]; } g_SuiteCounters.u64TotalLMPPruned += g_Options.u64LMPPruned; // FH_REGRESSION_COLLECTION needs no accumulation here -- see the // g_SuiteCounters struct comment above. #ifdef JOINT_EXTRA_VERIFY { ULONG w; for (v = 0; v < JOINT_EXTRA_TIER_COUNT; v++) { for (w = 0; w < POST_REDUCE_DEPTH_BUCKETS; w++) { g_SuiteCounters.u64TotalJointExtraVerifyTries[v][w] += g_Options.u64JointExtraVerifyTries[v][w]; g_SuiteCounters.u64TotalJointExtraVerifySilentMiss[v][w] += g_Options.u64JointExtraVerifySilentMiss[v][w]; } g_SuiteCounters.u64TotalJointExtraVerifyNullBailoutSignature[v] += g_Options.u64JointExtraVerifyNullBailoutSignature[v]; } } #endif } #ifdef TEST_NULL { ULONG v; for (v = 0; v < NC_TOTAL_BUCKETS; v++) { g_SuiteCounters.u64TotalNCAttempts[v] += g_Options.u64NCAttempts[v]; g_SuiteCounters.u64TotalNCNullFH[v] += g_Options.u64NCNullFH[v]; g_SuiteCounters.u64TotalNCRealFH[v] += g_Options.u64NCRealFH[v]; g_SuiteCounters.u64TotalNCBothFH[v] += g_Options.u64NCBothFH[v]; g_SuiteCounters.u64TotalNCNullProbeNodeSum[v] += g_Options.u64NCNullProbeNodeSum[v]; g_SuiteCounters.u64TotalNCFirstMoveNodeSum[v] += g_Options.u64NCFirstMoveNodeSum[v]; g_SuiteCounters.u64TotalNCRealLoopNodeSum[v] += g_Options.u64NCRealLoopNodeSum[v]; } } #endif } else { ExecuteCommandLineDirectly(szLine, pos); } } // // Shared by ScriptCommand and EpdCommand: the end-of-suite banner and // statistics report. Verbatim extraction of what used to be // ScriptCommand's own tail -- see that function's history for the // meaning of each field. // static void _PrintSuiteReport(double dSuiteStart) { ULONG u, v, uMax; double dMult = (double)g_Options.uMyIncrement / (double)SUITE_NUM_HISTOGRAM; Banner(); Trace("\n" "TEST SCRIPT execution complete. Final statistics:\n" "--------------------------------------------------\n" " correct solutions : %u\n" " incorrect solutions : %u\n" " total problems : %u\n" " total nodecount : %" COMPILER_LONGLONG_UNSIGNED_FORMAT "\n" " avg. search speed : %6.1f nps\n" " avg. solution time : %3.1f sec\n" " avg. search depth : %4.1f ply\n" " 1st move beta cut : %5.2f percent\n" " avg. eff. branching : %5.3f\n" " counter move hit %% : %5.2f percent (%" COMPILER_LONGLONG_UNSIGNED_FORMAT " tries)\n" " leftover : %5.2f%% alpha, %5.2f%% FH (%" COMPILER_LONGLONG_UNSIGNED_FORMAT " tries)\n" " quick nullmove fire : %5.2f%% (%" COMPILER_LONGLONG_UNSIGNED_FORMAT " of %" COMPILER_LONGLONG_UNSIGNED_FORMAT " eligible)\n" " script time : %6.1f sec\n\n", g_SuiteCounters.uCorrect, g_SuiteCounters.uIncorrect, g_SuiteCounters.uTotal, g_SuiteCounters.u64TotalNodeCount, ((double)g_SuiteCounters.u64TotalNodeCount / (SystemTimeStamp() - dSuiteStart)), ((g_SuiteCounters.uCorrect > 0) ? (g_SuiteCounters.dSigmaSolutionTime / (double)g_SuiteCounters.uCorrect) : 0.0), ((double)g_SuiteCounters.uSigmaDepth / (double)g_SuiteCounters.uTotal), (100.0 * (double)g_SuiteCounters.u64TotalBetaCutoffsOnFirstMove / ((double)g_SuiteCounters.u64TotalBetaCutoffs + 1.0)), (g_SuiteCounters.dSigmaEBF / ((double)g_SuiteCounters.uEBFCount + 1.0)), (100.0 * (double)g_SuiteCounters.u64TotalCounterMoveHits / ((double)g_SuiteCounters.u64TotalCounterMoveTries + 1.0)), g_SuiteCounters.u64TotalCounterMoveTries, (100.0 * (double)g_SuiteCounters.u64TotalLeftoverAlpha / ((double)g_SuiteCounters.u64TotalLeftoverTries + 1.0)), (100.0 * (double)g_SuiteCounters.u64TotalLeftoverFH / ((double)g_SuiteCounters.u64TotalLeftoverTries + 1.0)), g_SuiteCounters.u64TotalLeftoverTries, (100.0 * (double)g_SuiteCounters.u64TotalQuickNullMoveSuccess / ((double)g_SuiteCounters.u64TotalQuickNullMoves + 1.0)), g_SuiteCounters.u64TotalQuickNullMoveSuccess, g_SuiteCounters.u64TotalQuickNullMoves, (SystemTimeStamp() - dSuiteStart)); // Countermove evidence calibration -- FH% per evidence bucket, // an ongoing check that COUNTERMOVE_EVIDENCE_THRESHOLD (chess.h) // is still well-calibrated as the engine/data evolve. { static const ULONG uCMEvidenceFloors[CM_EVIDENCE_BUCKETS] = { 0, 1, 100, 1000, 10000, 100000, 1000000 }; Trace("\ncountermove evidence calibration:\n"); for (v = 0; v < CM_EVIDENCE_BUCKETS; v++) { Trace(" evidence >= %8lu : %5.2f%% FH (%" COMPILER_LONGLONG_UNSIGNED_FORMAT " tries)\n", uCMEvidenceFloors[v], (100.0 * (double)g_SuiteCounters.u64TotalCMEvidenceFH[v] / ((double)g_SuiteCounters.u64TotalCMEvidenceTries[v] + 1.0)), g_SuiteCounters.u64TotalCMEvidenceTries[v]); } } // EstimateHangingMaterialCp calibration -- does "how much material // does this leftover move look like it hangs" actually predict // FH%? See chess.h's HANG_CP_BUCKETS comment for the bucket shape // (bucket 0 == not dumb; 1..9 are 100cp-wide bins 1-900cp; 10 is // the 901cp+ overflow). { Trace("\nhanging-material estimate calibration (captures + quiet " "moves, both gated on fPruneReduceEligible):\n"); Trace(" [baseline] eligible : %5.2f%% FH (%" COMPILER_LONGLONG_UNSIGNED_FORMAT " tries)\n", (100.0 * (double)g_SuiteCounters.u64TotalEligibleLeftoverFH / ((double)g_SuiteCounters.u64TotalEligibleLeftoverTries + 1.0)), g_SuiteCounters.u64TotalEligibleLeftoverTries); Trace(" not dumb (0cp) : %5.2f%% FH (%" COMPILER_LONGLONG_UNSIGNED_FORMAT " tries)\n", (100.0 * (double)g_SuiteCounters.u64TotalHangEstimateFH[0] / ((double)g_SuiteCounters.u64TotalHangEstimateTries[0] + 1.0)), g_SuiteCounters.u64TotalHangEstimateTries[0]); for (v = 1; v < HANG_CP_BUCKETS; v++) { if (v < HANG_CP_BUCKETS - 1) { Trace(" %4u - %4u cp lost : %5.2f%% FH (%" COMPILER_LONGLONG_UNSIGNED_FORMAT " tries)\n", 1 + (v - 1) * HANG_CP_BUCKET_WIDTH, v * HANG_CP_BUCKET_WIDTH, (100.0 * (double)g_SuiteCounters.u64TotalHangEstimateFH[v] / ((double)g_SuiteCounters.u64TotalHangEstimateTries[v] + 1.0)), g_SuiteCounters.u64TotalHangEstimateTries[v]); } else { Trace(" %4u+ cp lost : %5.2f%% FH (%" COMPILER_LONGLONG_UNSIGNED_FORMAT " tries)\n", 1 + (v - 1) * HANG_CP_BUCKET_WIDTH, (100.0 * (double)g_SuiteCounters.u64TotalHangEstimateFH[v] / ((double)g_SuiteCounters.u64TotalHangEstimateTries[v] + 1.0)), g_SuiteCounters.u64TotalHangEstimateTries[v]); } } } // The "down axis" -- (iAlpha - iEval) calibration. See chess.h's // GAP_CP_BUCKETS comment for the bucket shape (bucket 0 == gap // <= 0, our own static eval already meets/beats alpha; 1..9 are // 100cp-wide bins for a positive gap of 1-900cp; 10 is the // 901cp+ overflow). Same [baseline] eligible line above applies // here too -- same population, same fPruneReduceEligible gate. { Trace("\ngap-to-alpha estimate calibration (captures + quiet " "moves, both gated on fPruneReduceEligible):\n"); Trace(" gap <= 0 (eval>=alpha): %5.2f%% FH (%" COMPILER_LONGLONG_UNSIGNED_FORMAT " tries)\n", (100.0 * (double)g_SuiteCounters.u64TotalGapEstimateFH[0] / ((double)g_SuiteCounters.u64TotalGapEstimateTries[0] + 1.0)), g_SuiteCounters.u64TotalGapEstimateTries[0]); for (v = 1; v < GAP_CP_BUCKETS; v++) { if (v < GAP_CP_BUCKETS - 1) { Trace(" %4u - %4u cp below alpha : %5.2f%% FH (%" COMPILER_LONGLONG_UNSIGNED_FORMAT " tries)\n", 1 + (v - 1) * GAP_CP_BUCKET_WIDTH, v * GAP_CP_BUCKET_WIDTH, (100.0 * (double)g_SuiteCounters.u64TotalGapEstimateFH[v] / ((double)g_SuiteCounters.u64TotalGapEstimateTries[v] + 1.0)), g_SuiteCounters.u64TotalGapEstimateTries[v]); } else { Trace(" %4u+ cp below alpha : %5.2f%% FH (%" COMPILER_LONGLONG_UNSIGNED_FORMAT " tries)\n", 1 + (v - 1) * GAP_CP_BUCKET_WIDTH, (100.0 * (double)g_SuiteCounters.u64TotalGapEstimateFH[v] / ((double)g_SuiteCounters.u64TotalGapEstimateTries[v] + 1.0)), g_SuiteCounters.u64TotalGapEstimateTries[v]); } } } // The "late axis" -- this move's own 1-based ordinal position // among moves actually tried at this node. See chess.h's // MOVE_NUM_BUCKETS comment -- direct, unpaired buckets, move // number (MOVE_NUM_BUCKETS-2)+ collapses into one overflow // bucket. Same [baseline] eligible line as the other two axes // applies here too. { Trace("\nmove-number estimate calibration (captures + quiet " "moves, both gated on fPruneReduceEligible):\n"); for (v = 1; v < MOVE_NUM_BUCKETS; v++) { if (v < MOVE_NUM_BUCKETS - 1) { Trace(" move %4u : %5.2f%% FH (%" COMPILER_LONGLONG_UNSIGNED_FORMAT " tries)\n", v, (100.0 * (double)g_SuiteCounters.u64TotalMoveNumEstimateFH[v] / ((double)g_SuiteCounters.u64TotalMoveNumEstimateTries[v] + 1.0)), g_SuiteCounters.u64TotalMoveNumEstimateTries[v]); } else { Trace(" move %4u+ : %5.2f%% FH (%" COMPILER_LONGLONG_UNSIGNED_FORMAT " tries)\n", v, (100.0 * (double)g_SuiteCounters.u64TotalMoveNumEstimateFH[v] / ((double)g_SuiteCounters.u64TotalMoveNumEstimateTries[v] + 1.0)), g_SuiteCounters.u64TotalMoveNumEstimateTries[v]); } } } // The "depth axis" -- remaining search depth at this node (uDepth // / ONE_PLY, whole plies, before this move's own extension/ // reduction). Direct, unpaired buckets, index 0 legitimately used // (a heavily-reduced move can arrive at remaining depth 0). Same // [baseline] eligible line as the other axes applies here too. { Trace("\ndepth estimate calibration (captures + quiet moves, " "both gated on fPruneReduceEligible):\n"); for (v = 0; v < SEARCH_DEPTH_BUCKETS; v++) { if (v < SEARCH_DEPTH_BUCKETS - 1) { Trace(" depth %4u : %5.2f%% FH (%" COMPILER_LONGLONG_UNSIGNED_FORMAT " tries)\n", v, (100.0 * (double)g_SuiteCounters.u64TotalDepthEstimateFH[v] / ((double)g_SuiteCounters.u64TotalDepthEstimateTries[v] + 1.0)), g_SuiteCounters.u64TotalDepthEstimateTries[v]); } else { Trace(" depth %4u+ : %5.2f%% FH (%" COMPILER_LONGLONG_UNSIGNED_FORMAT " tries)\n", v, (100.0 * (double)g_SuiteCounters.u64TotalDepthEstimateFH[v] / ((double)g_SuiteCounters.u64TotalDepthEstimateTries[v] + 1.0)), g_SuiteCounters.u64TotalDepthEstimateTries[v]); } } } // Phase 2 -- joint-table-driven graduated LMR calibration: for each // tier (0 == GetLMRReduction's baseline only, 1..3 == that many // extra plies the joint table added), what fraction of moves // assigned that tier triggered the existing re-search-on-fail-high // path? This is the actual scale-calibration mechanism (not the // offline collection data) -- if low-predicted-FH tiers (2, 3) show // an EQUAL OR HIGHER research rate than tier 0/1, that's the // distribution-shift failure this project's history keeps // producing, and the tier thresholds (or the whole approach) need // rethinking before any self-play run. A rising research rate with // tier is the expected, healthy shape. { Trace("\njoint-table extra-reduction tier calibration " "(re-search rate per tier):\n"); for (v = 0; v < JOINT_EXTRA_TIER_COUNT; v++) { Trace(" tier %u (+%u extra ply%s) : %5.2f%% research-rate (%" COMPILER_LONGLONG_UNSIGNED_FORMAT " tries)\n", v, v, (1 == v) ? "" : "s", (100.0 * (double)g_SuiteCounters.u64TotalJointExtraResearch[v] / ((double)g_SuiteCounters.u64TotalJointExtraTries[v] + 1.0)), g_SuiteCounters.u64TotalJointExtraTries[v]); } Trace("\nlate-move pruning (overt skip, not reduction): %" COMPILER_LONGLONG_UNSIGNED_FORMAT " moves pruned\n", g_SuiteCounters.u64TotalLMPPruned); } #ifdef HASHCAP_COLLECTION // 2026-10-23, one-off measurement: P(leftover move fails high | // hash move at this node was a capture, node type guess). See // GNUmakefile's HASHCAP_COLLECTION comment. { static const char *_pszLabel[2][2] = { { "hashMove=quiet/none, type=ALL/PV", "hashMove=quiet/none, type=CUT" }, { "hashMove=capture, type=ALL/PV", "hashMove=capture, type=CUT" }, }; ULONG u2, v2; Trace("\nhash-move-is-capture fail-high calibration " "(leftover moves only):\n"); for (u2 = 0; u2 < 2; u2++) { for (v2 = 0; v2 < 2; v2++) { Trace(" %s : %6.3f%% FH (%" COMPILER_LONGLONG_UNSIGNED_FORMAT " tries)\n", _pszLabel[u2][v2], (100.0 * (double)g_SuiteCounters.u64TotalHashCapFH[u2][v2] / ((double)g_SuiteCounters.u64TotalHashCapTries[u2][v2] + 1.0)), g_SuiteCounters.u64TotalHashCapTries[u2][v2]); } } } #endif #ifdef JOINT_EXTRA_VERIFY // "Silent miss" shadow-verification calibration: of the extra- // reduced moves whose real score never triggered a re-search (the // population the report block above CAN'T see into), how many // would have failed high anyway if just the extra plies were // removed? This is the direct answer to "how much unverified // playing-strength loss is this mechanism causing" -- a real- // search-cost-doubling measurement, JOINT_EXTRA_VERIFY builds only. { UINT64 u64TierTries, u64TierMiss; ULONG w; Trace("\njoint-table extra-reduction SILENT MISS calibration " "(shadow re-search, extra-plies-removed):\n"); for (v = 1; v < JOINT_EXTRA_TIER_COUNT; v++) { u64TierTries = 0; u64TierMiss = 0; for (w = 0; w < POST_REDUCE_DEPTH_BUCKETS; w++) { u64TierTries += g_SuiteCounters.u64TotalJointExtraVerifyTries[v][w]; u64TierMiss += g_SuiteCounters.u64TotalJointExtraVerifySilentMiss[v][w]; } Trace(" tier %u (+%u extra ply%s) : %5.2f%% silent-miss (%" COMPILER_LONGLONG_UNSIGNED_FORMAT " tries), of which %5.2f%% " "(%" COMPILER_LONGLONG_UNSIGNED_FORMAT ") match the null-move " "bailout signature (iShadowScore == beta+1 exactly)\n", v, v, (1 == v) ? "" : "s", (100.0 * (double)u64TierMiss / ((double)u64TierTries + 1.0)), u64TierTries, (100.0 * (double)g_SuiteCounters.u64TotalJointExtraVerifyNullBailoutSignature[v] / ((double)u64TierMiss + 1.0)), g_SuiteCounters.u64TotalJointExtraVerifyNullBailoutSignature[v]); } // Breakdown by EFP's own two-tier margin-schedule boundaries // (search.c's _PostReduceDepthBucketEfpAligned) rather than // plain whole-ply buckets -- tests whether silent misses // concentrate specifically inside EFP's tier windows (a // different pruning mechanism behaving differently there) or // are spread uniformly by remaining depth alone. { static const char *rgszBucketLabel[POST_REDUCE_DEPTH_BUCKETS] = { "< 1 ply (should not happen)", "EFP tier1 (selective futility)", "EFP tier2 (extended futility)", "no EFP, nearby", "no EFP, comfortably deep" }; Trace("\n ...broken down by EFP-tier-aligned remaining " "depth window (is this an EFP-tier-window effect?):\n"); for (v = 1; v < JOINT_EXTRA_TIER_COUNT; v++) { for (w = 0; w < POST_REDUCE_DEPTH_BUCKETS; w++) { Trace(" tier %u, %-32s : %5.2f%% silent-miss (%" COMPILER_LONGLONG_UNSIGNED_FORMAT " tries)\n", v, rgszBucketLabel[w], (100.0 * (double)g_SuiteCounters.u64TotalJointExtraVerifySilentMiss[v][w] / ((double)g_SuiteCounters.u64TotalJointExtraVerifyTries[v][w] + 1.0)), g_SuiteCounters.u64TotalJointExtraVerifyTries[v][w]); } } } } #endif // Joint 4D raw dump for offline reassembly/baking -- one line per // populated cell, marginal (uncoarsened) indices, this checkpoint's // cumulative totals (never summed across checkpoints by the bake // script -- last checkpoint per shard is authoritative, matching // every prior FHGAPRAW/FHJOINTRAW collection run in this project). { ULONG a, b, c; for (a = 0; a < SEARCH_DEPTH_BUCKETS; a++) { for (b = 0; b < HANG_CP_BUCKETS; b++) { for (c = 0; c < GAP_CP_BUCKETS; c++) { for (v = 0; v < MOVE_NUM_BUCKETS; v++) { if (g_SuiteCounters.u64TotalJointTries[a][b][c][v] > 0) { Trace("FOURAXISRAW %lu %lu %lu %lu %" COMPILER_LONGLONG_UNSIGNED_FORMAT " %" COMPILER_LONGLONG_UNSIGNED_FORMAT "\n", a, b, c, v, g_SuiteCounters.u64TotalJointFH[a][b][c][v], g_SuiteCounters.u64TotalJointTries[a][b][c][v]); } } } } } } // FH_REGRESSION_COLLECTION needs no end-of-script dump here -- // each record was already written to its own thread's binary file // as it was produced (fhcollect.c). See docs/REGRESSION.md. #ifdef TEST_NULL // Null-move precision/recall calibration, summed across the whole // suite (see _NullCalibBucketIndex's comment in search.c for the // encoding and what each dimension means). Decode each bucket // index back into its component bands for a readable line; skip // empty cells so this stays legible even though the full table has // NC_TOTAL_BUCKETS cells. { static const char *rgszDepthBand[NC_DEPTH_BUCKETS] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16+" }; static const char *rgszDeficitBand[NC_DEFICIT_BUCKETS] = { "<-300", "-300..-100", "-100..0", "0..100", "100..300", "300+" }; static const char *rgszMaterialBand[NC_MATERIAL_BUCKETS] = { "0-1", "2", "3-5", "6+" }; ULONG uIdx, uDecode, uNullDepthB, uOuterDepthB, uDeficitB; ULONG uMaxMaterialB, uMoverMaterialB; UINT64 u64Attempts, u64NullFH, u64RealFH, u64BothFH; UINT64 u64NullProbeNodeSum, u64FirstMoveNodeSum, u64RealLoopNodeSum; double dAvgNullProbeNodes, dAvgFirstMoveNodes, dAvgRealLoopNodes; double dNullSuccessRate, dEVFirstMoveOnly, dEV; Trace("\nNull-move calibration (attempts / nullFH / realFH / both / " "precision / recall / nullSuccessRate / avgNullProbeNodes / " "avgFirstMoveNodes / avgRealLoopNodes / EVFirstMoveOnly / " "EV-per-attempt-in-nodes):\n"); for (uIdx = 0; uIdx < NC_TOTAL_BUCKETS; uIdx++) { u64Attempts = g_SuiteCounters.u64TotalNCAttempts[uIdx]; if (0 == u64Attempts) continue; u64NullFH = g_SuiteCounters.u64TotalNCNullFH[uIdx]; u64RealFH = g_SuiteCounters.u64TotalNCRealFH[uIdx]; u64BothFH = g_SuiteCounters.u64TotalNCBothFH[uIdx]; u64NullProbeNodeSum = g_SuiteCounters.u64TotalNCNullProbeNodeSum[uIdx]; u64FirstMoveNodeSum = g_SuiteCounters.u64TotalNCFirstMoveNodeSum[uIdx]; u64RealLoopNodeSum = g_SuiteCounters.u64TotalNCRealLoopNodeSum[uIdx]; // Decode uIdx (innermost/fastest-varying dimension first), // matching _NullCalibBucketIndex's encoding in search.c. // Use a scratch copy -- uIdx itself is still the array // index for the lookups above/below. uDecode = uIdx; uMoverMaterialB = uDecode % NC_MATERIAL_BUCKETS; uDecode /= NC_MATERIAL_BUCKETS; uMaxMaterialB = uDecode % NC_MATERIAL_BUCKETS; uDecode /= NC_MATERIAL_BUCKETS; uDeficitB = uDecode % NC_DEFICIT_BUCKETS; uDecode /= NC_DEFICIT_BUCKETS; uOuterDepthB = uDecode % NC_DEPTH_BUCKETS; uDecode /= NC_DEPTH_BUCKETS; uNullDepthB = uDecode % NC_DEPTH_BUCKETS; dAvgNullProbeNodes = (double)u64NullProbeNodeSum / (double)u64Attempts; dAvgFirstMoveNodes = (double)u64FirstMoveNodeSum / (double)u64Attempts; dAvgRealLoopNodes = (double)u64RealLoopNodeSum / (double)u64Attempts; dNullSuccessRate = (double)u64NullFH / (double)u64Attempts; // EV of TRYING null vs. going straight to the real move loop, // in nodes saved per attempt (positive = trying pays off): // on the dNullSuccessRate fraction of attempts we pay the // (cheap) null probe instead of the (expensive) real-loop // cost; on the rest we pay the null probe *in addition* to // still needing the real loop. dEV uses avgRealLoopNodes -- // the true total cost of however the real search actually // resolved the node (one move, several, or production's own // separate null success) -- while dEVFirstMoveOnly keeps the // cheaper move-1-only proxy alongside it for comparison. // Both assume (per the user's simplifying assumption, // matched by this dataset's ~99.96% overall precision) that // a null-move fail-high is correct. dEVFirstMoveOnly = dNullSuccessRate * (dAvgFirstMoveNodes - dAvgNullProbeNodes) - (1.0 - dNullSuccessRate) * dAvgNullProbeNodes; dEV = dNullSuccessRate * (dAvgRealLoopNodes - dAvgNullProbeNodes) - (1.0 - dNullSuccessRate) * dAvgNullProbeNodes; Trace(" nullDepth=%s outerDepth=%s deficit=%s " "maxMaterial=%s moverMaterial=%s : " "%"COMPILER_LONGLONG_UNSIGNED_FORMAT" / " "%"COMPILER_LONGLONG_UNSIGNED_FORMAT" / " "%"COMPILER_LONGLONG_UNSIGNED_FORMAT" / " "%"COMPILER_LONGLONG_UNSIGNED_FORMAT" / " "%5.3f / %5.3f / %5.3f / %10.1f / %10.1f / %10.1f / %10.1f / %10.1f\n", rgszDepthBand[uNullDepthB], rgszDepthBand[uOuterDepthB], rgszDeficitBand[uDeficitB], rgszMaterialBand[uMaxMaterialB], rgszMaterialBand[uMoverMaterialB], u64Attempts, u64NullFH, u64RealFH, u64BothFH, (u64NullFH != 0) ? (100.0 * (double)u64BothFH / (double)u64NullFH) : 0.0, (u64RealFH != 0) ? (100.0 * (double)u64BothFH / (double)u64RealFH) : 0.0, 100.0 * dNullSuccessRate, dAvgNullProbeNodes, dAvgFirstMoveNodes, dAvgRealLoopNodes, dEVFirstMoveOnly, dEV); } } #endif // Histogram stuff if (g_SuiteCounters.uTotal > 0) { uMax = g_SuiteCounters.uHistogram[0]; for (u = 1; u < SUITE_NUM_HISTOGRAM; u++) { if (g_SuiteCounters.uHistogram[u] > uMax) { uMax = g_SuiteCounters.uHistogram[u]; } } for (u = 0; u < SUITE_NUM_HISTOGRAM; u++) { Trace("%4.1f .. %4.1f: ", (double)u * dMult, (double)(u + 1) * dMult); for (v = 0; (uMax > 0) && (v < 50 * g_SuiteCounters.uHistogram[u] / uMax); v++) { Trace("*"); } Trace("\n"); } } } COMMAND(ScriptCommand) /** Routine description: This function implements the 'script' engine command. Usage: script The script command opens the reads the required filename and reads it line by line. Each line of the script file is treated as a command and executed in sequence. Each command is executed fully before the next script line is read and executed. When all lines in the script file have been read and executed the engine will print out a post-script report of test suite statistics and then begin to pay attention to commands from the keyboard again. Scripts are meant to facilitate execution of test suites. Parameters: The COMMAND macro hides four arguments from the input parser: CHAR *szInput : the full line of input ULONG argc : number of argument chunks CHAR *argv[] : array of ptrs to each argument chunk POSITION *pos : a POSITION pointer to operate on Return value: void **/ { FILE *p; static CHAR szLine[SMALL_STRING_LEN_CHAR]; double dSuiteStart; ULONG uGoCount = 0; // 2026-09-28: a wall-clock `timeout`-killed shard (e.g. a 90-minute // sharded joint-table collection run) never reaches true end-of- // script, so _PrintSuiteReport's single end-of-suite call would // never fire and a killed shard would contribute zero data. Print // the same (cumulative, non-resetting) report every // CHECKPOINT_GO_INTERVAL positions too -- the FOURAXISRAW dump (and // every other line in the report) always reflects the full running // total since suite start, so the *last* checkpoint printed before // a kill is a complete, valid snapshot on its own; a bake script // just needs to find and use the last one, never sum across them. #define CHECKPOINT_GO_INTERVAL (5) if (argc < 2) { Trace("Error (Usage: script ): %s\n", argv[0]); return; } if (FALSE == SystemDoesFileExist(argv[1])) { Trace("Error (file doesn't exist): %s\n", argv[1]); return; } p = fopen(argv[1], "rb"); if (NULL != p) { dSuiteStart = SystemTimeStamp(); memset(&(g_SuiteCounters), 0, sizeof(g_SuiteCounters)); while(fgets(szLine, ARRAY_LENGTH(szLine), p)) { _ProcessSuiteLine(szLine, pos); if (!STRNCMPI(szLine, "go", 2)) { uGoCount++; if (0 == (uGoCount % CHECKPOINT_GO_INTERVAL)) { Trace("\nCHECKPOINT after %lu positions:\n", uGoCount); _PrintSuiteReport(dSuiteStart); } } if (TRUE == g_fExitProgram) break; } fclose(p); _PrintSuiteReport(dSuiteStart); } #undef CHECKPOINT_GO_INTERVAL } COMMAND(EpdCommand) /** Routine description: Runs a raw EPD test suite file directly -- no perl preprocessing into a setboard/solution/go script first. Historically the only way to run a suite from real-world EPD (the "board stm castle ep [halfmove fullmove] bm ; id \"...\"; ..." format most public tactical suites ship in) was tests/convert_epd.pl, which had a real, silent-corruption bug: its single "everything between the board and bm is [^b]+" regex breaks on any Black-to-move record (the side-to-move field is literally the character "b"), and because $fen/$id/$solution were unscoped globals rather than per-line locals, a failed match silently carried the *previous* record's board and solution forward instead of erroring -- confirmed live by feeding it a real 5-position batch, where the one Black-to-move line came out as a byte-for-byte duplicate of the line before it. This command replaces that whole external preprocessing step with real per-record EPD parsing (see ParseEpdRecord, fen.c) feeding the exact same _ProcessSuiteLine/_PrintSuiteReport machinery ScriptCommand uses, so a raw EPD file can just be handed to the engine directly. Usage: epd Parameters: The COMMAND macro hides four arguments from the input parser: CHAR *szInput : the full line of input ULONG argc : number of argument chunks CHAR *argv[] : array of ptrs to each argument chunk POSITION *pos : a POSITION pointer to operate on Return value: void **/ { FILE *p; static CHAR szLine[SMALL_STRING_LEN_CHAR]; static CHAR szSynth[SMALL_STRING_LEN_CHAR]; CHAR szFen[SMALL_STRING_LEN_CHAR]; CHAR szId[SMALL_STRING_LEN_CHAR]; CHAR szMoves[SUITE_MAX_SOLUTIONS + SUITE_MAX_AVOIDS][SMALL_STRING_LEN_CHAR]; ULONG uNumMoves; FLAG fIsAvoid; double dSuiteStart; ULONG u; ULONG uLineNum = 0; if (argc < 2) { Trace("Error (Usage: epd ): %s\n", argv[0]); return; } if (FALSE == SystemDoesFileExist(argv[1])) { Trace("Error (file doesn't exist): %s\n", argv[1]); return; } p = fopen(argv[1], "rb"); if (NULL != p) { dSuiteStart = SystemTimeStamp(); memset(&(g_SuiteCounters), 0, sizeof(g_SuiteCounters)); while(fgets(szLine, ARRAY_LENGTH(szLine), p)) { uLineNum++; if (FALSE == ParseEpdRecord(szLine, szFen, ARRAY_LENGTH(szFen), szId, ARRAY_LENGTH(szId), szMoves, ARRAY_LENGTH(szMoves), &uNumMoves, &fIsAvoid)) { if (szLine[0] && (szLine[0] != '\n') && (szLine[0] != '#')) { Trace("epd: skipping unparseable line %lu: %s", uLineNum, szLine); } continue; } snprintf(szSynth, ARRAY_LENGTH(szSynth), "setboard %s\n", szFen); _ProcessSuiteLine(szSynth, pos); if (TRUE == g_fExitProgram) break; if (szId[0]) { snprintf(szSynth, ARRAY_LENGTH(szSynth), "id %s\n", szId); _ProcessSuiteLine(szSynth, pos); } for (u = 0; u < uNumMoves; u++) { snprintf(szSynth, ARRAY_LENGTH(szSynth), "%s %s\n", fIsAvoid ? "avoid" : "solution", szMoves[u]); _ProcessSuiteLine(szSynth, pos); } _ProcessSuiteLine("go\n", pos); if (TRUE == g_fExitProgram) break; } fclose(p); _PrintSuiteReport(dSuiteStart); } } FLAG WeAreRunningASuite(void) /** Routine description: A function that returns TRUE if the engine is running a test suite and FALSE otherwise. Parameters: void Return value: FLAG **/ { if (g_SuiteCounters.uNumSolutions + g_SuiteCounters.uNumAvoids) { return(TRUE); } return(FALSE); } FLAG CheckTestSuiteMove(MOVE mv, SCORE iScore, ULONG uDepth) /** Routine description: This function is called by RootSearch when it has finished a search. The MOVE parameter is the best move that the search found. This code checks that move against the solution or avoid moves for the current position, determines if we "got it right" and updates the test suite counters accordingly. Parameters: MOVE mv Return value: FLAG **/ { FLAG fSolved = FALSE; ULONG u; if (!WeAreRunningASuite()) return FALSE; // // There is(are) solution move(s). // if (g_SuiteCounters.uNumSolutions) { ASSERT(g_SuiteCounters.uNumAvoids == 0); fSolved = FALSE; for (u = 0; u < g_SuiteCounters.uNumSolutions; u++) { if ((mv.cFrom == g_SuiteCounters.mvSolution[u].cFrom) && (mv.cTo == g_SuiteCounters.mvSolution[u].cTo)) { fSolved = TRUE; break; } } if (!fSolved) { g_SuiteCounters.uCurrentSolvedPlies = 0; g_SuiteCounters.dCurrentSolutionTime = 0.0; } else { if (g_SuiteCounters.uCurrentSolvedPlies == 0) { g_SuiteCounters.dCurrentSolutionTime = (SystemTimeStamp() - g_MoveTimer.dStartTime); } g_SuiteCounters.uCurrentSolvedPlies++; } } else if (g_SuiteCounters.uNumAvoids) { // // Handle avoid-move problems. // fSolved = TRUE; for (u = 0; u < g_SuiteCounters.uNumAvoids; u++) { if ((mv.cFrom == g_SuiteCounters.mvAvoid[u].cFrom) && (mv.cTo == g_SuiteCounters.mvAvoid[u].cTo)) { fSolved = FALSE; } } if (!fSolved) { g_SuiteCounters.uCurrentSolvedPlies = 0; g_SuiteCounters.dCurrentSolutionTime = 0.0; } else { if (g_SuiteCounters.uCurrentSolvedPlies == 0) { g_SuiteCounters.dCurrentSolutionTime = (SystemTimeStamp() - g_MoveTimer.dStartTime); } g_SuiteCounters.uCurrentSolvedPlies++; } } else { UtilPanic(SHOULD_NOT_GET_HERE, NULL, NULL, NULL, NULL, __FILE__, __LINE__); } // // Handle "FastScript" variable for solution moves. // if ((g_Options.fFastScript) && (g_SuiteCounters.uCurrentSolvedPlies > 4) && (iScore >= 0)) { if (((g_Options.uMyIncrement != 0) && (SystemTimeStamp() - g_MoveTimer.dStartTime >= (double)g_Options.uMyIncrement / 3)) || ((g_Options.uMaxDepth != 0) && (uDepth >= g_Options.uMaxDepth / 3))) { Trace("FAST SCRIPT --> stop searching now\n"); g_MoveTimer.bvFlags |= TIMER_STOPPING; } } return(fSolved); } void PostMoveTestSuiteReport(SEARCHER_THREAD_CONTEXT *ctx) /** Routine description: If we're running a suite, print a little blurb after each move to act as a running total of how we're doing. Parameters: SEARCHER_THREAD_CONTEXT *ctx Return value: void **/ { MOVE mv = ctx->mvRootMove; ULONG uDepth = ctx->uRootDepth / ONE_PLY, y; double dMult; // // This is the real move the searched picked when all was said and // done (i.e. it ran out of time or reached a fixed depth). See // if it's right. // if (WeAreRunningASuite()) { g_SuiteCounters.uTotal++; g_SuiteCounters.uSigmaDepth += uDepth; if (uDepth > 0) { g_SuiteCounters.dSigmaEBF += pow((double)ctx->sCounters.tree.u64TotalNodeCount, 1.0 / (double)uDepth); g_SuiteCounters.uEBFCount++; } if (CheckTestSuiteMove(mv, -1, uDepth)) { Trace("Problem %s solved in %3.1f sec.\n", g_SuiteCounters.szId, g_SuiteCounters.dCurrentSolutionTime); g_SuiteCounters.uCorrect++; g_SuiteCounters.dSigmaSolutionTime += g_SuiteCounters.dCurrentSolutionTime; dMult = (double)g_Options.uMyIncrement / (double)SUITE_NUM_HISTOGRAM; ASSERT(SUITE_NUM_HISTOGRAM > 0); for (y = 1; y <= SUITE_NUM_HISTOGRAM; y++) { if (g_SuiteCounters.dCurrentSolutionTime < ((double)y * dMult)) { g_SuiteCounters.uHistogram[y-1]++; break; } if (y == SUITE_NUM_HISTOGRAM) { // // This one is actually > time-to-think. This // really happens... like we had 20 sec to think // and solved it in 20.1 or something before the // stop-searching timer was checked. // g_SuiteCounters.uHistogram[y-1]++; } } } else { Trace(">>>>> Problem %s was not solved. <<<<<\n\n", g_SuiteCounters.szId); g_SuiteCounters.uIncorrect++; } Trace("Current suite score: %u correct of %u problems.\n", g_SuiteCounters.uCorrect, g_SuiteCounters.uTotal); _ClearSuiteData(); } }