Geralt_of_Rivia: That chess board is wrong. The rows are numbered from bottom to top. White is on the bottom covering the rows 1 and 2, black is on top covering rows 7 and 8.
Been a while, although inverting the numbers is easily enough.
Gede: Actually, I meant the internal data structures you use to store the board position.
When reading about the Crafty engine, and learning about the bitboard representation, I was really surprised. Once CPUs would move to 64-bit, it would provide a big jump in processing speed when using this method.
You seem to be using and array of 8 arrays, right?
[code]
enum Pieces { NA=0, Pole=0, Pawn, Knight, Bishop, Rook, Queen, King};
enum Side { White, Black, Green, Red };
struct Piece {
mixin(bitfields!(
Pieces,"piece" ,3,
Side,"player" ,2, //i've seen 4way chess before, so this opens that up.
uint,"x" ,3,
uint,"y" ,3,
uint,"z" ,2, //potentially 3D chess
bool,"moved" ,1, //for castling, and first pawn move options
uint, "", 2 //unused
));
}
struct Board {
alias Grid = Piece[8][8];
Grid grid;
Piece playerPieces[2][16] = [
[
Piece(Pieces.Rook, Side.White, 0, 7), Piece(Pieces.Rook, Side.White, 7, 7),
Piece(Pieces.Knight, Side.White, 1, 7), Piece(Pieces.Knight, Side.White, 6, 7),
Piece(Pieces.Bishop, Side.White, 2, 7), Piece(Pieces.Bishop, Side.White, 5, 7),
Piece(Pieces.Queen, Side.White, 3, 7), Piece(Pieces.King, Side.White, 4, 7),
// ... etc
[/code]
This gives each piece all it's information while fitting in 16bits. This means i can store the entire board in 32 entries rather than 64.
However for checking if a spot is used, using an 8x8 grid is easier, and calculating the score is easier that way too...