actually add threat.h
This commit is contained in:
parent
49aa6ec54b
commit
1bb28da249
|
|
@ -0,0 +1,42 @@
|
|||
#ifndef __THREAT_H_INC
|
||||
#define __THREAT_H_INC
|
||||
|
||||
namespace Threat {
|
||||
byte can_capture(byte square) {
|
||||
// TODO make this more efficient
|
||||
byte t = 0;
|
||||
Board::swap_side();
|
||||
Movegen gen = Movegen();
|
||||
Move m;
|
||||
while((m = gen.next_move()).sq_to != 255) {
|
||||
if(m.sq_to == square) {
|
||||
t++;
|
||||
}
|
||||
}
|
||||
Board::swap_side();
|
||||
return t;
|
||||
}
|
||||
|
||||
byte threats(byte square) {
|
||||
byte t = 0;
|
||||
Board::swap_side();
|
||||
t = can_capture(square);
|
||||
Board::swap_side();
|
||||
return t;
|
||||
}
|
||||
|
||||
bool is_check() {
|
||||
byte king_ptr = Board::field[PTR_W_KING | Board::black_moving()];
|
||||
return (threats(king_ptr)) > 0;
|
||||
}
|
||||
|
||||
bool illegal() {
|
||||
// if the enemy king can be captured, move they did is illegal.
|
||||
byte king_ptr = Board::field[PTR_W_KING | !Board::black_moving()];
|
||||
return (can_capture(king_ptr)) > 0;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Loading…
Reference in New Issue