1 /***************************************************************************
2 draw.cpp - Draw recognition
4 begin : Sun Nov 28 2007
5 copyright : (C) 2007 by Maurizio Monge
6 email : monge@linuz.sns.it
7 ***************************************************************************/
9 /***************************************************************************
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. *
16 ***************************************************************************/
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 */
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
])
38 return insufficient_material();
41 bool Engine::insufficient_material()
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)
52 /* ok, unless the 2 bishop are on squares of the same color :) */
53 if(board
.mat_tracking
[BISHOP
+mt
].count
>= 2)
56 if(board
.mat_tracking
[KNIGHT
+mt
].count
>= 1 &&
57 board
.mat_tracking
[BISHOP
+mt
].count
>= 1)
60 /* let's not consider insufficient material in 3-knights engames! */
61 if(board
.mat_tracking
[KNIGHT
+mt
].count
>= 3)