summaryrefslogtreecommitdiff
path: root/src/testsearch.c
diff options
context:
space:
mode:
authorScott Gasch <[email protected]>2016-06-01 18:58:58 -0700
committerScott Gasch <[email protected]>2016-06-01 18:58:58 -0700
commit3fd43cd5fcb22bb65bf2a92a25d95d801b11c9e0 (patch)
tree9b6443235d16ba17f094a1a1c7ae53d2bcb9267b /src/testsearch.c
Initial checkin for typhoon chess engine.
Diffstat (limited to 'src/testsearch.c')
-rw-r--r--src/testsearch.c123
1 files changed, 123 insertions, 0 deletions
diff --git a/src/testsearch.c b/src/testsearch.c
new file mode 100644
index 0000000..4290a4f
--- /dev/null
+++ b/src/testsearch.c
@@ -0,0 +1,123 @@
+/**
+
+Copyright (c) Scott Gasch
+
+Module Name:
+
+ testsearch.c
+
+Abstract:
+
+ This is a test module to sanity check the search code. It
+ operates by generating a random legal chess position and
+ performing a two-ply search on the position. It is expected that
+ the search will terminate and return a legal move.
+
+Author:
+
+ Scott Gasch ([email protected]) 2 Jan 2005
+
+Revision History:
+
+**/
+
+#include "chess.h"
+
+#ifdef TEST
+#define TIME_LIMIT 200.0
+
+void
+SetMoveTimerForTestingSearch(void)
+{
+ g_MoveTimer.uNodeCheckMask = 0x10000 - 1;
+ g_MoveTimer.dStartTime = SystemTimeStamp();
+ g_MoveTimer.bvFlags = 0;
+ g_MoveTimer.dSoftTimeLimit = g_MoveTimer.dStartTime + TIME_LIMIT;
+ g_MoveTimer.dHardTimeLimit = g_MoveTimer.dStartTime + TIME_LIMIT;
+}
+
+FLAG
+TestSearch(void)
+{
+ SEARCHER_THREAD_CONTEXT *ctx;
+ POSITION pos;
+ ULONG u;
+ FLAG fOver;
+ FLAG fPost = g_Options.fShouldPost;
+ FLAG fRet = FALSE;
+
+ ctx = SystemAllocateMemory(sizeof(SEARCHER_THREAD_CONTEXT));
+ ASSERT(ctx);
+ g_Options.fShouldPost = FALSE;
+ Trace("Testing Search routine...\n");
+ for (u = 0; u < 20; u++)
+ {
+ GenerateRandomLegalPosition(&pos);
+ InitializeSearcherContext(&pos, ctx);
+
+ g_MoveTimer.bvFlags = 0;
+ g_Options.fPondering = FALSE;
+ g_Options.fThinking = TRUE;
+ g_Options.fSuccessfulPonder = FALSE;
+
+ MaintainDynamicMoveOrdering();
+ DirtyHashTable();
+
+ //
+ // TODO: Any preEval?
+ //
+
+ //
+ // Set a very long time limit on the search
+ //
+ SetMoveTimerForTestingSearch();
+ g_Options.uMaxDepth = 2;
+
+ //
+ // TODO: Set draw value
+ //
+#if (PERF_COUNTERS && MP)
+ ClearHelperThreadIdleness();
+#endif
+ fOver = Iterate(ctx);
+
+ //
+ // How long did that take?
+ //
+ if (SystemTimeStamp() - g_MoveTimer.dStartTime > TIME_LIMIT)
+ {
+ UtilPanic(TESTCASE_FAILURE,
+ NULL, "TestSearch", NULL, NULL,
+ __FILE__, __LINE__);
+ }
+
+ //
+ // Did we get a sane move?
+ //
+ if (GAME_NOT_OVER == fOver)
+ {
+ if (FALSE == SanityCheckMove(&pos, ctx->mvRootMove))
+ {
+ UtilPanic(TESTCASE_FAILURE,
+ NULL, "TestSearch", NULL, NULL,
+ __FILE__, __LINE__);
+ }
+ }
+#ifdef DEBUG
+ else if (GAME_WHITE_WON == fOver)
+ {
+ ASSERT(InCheck(&pos, BLACK));
+ }
+ else if (GAME_BLACK_WON == fOver)
+ {
+ ASSERT(InCheck(&pos, WHITE));
+ }
+#endif
+ }
+ fRet = TRUE;
+
+ g_Options.fShouldPost = fPost;
+ SystemFreeMemory(ctx);
+ return(fRet);
+}
+#endif