Update codebase to remove clang warnings (and a couple of legit errors
[typhoon.git] / src / draw.c
1 /**
2
3 Copyright (c) Scott Gasch
4
5 Module Name:
6
7     draw.c
8
9 Abstract:
10
11     Function for detecting a draw by repetition from the search tree.
12
13 Author:
14
15     Scott Gasch ([email protected]) 19 May 2004
16
17 Revision History:
18
19     $Id: draw.c 345 2007-12-02 22:56:42Z scott $
20
21 **/
22
23 #include "chess.h"
24
25 FLAG
26 IsDraw(SEARCHER_THREAD_CONTEXT *ctx)
27 {
28     ULONG uPly;
29     UINT64 u64CurrentSig;
30     
31     //
32     // Recognize 50-moves w/o progress draw rule
33     // 
34     if (ctx->sPosition.uFifty >= 100)
35     {
36         return(TRUE);
37     }
38
39     //
40     // Check for repeated positions if needed.
41     // 
42     if (ctx->sPosition.uFifty < 4)
43     {
44         return(FALSE);
45     }
46
47     u64CurrentSig = (ctx->sPosition.u64NonPawnSig ^
48                      ctx->sPosition.u64PawnSig);
49     uPly = ctx->uPly - 2;
50     while(uPly < MAX_PLY_PER_SEARCH)
51     {
52 #ifdef DEBUG
53         if ((GET_COLOR(ctx->sPlyInfo[uPly].mv.pMoved) != 
54              ctx->sPosition.uToMove) &&
55             (ctx->sPlyInfo[uPly].mv.uMove != 0))
56         {
57             ASSERT(FALSE);
58         }
59         ASSERT(ctx->sPlyInfo[uPly].u64Sig == (ctx->sPlyInfo[uPly].u64PawnSig ^
60                                            ctx->sPlyInfo[uPly].u64NonPawnSig));
61 #endif
62         if (ctx->sPlyInfo[uPly].u64Sig == u64CurrentSig)
63         {
64             return(TRUE);
65         }
66         
67         if (IS_PAWN(ctx->sPlyInfo[uPly].mv.pMoved) ||
68             (ctx->sPlyInfo[uPly].mv.pCaptured))
69         {
70             return(FALSE);
71         }
72         uPly -= 2;
73     }
74     
75     //
76     // Keep looking in the official game record.
77     //
78     return(DoesSigAppearInOfficialGameList(u64CurrentSig));
79 }