@@ -174,27 +174,27 @@ std::vector<Move> MoveGenerator::tacticalMoves(const ChessBoard&board) {
174
174
}
175
175
176
176
177
- bool MoveGenerator::isSquareAttacked (const ChessBoard&board, int_fast8_t square, Color color) {
177
+ bool MoveGenerator::isSquareAttacked (const ChessBoard&board, const int_fast8_t square, const Color color) {
178
178
const int_fast8_t sign = (color == WHITE) ? -1 : 1 ;
179
179
180
180
// PAWNS
181
181
for (int i = 1 ; i < 3 ; ++i) {
182
182
const int_fast8_t n = MAILBOX[MAILBOX64[square] + (sign * OFFSET[PAWN][i])];
183
183
if (n != -1 ) {
184
- if (board.squares [n].color != color && board.squares [n].type == PAWN ) return true ;
184
+ if (board.squares [n].type == PAWN && board.squares [n].color != color ) return true ;
185
185
}
186
186
}
187
187
// KNIGHTS
188
188
for (int i = 0 ; i < OFFSETS[KNIGHT]; ++i) {
189
189
const int_fast8_t n = MAILBOX[MAILBOX64[square] + OFFSET[KNIGHT][i]];
190
190
if (n != -1 ) {
191
- if (board.squares [n].color != color && board.squares [n].type == KNIGHT ) return true ;
191
+ if (board.squares [n].type == KNIGHT && board.squares [n].color != color ) return true ;
192
192
}
193
193
}
194
194
// REST
195
195
for (int i = 0 ; i < OFFSETS[QUEEN]; ++i) {
196
196
int_fast8_t n = square;
197
- int_fast8_t offset = OFFSET[QUEEN][i];
197
+ const int_fast8_t offset = OFFSET[QUEEN][i];
198
198
bool sliding = false ;
199
199
while (true ) {
200
200
n = MAILBOX[MAILBOX64[n] + offset];
@@ -203,9 +203,9 @@ bool MoveGenerator::isSquareAttacked(const ChessBoard&board, int_fast8_t square,
203
203
if (target.type != EMPTY) {
204
204
if (target.color != color && (SLIDE[target.type ] || !sliding) && target.type != PAWN &&
205
205
target.type != KNIGHT) {
206
- const int_fast8_t * offsetPtr = std::find (OFFSET[ target.type ], OFFSET[target. type ] + OFFSETS[ target.type ],
207
- offset);
208
- if (offsetPtr != OFFSET[ target.type ] + OFFSETS[target. type ] ) return true ;
206
+ if ( target.type == QUEEN || target.type == KING) return true ;
207
+ if (i % 2 == 0 ) { if (target. type == BISHOP) return true ;}
208
+ else { if (target.type == ROOK ) return true ;}
209
209
}
210
210
break ;
211
211
}
@@ -232,10 +232,6 @@ unsigned long long MoveGenerator::perft(int depth, ChessBoard&board) {
232
232
board.makeMove (move);
233
233
if (!inCheck (board, invertColor (board.sideToMove ))) {
234
234
const unsigned long long childNodes = perft (depth - 1 , board);
235
- // if(depth == 6){
236
- // printf("Move: %s-%s %d\n", Util::positionToString(move.start).c_str(), Util::positionToString(move.end).c_str(), move.flag);
237
- // printf("Nodes: %llu\n", childNodes);
238
- // }
239
235
nodes += childNodes;
240
236
}
241
237
board.unMakeMove ();
0 commit comments