• Post Reply Bookmark Topic Watch Topic
  • New Topic

Bitboard size of 256 bits  RSS feed

 
Rain Draken
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I know that bitboards can be used for boards of a size up to 64 bits but can this be extended all the way to 256 bits, the reason is I want to make a game with a board but the board needs 256 bits as it is 16x16 is this possible with a bitboard and what primitive type will be used to hold the values as a long only goes up to 64 bits, also if a bitboard can't be used what else can be used an array will work but it will be to slow.
 
Tim Moores
Saloon Keeper
Posts: 3893
91
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know what a "bitboard" is, or why it would be limited to 64 bits, but such functionality is available in Java via the java.util.BitSet class. It is not limited to a particular size (although eventually via the available memory :-)
 
Campbell Ritchie
Marshal
Posts: 55770
163
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is a bitboard? Is it the same as a BitSet? If you look at that, you can see it defaults to 64 bits, but if you need 65+ bits, it simply adds another 64 to its capacity.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Long ago (in fact, one of the very first programs I wrote in Java) I wrote a small Java program for the game of chess. A chess board has 8x8 = 64 fields. One technique that was used in chess is to use bitboards - for each type of chess piece you would use a 64-bit long, in which the bits each correspond to a field on the board. You would for example have a 64-bit long for the pawns; if a bit is 1, then there is a pawn on the corresponding field, and if it's 0 there's no pawn.

This is useful because a CPU can easily handle 64-bit integers, so this is an efficient way to store a chess board in memory.

Since there is no 256-bit primitive type in Java (nor in any other programming language that I'm aware of), there's no way to do this in the same way for 256 bits.

However, class BitSet, which Tim and Campbell already mentioned, is an efficient way to store an array of bits of arbitrary size, so that's probably the best way to go in Java. A BitSet stores its bits in multiple 64-bit long fields, and gives you convenient methods to manipulate the bits.
 
Rain Draken
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi thank you for the advice I will do it with bitsets.
 
Rain Draken
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper new exactly what I was talking about thank you
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!