1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
/**
Copyright (c) Scott Gasch
Module Name:
testsee.c
Abstract:
This code is meant to sanity check the SEE routine. It works by
using the generator and MakeMove/UnmakeMove to play out a sequence
of moves on a single square. It's somewhat useful code but right
now I don't really use it because it is too good: it detects
things like pieces that are pinned against the king whereas the
SEE itself does not. Still, I'd want to run it and verify the
discrepencies if I was doing much work in the SEE code.
Author:
Scott Gasch ([email protected]) 21 Oct 2004
Revision History:
**/
#include "chess.h"
#ifdef TEST_BROKEN
ULONG g_uRootOnMove;
SCORE
DebugSEERecursive(SEARCHER_THREAD_CONTEXT *ctx,
MOVE mv)
{
SCORE i, iMinMax;
ULONG x;
MOVE mvReply;
ULONG uToMove = ctx->sPosition.uToMove;
//
// Make the move, this is not optional
//
ASSERT(GET_COLOR(mv.pMoved) == uToMove);
if (FALSE == MakeMove(ctx, mv))
{
return(INVALID_SCORE);
}
//
// Initialize MinMax to the stand pat score here so that the reply
// can be "something else".
//
iMinMax = ((ctx->sPosition.uPawnMaterial[g_uRootOnMove] +
ctx->sPosition.uNonPawnMaterial[g_uRootOnMove]) -
(ctx->sPosition.uPawnMaterial[FLIP(g_uRootOnMove)] +
ctx->sPosition.uNonPawnMaterial[FLIP(g_uRootOnMove)]));
//
// Generate the reply moves.
//
GenerateMoves(ctx, (MOVE){0}, GENERATE_DONT_SCORE);
for (x = ctx->sMoveStack.uBegin[ctx->uPly];
x < ctx->sMoveStack.uEnd[ctx->uPly];
x++)
{
//
// Only consider replies that end up on the same sq as the
// move.
//
mvReply = ctx->sMoveStack.mvf[x].mv;
ASSERT(SanityCheckMove(&ctx->sPosition, mvReply));
if (mvReply.cTo != mv.cTo)
{
continue;
}
i = DebugSEERecursive(ctx, mvReply);
if (INVALID_SCORE != i)
{
if ((ctx->uPly % 2) == 0)
{
if (i > iMinMax) iMinMax = i;
}
else
{
if (i < iMinMax) iMinMax = i;
}
}
}
//
// Unmake the original move
//
UnmakeMove(ctx, mv);
return(iMinMax);
}
SCORE
DebugSEE(POSITION *pos,
MOVE mv)
{
SCORE iRootBalance = ((pos->uPawnMaterial[pos->uToMove] +
pos->uNonPawnMaterial[pos->uToMove]) -
(pos->uPawnMaterial[FLIP(pos->uToMove)] +
pos->uNonPawnMaterial[FLIP(pos->uToMove)]));
SCORE iAfterExchange = iRootBalance;
SEARCHER_THREAD_CONTEXT *ctx =
malloc(sizeof(SEARCHER_THREAD_CONTEXT));
g_uRootOnMove = pos->uToMove;
if (NULL != ctx)
{
pos->uDangerCount[BLACK] = pos->uDangerCount[WHITE] = 0;
InitializeSearcherContext(pos, ctx);
GenerateMoves(ctx, (MOVE){0}, GENERATE_DONT_SCORE);
mv.bvFlags |= WouldGiveCheck(ctx, mv);
if (InCheck(pos, pos->uToMove))
{
mv.bvFlags |= MOVE_FLAG_ESCAPING_CHECK;
}
iAfterExchange = DebugSEERecursive(ctx, mv);
if (iAfterExchange != INVALID_SCORE)
{
iAfterExchange -= iRootBalance;
}
free(ctx);
}
return(iAfterExchange);
}
#endif
#ifdef TEST
FLAG
SeeListsAreEqual(SEE_LIST *pA, SEE_LIST *pB)
{
ULONG u;
if (pA->uCount != pB->uCount) return FALSE;
for (u = 0; u < pA->uCount; u++)
{
if ((pA->data[u].pPiece != pB->data[u].pPiece) ||
(pA->data[u].cLoc != pB->data[u].cLoc) ||
(pA->data[u].uVal != pB->data[u].uVal))
{
return FALSE;
}
}
return TRUE;
}
void
TestGetAttacks(void)
{
POSITION pos;
ULONG u;
COOR c;
SEE_LIST rgSlowList;
SEE_LIST rgAsmList;
ULONG color;
#ifndef _X86_
return;
#endif
Trace("Testing GetAttacks...\n");
for (u = 0; u < 20000; u++)
{
GenerateRandomLegalPosition(&pos);
FOREACH_SQUARE(c)
{
if (!IS_ON_BOARD(c)) continue;
for (color = BLACK; color <= WHITE; color++)
{
SlowGetAttacks(&rgSlowList,
&pos,
c,
color);
GetAttacks(&rgAsmList,
&pos,
c,
color);
if (!SeeListsAreEqual(&rgSlowList, &rgAsmList))
{
UtilPanic(TESTCASE_FAILURE,
&pos,
"SEE_LIST mismatch", &rgSlowList, &rgAsmList,
__FILE__, __LINE__);
}
}
}
}
}
#endif // TEST
|