3 Copyright (c) Scott Gasch
11 This is a test module to sanity check the search code. It
12 operates by generating a random legal chess position and
13 performing a two-ply search on the position. It is expected that
14 the search will terminate and return a legal move.
27 #define TIME_LIMIT 200.0
30 SetMoveTimerForTestingSearch(void)
32 g_MoveTimer.uNodeCheckMask = 0x10000 - 1;
33 g_MoveTimer.dStartTime = SystemTimeStamp();
34 g_MoveTimer.bvFlags = 0;
35 g_MoveTimer.dSoftTimeLimit = g_MoveTimer.dStartTime + TIME_LIMIT;
36 g_MoveTimer.dHardTimeLimit = g_MoveTimer.dStartTime + TIME_LIMIT;
42 SEARCHER_THREAD_CONTEXT *ctx;
46 FLAG fPost = g_Options.fShouldPost;
49 ctx = SystemAllocateMemory(sizeof(SEARCHER_THREAD_CONTEXT));
51 g_Options.fShouldPost = FALSE;
52 Trace("Testing Search routine...\n");
53 for (u = 0; u < 20; u++)
55 GenerateRandomLegalPosition(&pos);
56 InitializeSearcherContext(&pos, ctx);
58 g_MoveTimer.bvFlags = 0;
59 g_Options.fPondering = FALSE;
60 g_Options.fThinking = TRUE;
61 g_Options.fSuccessfulPonder = FALSE;
63 MaintainDynamicMoveOrdering();
71 // Set a very long time limit on the search
73 SetMoveTimerForTestingSearch();
74 g_Options.uMaxDepth = 2;
77 // TODO: Set draw value
79 #if (PERF_COUNTERS && MP)
80 ClearHelperThreadIdleness();
85 // How long did that take?
87 if (SystemTimeStamp() - g_MoveTimer.dStartTime > TIME_LIMIT)
89 UtilPanic(TESTCASE_FAILURE,
90 NULL, "TestSearch", NULL, NULL,
95 // Did we get a sane move?
97 if (GAME_NOT_OVER == fOver)
99 if (FALSE == SanityCheckMove(&pos, ctx->mvRootMove))
101 UtilPanic(TESTCASE_FAILURE,
102 NULL, "TestSearch", NULL, NULL,
107 else if (GAME_WHITE_WON == fOver)
109 ASSERT(InCheck(&pos, BLACK));
111 else if (GAME_BLACK_WON == fOver)
113 ASSERT(InCheck(&pos, WHITE));
119 g_Options.fShouldPost = fPost;
120 SystemFreeMemory(ctx);