-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmovegen.cpp
78 lines (74 loc) · 3.06 KB
/
movegen.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
Clarity
Copyright (C) 2024 Joseph Pasfield
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "masks.h"
#include "slidey.h"
// classical approach move generation
uint64_t getRookAttacksOld(int square, uint64_t occupiedBitboard) {
uint64_t attacks = 0;
for(int direction = 0; direction < 4; direction++) {
uint64_t currentAttack = slideyPieceRays[direction][square];
if((direction & 1) == 0) {
currentAttack ^= slideyPieceRays[direction][std::clamp(std::countr_zero(currentAttack & occupiedBitboard), 0, 63)];
} else {
currentAttack ^= slideyPieceRays[direction][std::clamp(63 - std::countl_zero(currentAttack & occupiedBitboard), 0, 63)];
}
attacks |= currentAttack;
}
return attacks;
}
uint64_t getBishopAttacksOld(int square, uint64_t occupiedBitboard) {
uint64_t attacks = 0;
for(int direction = 4; direction < 8; direction++) {
uint64_t currentAttack = slideyPieceRays[direction][square];
if((direction & 1) == 0) {
currentAttack ^= slideyPieceRays[direction][std::countr_zero(currentAttack & occupiedBitboard)];
} else {
currentAttack ^= slideyPieceRays[direction][63 - std::countl_zero(currentAttack & occupiedBitboard)];
}
attacks |= currentAttack;
}
return attacks;
}
// this is getting the attacks from either pext or magic bitboard move generation, which is decided by which build is being done
uint64_t getRookAttacks(int square, uint64_t occupiedBitboard) {
assert(square < 64);
return getRookAttacksFromTable(occupiedBitboard, square);
}
uint64_t getBishopAttacks(int square, uint64_t occupiedBitboard) {
assert(square < 64);
return getBishopAttacksFromTable(occupiedBitboard, square);
}
// pawn pushes
uint64_t getPawnPushes(uint64_t pawnBitboard, uint64_t emptyBitboard, int colorToMove) {
return (colorToMove == 0 ? pawnBitboard >> 8 : pawnBitboard << 8) & emptyBitboard;
}
uint64_t getDoublePawnPushes(uint64_t pawnAttacks, uint64_t emptyBitboard, int colorToMove) {
pawnAttacks &= getRankMask(colorToMove == 1 ? 2 : 5);
return (colorToMove == 0 ? pawnAttacks >> 8 : pawnAttacks << 8) & emptyBitboard;
}
// using the lookups from Homura
uint64_t getPawnAttacks(int square, int colorToMove) {
return pawnAttacks[colorToMove][square];
}
uint64_t getKnightAttacks(int square) {
return knightAttacks[square];
}
uint64_t getKingAttacks(int square) {
return kingAttacks[square];
}
// using my own lookups, cool
uint64_t getPassedPawnMask(int square, int colorToMove) {
return passedPawnMasks[colorToMove][square];
}