Skip to content

Commit

Permalink
fix movegen bug
Browse files Browse the repository at this point in the history
  • Loading branch information
PGG106 committed Nov 20, 2022
1 parent 7ca1f9c commit 80e1db1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ int main(int argc, char** argv) {
S_Board pos[1];
S_SearchINFO info[1];
S_Stack ss[1];
S_MOVELIST move_list[1];
Reset_info(info);
InitHashTable(HashTable, 16);
setvbuf(stdin, NULL, _IONBF, 0);
Expand Down
17 changes: 9 additions & 8 deletions src/movegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,11 @@ static inline void AddPawnMove(const S_Board* pos, const int from, const int to,
}

static inline Bitboard LegalPawnMoves(S_Board* pos, int color, int square) {
Bitboard enemy = pos->occupancies[color ^ 1];
Bitboard enemy = pos->occupancies[color ^ 1] | 1ULL << pos->enPas;

// If we are pinned diagonally we can only do captures which are on the pin_dg
// and on the checkmask

if (pos->pinD & (1ULL << square))
return pawn_attacks[color][square] & pos->pinD & pos->checkMask & enemy;
// Calculate pawn pushs
Expand Down Expand Up @@ -146,8 +147,8 @@ static inline Bitboard LegalPawnMoves(S_Board* pos, int color, int square) {
ClearPiece(theirPawn, (pos->enPas + offset), pos);
AddPiece(ourPawn, pos->enPas, pos);
if (!((get_rook_attacks(kSQ, pos->occupancies[2]) &
(GetPieceColorBB(pos, ROOK,color ^ 1) |
GetPieceColorBB(pos,QUEEN, color ^ 1)))))
(GetPieceColorBB(pos, ROOK, color ^ 1) |
GetPieceColorBB(pos, QUEEN, color ^ 1)))))
moves |= (1ULL << pos->enPas);
AddPiece(ourPawn, square, pos);
AddPiece(theirPawn, pos->enPas + offset, pos);
Expand Down Expand Up @@ -394,11 +395,11 @@ void generate_captures(S_MOVELIST* move_list, S_Board* pos) {
init(pos, pos->side, KingSQ(pos, pos->side));

if (pos->checks < 2) {
Bitboard pawn_mask = GetPieceColorBB(pos,PAWN ,pos->side);
Bitboard knights_mask = GetPieceColorBB(pos, KNIGHT,pos->side);
Bitboard bishops_mask = GetPieceColorBB(pos, BISHOP,pos->side);
Bitboard rooks_mask = GetPieceColorBB(pos, ROOK,pos->side);
Bitboard queens_mask = GetPieceColorBB(pos, QUEEN,pos->side);
Bitboard pawn_mask = GetPieceColorBB(pos, PAWN, pos->side);
Bitboard knights_mask = GetPieceColorBB(pos, KNIGHT, pos->side);
Bitboard bishops_mask = GetPieceColorBB(pos, BISHOP, pos->side);
Bitboard rooks_mask = GetPieceColorBB(pos, ROOK, pos->side);
Bitboard queens_mask = GetPieceColorBB(pos, QUEEN, pos->side);

while (pawn_mask) {
// init source square
Expand Down
2 changes: 1 addition & 1 deletion src/perft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ unsigned long long perft_test(int depth, S_Board *pos) {
long old_nodes = nodes - cummulative_nodes;

// print move
printf(" move: %s%s%c nodes: %ld\n",
printf(" %s%s%c: %ld\n",
square_to_coordinates[get_move_source(
move_list->moves[move_count].move)],
square_to_coordinates[get_move_target(
Expand Down

0 comments on commit 80e1db1

Please sign in to comment.