Reputation: 63
I have a chess program written in Java. Currently I am using a 2d char array to represent the chessboard. Upper case characters to represent white and lower case to represent black. Should I use an array of bytes to reduce the memory usage? Or maybe enums? Thank you.
Upvotes: 6
Views: 2836
Reputation: 1313
In short: The most efficient and professional way is to use Bitboards.
Basically, there are 3 ways of representing a chessboard that are often used:
8x8 2-dimensional array: Slow but easy to maintain
10x12 1-dimensional array: Faster, a little bit trickier
Bitboards: They are the fastest method, also used in professional engines like Stockfish or Rybka. Basically, you need a 64-Bit uint for every figure type, where every bit stands for a single field. For more information, i recommend the chessprogramming wiki or google=>bitboards.
Upvotes: 7