6
votes
Quickly converting board to bitboard representation using python-chess library
To convert a single bitboard to a numpy array:
def bitboard_to_array(bb: int) -> np.ndarray:
s = 8 * np.arange(7, -1, -1, dtype=np.uint64)
b = (bb >> s).astype(np.uint8)
b = np....
6
votes
Quickly converting board to bitboard representation using python-chess library
python-chess already has the built in utilities to handle conversions. Here is an example:
import chess
board = chess.Board('rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1')
WP = board....
6
votes
Accepted
What's the right approach of storing moves generated using bitboards?
Q1: Should I generate all pawn moves at once?
Yes. There's no reason not to do that. But... your code wouldn't work because you're returning a bitboard in your function. You should instead return a ...
6
votes
Accepted
Chess Engine: Generate a Bitboard of Pinned Pieces
This task is nontrivial and cannot be obtained easily or setwise from the available bitboards.
The following solution is an example for how such a task might be done for a generic slider - only ...
5
votes
What's the right approach of storing moves generated using bitboards?
I really appreciate the response from our contributors, but still there is a question unanswered floating on air. How do I implement the “MOVE” structure? Based on Bitboard approach?
In reality, there ...
5
votes
Accepted
Representing Moves found via BitBoards, applying them, and removing them
My last chess engine used bitboards to store position information. It represented moves as a vector of simple move structures that looks something like this:
struct move_info {
char move[2]; ...
5
votes
Accepted
How do I apply moves (bitboard) and continue searching? My current attempt is throwing a strange error!
The issue may be here:
Board newBoard = board;
This creates a new variable, but it doesn't actually create a new Board. board and newBoard are pointing to the exact same Board object. So, when your ...
4
votes
Accepted
Fastest way to parse a bitboard
I found some well hidden pages in the Chess Programming Wiki.
The first one basically introduces your solution:
https://www.chessprogramming.org/Bitboard_Serialization#Single_Bits
However, the next ...
3
votes
Accepted
How do Chess Bitboards generate individual moves?
How would you be able to tell individual moves like this? Would you
have to separate it out, i.e. create a bit-board with only one square?
In a similar vein, if there were to be multiple moves, how ...
3
votes
Accepted
Bitboard chess engine design
I'm building a chess engine but I often find myself overwhelmed
I can identify quite a lot with how you're currently feeling. So before I address your questions, I'd like to give some encouragement ...
3
votes
Accepted
How do I complete this implementation of magic bitboards?
It is probably most efficient if I paste my code from my chess move generator on GitHub.
int ROOK_ATTACK_SHIFTS[64];
Bitboard ROOK_ATTACK_MASKS[64];
Bitboard ROOK_ATTACKS[64][4096];
void ...
3
votes
Fastest way to generate castling moves in a computer chess engine
It's been a long time since I've made any efficiency mods, but this can be reduced to one if statement, but many would be easier to read.
if
!bitboard_occupied // easy to find by ORing with f1/g1 (or ...
3
votes
Accepted
Are these magics wrong?
I think you're misunderstanding something here based on the way you formulated your question. Multiplying the blockers by the magic and the shifting does not give you the attack set. What it gives ...
3
votes
Can engines use the current pawn structure to refine its search/eval?
Something very similar is doubtless encoded into AlphaZero and Leela's neural network evaluators, which are very positional. Most conventional Minimax engines, by contrast, are stronger at tactics ...
2
votes
Understanding magic bitboard
It's not about avoiding the border. It's about avoiding the last bit of the ray.
Given this:
10000000
10000000
10000000
10000000
10000000
10000000
10000000
01111111
(Note that A1 should be zero as ...
2
votes
Accepted
Building a chess using magic bitboard... how do I know if the movement is valid
Let me answer your questions for @MikeJones:
You will need to store the generated moves in a bitboard. The following code example should work:
unsigned int moves = .... // This gives a bitboard of ...
2
votes
Building a chess using magic bitboard... how do I know if the movement is valid
Make a bitboard of all the white pieces. If the AND of the possible knight move and the white pieces is TRUE, then the move is illegal--attempting to capture your own piece.
The simplest way is to ...
2
votes
Chess Engine: Generate a Bitboard of Pinned Pieces
Pinned pieces only exist when attackers are sliding pieces (bishop, rook, queen). Also pinned pieces can move along the attack ray to the king, you cannot exclude them from legal moves directly. For ...
2
votes
Border pieces in Magic Bitboards
The move mask is only used to obtain the pieces that will block the Bishop. Edge pieces will never block any diagonal moves.
Given the blockers and the Bishop's location the algorithm then looks up ...
2
votes
Fastest way to generate castling moves in a computer chess engine
I am not sure about the fastest way but I used pre-defined bitboards with 1:s on the bishop and knight squares (and queen if castling queen side) respectively and AND those together with the all ...
2
votes
Accepted
Move generation for sliding pieces and Hyperbola Quintessence
Your implementation looks incorrect to me. Here's the correct hyperbola quintessence implementation:
Bitboard hyp_quint(Square square, Bitboard occ, Bitboard mask) {
return (((mask & occ) - ...
2
votes
Accepted
Search function for chess engines
One possible approach is to decrement the evaluation for a mate score. For instance:
evaluation = -search(pos, depth - 1, -beta, -alpha);
if (evaluation > 900) {
evaluation--;
} else if (...
2
votes
Storing generated moves for a chess engine in Java
My answer is not about chess, just as your question only superficially is about chess. The questions you ask are really about other things, and you may be better advised to try to address that part of ...
2
votes
Accepted
Issue with Magic Bitboards
After some more investigation, if found out that the issue was in the GetRookMoves function. The issue was that i was using the ROOK_MASK as parameter and not the ROOK_MAGIC array.
uint64_t ...
1
vote
Accepted
Border pieces in Magic Bitboards
The method of magic bitboards basically applies a hash function to the important occupancy, or in other words, all the pieces that could potentially block the currently moving piece.
For example, let'...
1
vote
Accepted
Evaluation function in a bitboard based chess engine
Given there is a maximum of 16 pieces on the chessboard you could loop on the pieces instead of the 64 squares. In this way, the less pieces on the board the faster.
Each piece contains the index of ...
1
vote
Accepted
Bitboards and sliding piece attacks
You would use the same AND-ing of the board map and the attack bitmap to get a set of attacked positions, but you must then also cast a ray from any attacked piece back to the attacker to verify that ...
1
vote
Accepted
Fastest way to generate castling moves in a computer chess engine
Castling checks seem easy to short-circuit to be efficient. For my own implementation (not blazing fast), I did the following checks in order:
Generate pseudo-legal move:
Castling rights: Booleans ...
1
vote
How to store moves for a magic bitboard system?
It sounds like you have all the tools to do the job, you just need to put it all together. And yes, you can use the magic numbers you found.
When your engine initializes (or any time before you begin ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
bitboard × 29engines × 25
programming × 17
software × 5
computer-chess × 4
evaluation × 1
pawn-structure × 1
attack × 1
rooks × 1
python × 1
pins × 1
performance × 1
open-source × 1
chess-ai × 1