1 /***************************************************************************
2 evaluate.cpp - description
4 begin : Tue Nov 01 2005
5 copyright : (C) 2005 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 ***************************************************************************/
23 // 1 2 4 8 16 32 64 128
24 uint8_t Board::attack_dirs
[] = { UP
, DOWN
, LEFT
, RIGHT
, (uint8_t)(UP
+LEFT
), (uint8_t)(DOWN
+LEFT
),
25 (uint8_t)(DOWN
+RIGHT
), (uint8_t)(UP
+RIGHT
) };
28 Board::print_attacks()
33 A88 attacks
= x
>= 8 ? w_attacks
: b_attacks
;
34 uint8_t p
= POS_XY(x
%8,y
);
37 else if(attacks
[p
] == 8)
39 else if(attacks
[p
] == 4)
41 else if(attacks
[p
] == 1)
43 else if(attacks
[p
] == 2)
45 else if(attacks
[p
] == 3)
47 else if(attacks
[p
] == 12)
49 else if(attacks
[p
] == 16 || attacks
[p
] == 64)
51 else if(attacks
[p
] == 32 || attacks
[p
] == 128)
53 else if(!(attacks
[p
] & 0x0f))
55 else if(!(attacks
[p
] & 0xf0))
68 Board::check_attacks()
70 struct { DEF2_A88(old_b
, old_w
); } a
;
75 uint8_t p
= POS_XY(i
,j
);
76 a
.old_b
[p
] = b_attacks
[p
];
77 a
.old_w
[p
] = w_attacks
[p
];
85 uint8_t p
= POS_XY(i
,j
);
86 ASSERT(a
.old_b
[p
] == b_attacks
[p
]);
87 ASSERT(a
.old_w
[p
] == w_attacks
[p
]);
93 Board::recalc_attacks()
98 for(int i
=0;i
<mat_tracking
[BB_12
].count
;i
++)
99 add_attacks(BB
, mat_tracking
[BB_12
].pos
[i
]);
100 for(int i
=0;i
<mat_tracking
[BR_12
].count
;i
++)
101 add_attacks(BR
, mat_tracking
[BR_12
].pos
[i
]);
102 for(int i
=0;i
<mat_tracking
[BQ_12
].count
;i
++)
103 add_attacks(BQ
, mat_tracking
[BQ_12
].pos
[i
]);
104 for(int i
=0;i
<mat_tracking
[WB_12
].count
;i
++)
105 add_attacks(WB
, mat_tracking
[WB_12
].pos
[i
]);
106 for(int i
=0;i
<mat_tracking
[WR_12
].count
;i
++)
107 add_attacks(WR
, mat_tracking
[WR_12
].pos
[i
]);
108 for(int i
=0;i
<mat_tracking
[WQ_12
].count
;i
++)
109 add_attacks(WQ
, mat_tracking
[WQ_12
].pos
[i
]);
115 Board::add_attacks(uint8_t piece
, uint8_t where
)
117 A88 data
= this->data
;
119 /* update the attacks passing through this place */
120 for(int is_white
= 0; is_white
<2; is_white
++)
122 A88 attacks
= is_white
? w_attacks
: b_attacks
;
131 if(!(attacks
[where
] & m
))
134 uint8_t inc
= attack_dirs
[d
];
135 uint8_t currpos
= where
+inc
;
138 while(!OUT_OF_BOARD(currpos
))
140 /* clear the "attack from this direction" flag */
141 attacks
[currpos
] &= m
;
151 A88 attacks
= IS_WHITE(piece
) ? w_attacks
: b_attacks
;
153 /* if ROOK-like movements... */
154 if( (PIECE_OF(piece
) & ~BISHOP
) == ROOK
)
159 uint8_t inc
= attack_dirs
[d
];
160 uint8_t currpos
= where
+inc
;
162 while(!OUT_OF_BOARD(currpos
))
164 /* set the "attack from this direction" flag */
165 attacks
[currpos
] |= m
;
175 /* if BISHOP-like movements... */
176 if( (PIECE_OF(piece
) & ~ROOK
) == BISHOP
)
181 uint8_t inc
= attack_dirs
[d
];
182 uint8_t currpos
= where
+inc
;
184 while(!OUT_OF_BOARD(currpos
))
186 /* set the "attack from this direction" flag */
187 attacks
[currpos
] |= m
;
199 Board::del_attacks(uint8_t piece
, uint8_t where
)
201 A88 data
= this->data
;
202 A88 attacks
= IS_WHITE(piece
) ? w_attacks
: b_attacks
;
204 /* if ROOK-like movements... */
205 if( (PIECE_OF(piece
) & ~BISHOP
) == ROOK
)
210 uint8_t inc
= attack_dirs
[d
];
211 uint8_t currpos
= where
+inc
;
213 while(!OUT_OF_BOARD(currpos
))
215 /* clear the "attack from this direction" flag */
216 attacks
[currpos
] &= m
;
226 /* if BISHOP-like movements... */
227 if( (PIECE_OF(piece
) & ~ROOK
) == BISHOP
)
232 uint8_t inc
= attack_dirs
[d
];
233 uint8_t currpos
= where
+inc
;
235 while(!OUT_OF_BOARD(currpos
))
237 /* clear the "attack from this direction" flag */
238 attacks
[currpos
] &= m
;
248 /* update the attacks passing through this place */
249 for(int is_white
= 0; is_white
<2; is_white
++)
251 A88 attacks
= is_white
? w_attacks
: b_attacks
;
260 if(!(attacks
[where
] & m
))
263 uint8_t inc
= attack_dirs
[d
];
264 uint8_t currpos
= where
+inc
;
266 while(!OUT_OF_BOARD(currpos
))
268 /* clear the "attack from this direction" flag */
269 attacks
[currpos
] |= m
;
281 Board::replace_attacks(uint8_t piece1
, uint8_t piece2
, uint8_t where
)
283 A88 attacks
= IS_WHITE(piece1
) ? w_attacks
: b_attacks
;
285 /* if ROOK-like movements... */
286 if( (PIECE_OF(piece1
) & ~BISHOP
) == ROOK
)
291 uint8_t inc
= attack_dirs
[d
];
292 uint8_t currpos
= where
+inc
;
294 while(!OUT_OF_BOARD(currpos
))
296 /* clear the "attack from this direction" flag */
297 attacks
[currpos
] &= m
;
307 /* if BISHOP-like movements... */
308 if( (PIECE_OF(piece1
) & ~ROOK
) == BISHOP
)
313 uint8_t inc
= attack_dirs
[d
];
314 uint8_t currpos
= where
+inc
;
316 while(!OUT_OF_BOARD(currpos
))
318 /* clear the "attack from this direction" flag */
319 attacks
[currpos
] &= m
;
330 attacks
= IS_WHITE(piece2
) ? w_attacks
: b_attacks
;
332 /* if ROOK-like movements... */
333 if( (PIECE_OF(piece2
) & ~BISHOP
) == ROOK
)
338 uint8_t inc
= attack_dirs
[d
];
339 uint8_t currpos
= where
+inc
;
341 while(!OUT_OF_BOARD(currpos
))
343 /* set the "attack from this direction" flag */
344 attacks
[currpos
] |= m
;
354 /* if BISHOP-like movements... */
355 if( (PIECE_OF(piece2
) & ~ROOK
) == BISHOP
)
360 uint8_t inc
= attack_dirs
[d
];
361 uint8_t currpos
= where
+inc
;
363 while(!OUT_OF_BOARD(currpos
))
365 /* set the "attack from this direction" flag */
366 attacks
[currpos
] |= m
;
377 #endif //TRACK_ATTACKS