-
Notifications
You must be signed in to change notification settings - Fork 0
/
board_helper.cpp
executable file
·46 lines (38 loc) · 1.42 KB
/
board_helper.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**********************************************************************
|
| Bogart
| Chess Engine
|
| Copyright (C) 2009-2013 Dr.Kameleon
|
|**********************************************************************
| board_search.cpp
|**********************************************************************/
#include "bogart.h"
//=======================================================
// Attack Squares
//=======================================================
BOOL Board::isAttacked(int sq)
{
U64 ownPieces = this->piecesForColor(this->playing) | (1ULL<<sq);
U64 occupied = ~(this->pieces[empty]) | (1ULL<<sq);
int p = 3*(-this->playing)+3;
if ((QUEEN_(sq,ownPieces,occupied)) & (this->pieces[p+bQueen])) return true;
if ((BISHOP_(sq,ownPieces,occupied)) & (this->pieces[p+bBishops])) return true;
if ((KNIGHT_(sq,ownPieces,occupied)) & (this->pieces[p+bKnights])) return true;
if ((ROOK_(sq,ownPieces,occupied)) & (this->pieces[p+bRooks])) return true;
if ((this->playing==White) && ((WPAWN_(sq,ownPieces,occupied)) & (this->pieces[bPawns]))) return true;
if ((this->playing==Black) && ((BPAWN_(sq,ownPieces,occupied)) & (this->pieces[wPawns]))) return true;
if ((KING_(sq,ownPieces,occupied)) & (this->pieces[p+bKing])) return true;
return false;
}
BOOL Board::isKingAttacked()
{
U64 king = this->pieces[3*this->playing+3+bKing];
if (king!=0)
{
UINT pos = FIRSTBIT(king);
return this->isAttacked(pos);
}
else return true;
}