Questions tagged [bitboard]

A bitboard is a data structure commonly used in computer systems that play board games.

A bitboard, often used for boardgames such as chess, checkers and othello, is a specialization of the bitset data structure, where each bit represents a game position or state, designed for optimization of speed and/or memory or disk use in mass calculations. Bits in the same bitboard relate to each other in the rules of the game often forming a game position when taken together. Other bitboards are commonly used as masks to transform or answer queries about positions. The "game" may be any game-like system where information is tightly packed in a structured form with "rules" affecting how the individual units or pieces relate.

85 questions
33
votes
9 answers

"Isolate" specific Row/Column/Diagonal from a 64-bit number

OK, let's consider a 64-bit number, with its bits forming a 8x8 table. E.g. 0 1 1 0 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 1 1 0 1 0 0 1 1 0 1 0 1 0 1 1 1 0 1 0 1 0 0 1 1 0 1 0 1 0 0 1 1 0 1 1 1 0 0 1 1 0 1 0 1 0 written as a b c d e f g…
Dr.Kameleon
  • 22,532
  • 20
  • 115
  • 223
19
votes
2 answers

Test if a bitboard have only one bit set to 1

I have a bitboard and I want to check in C if there is ONLY one bit set to 1. #include typedef uint64_t bboard; bboard b = 0x0000000000000010; if (only_one_bit_set_to_one (b)) // in this example expected true // do something... Any…
Pioz
  • 6,051
  • 4
  • 48
  • 67
13
votes
3 answers

Bitwise (Bitshift) operations on 64-bit integers in C++

I'm trying to deal with bitboards, which requires me to set a particular bit in a 64-bit unsigned integer. To set bit i, I perform a bitwise OR with the bitboard in question, with a left shifted number. #include uint64_t kings = 0ULL; //…
Shreyas
  • 667
  • 2
  • 7
  • 20
13
votes
3 answers

Sliding move generation using magic bitboard

This is a question regarding the big picture of how to validate a sliding piece move in chess using magic bitboards. Just to clarify, I am not asking how magic bitboards work internally. Now, some more details about the question. I'm writing chess…
bytefire
  • 4,156
  • 2
  • 27
  • 36
9
votes
1 answer

Not understanding how the bitboard technique works for chess boards

My brain is smoking trying to understand the mechanics of this bitboard technique. In order to make it simple, lets imagine that, instead of chess and a lot of complex piece movements, we have a game with only two pieces and one a row of 8…
Duck
  • 34,902
  • 47
  • 248
  • 470
7
votes
4 answers

Bitboard to titboard (ternary bitboard) conversion

In many board games (like checkers, go and othello/reversi) each square can be represented by three states: white, black or empty. 8x8 boards in such game engines are usually represented as two bitboards: one 64-bit integer for location of white…
Andriy Makukha
  • 7,580
  • 1
  • 38
  • 49
6
votes
2 answers

Chess bitboard implementation in Java

I'm looking to create a basic chess (or failing that, checkers/draughts) engine. After researching the topic I'm fairly confident that I want to use a series of bitboards. I understand the concept at a basic level but I'm having trouble representing…
BeepBeep
  • 151
  • 3
  • 9
5
votes
1 answer

Chess Bitboard Population

In some bitboard chess engines piece bitboards are initialized as follows: white_pawns = 0x000000000000ff00 black_pawns = 0x00ff000000000000 white_knights = 0x000000000000042 black_knights = 0x4200000000000000 white_bishops…
5
votes
2 answers

How to iterate over a bit value?

I want to build a chessboard via bitboard system. Starting with 12 bitboards i want to display a table (chessboard), during loop/iteration a piece must be drawn. How do i loop through all bitvalues? I was thinking of something…
Terradon
  • 883
  • 2
  • 13
  • 33
4
votes
0 answers

Python Bitboard more than 64bit using Numpy lib

i'm actually trying to create an AI that can play a board game. My problem is that the boardgame is using a 9x9 square, so i can't use a 64bitboards like usually. Is there any way on how to use more than 64bitboard? I though of using 3 32bit…
Fanto
  • 377
  • 3
  • 14
4
votes
3 answers

Bit scan forward and reverse in numpy

I need to count the number of trailing and leading zeros in a numpy uint64 variable, so right now I'm doing it like this: # n > 0 n = np.uint64(100) s = np.binary_repr(n) trail_zeros = len(s) - len(s.rstrip('0')) lead_zeros = 64 - len(s) Is there a…
Fernando
  • 7,785
  • 6
  • 49
  • 81
3
votes
1 answer

Fast way of checking for alignment of in a 6x6 bitboard

I am trying to find a quick and fast way to check for alignment of 5 bits in a 6x6 board in all directions (diagonal, horizontal, vertical). The board is represented as a bitboard as they are very fast. The bitboard is like this: 00 01 02 03 04 05 …
3
votes
1 answer

how to use bitboards in chess?

I am making a bitboard based chess engine and I would like to ask - assuming that I made a bitboard to every piece, what do I do with it? I read a little bit about some techniques like if you shift the pawns bit board to the left by 7 and 9 you get…
Michael
  • 61
  • 1
  • 7
3
votes
1 answer

Understanding "o^(o-2r)" formula for generating sliding piece moves using unsigned bitboards?

What I Am Trying To Do I am trying to perform some bitwise operations to create a chess engine. To make this engine, I need to be able to generate moves for pieces, like rooks. There is a handy formula for creating a bitboard of squares available…
David Chopin
  • 2,780
  • 2
  • 19
  • 40
3
votes
1 answer

Is there a way to reverse the bit order in UInt64?

I am building a chess engine in Swift based off a tutorial written in Java. In the tutorial, Java's signed 64 bit integer long has a static method called reverse(long i) that "Returns the value obtained by reversing the order of the bits in the…
David Chopin
  • 2,780
  • 2
  • 19
  • 40
1
2 3 4 5 6