Re-enabled pawn-attack-escape extension.
[rattatechess.git] / draw.cpp
blob8f5089c9f6d966f0de985fbca06264198c3c0cc7
1 /***************************************************************************
2 draw.cpp - Draw recognition
3 -------------------
4 begin : Sun Nov 28 2007
5 copyright : (C) 2007 by Maurizio Monge
6 email : monge@linuz.sns.it
7 ***************************************************************************/
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
18 #include "engine.h"
20 /* check if the position can be considered draw for 50mvs rule or repetition */
21 bool Engine::check_draw()
23 if(board.fifty >= 50) /* 50mvs rule, at the moment */
24 return true;
26 /* for the latest reversible moves check if the hash value
27 (for this player) is the same */
28 int first_candidate = MAX(board.num_old_hashes-(board.fifty/2)*2, 0);
30 /* -4 because it is impossible that the previous position is
31 equal to the current one :) */
32 for(int i=board.num_old_hashes-4;i>=first_candidate;i-=2)
34 if(board.hash == board.old_hashes[i])
35 return true;
38 return insufficient_material();
41 bool Engine::insufficient_material()
43 for(int i=0;i<2;i++)
45 int mt = (i ? 5 : -1);
47 if(board.mat_tracking[PAWN+mt].count > 0
48 || board.mat_tracking[QUEEN+mt].count > 0
49 || board.mat_tracking[ROOK+mt].count > 0)
50 return false;
52 /* ok, unless the 2 bishop are on squares of the same color :) */
53 if(board.mat_tracking[BISHOP+mt].count >= 2)
54 return false;
56 if(board.mat_tracking[KNIGHT+mt].count >= 1 &&
57 board.mat_tracking[BISHOP+mt].count >= 1)
58 return false;
60 /* let's not consider insufficient material in 3-knights engames! */
61 if(board.mat_tracking[KNIGHT+mt].count >= 3)
62 return false;
64 return true;