The point is an array with const indices may be treated as homogeneous struct of elements of the same type, but not vice versa. For an example with struct fields and switch/cases rather than indices, see Beowulf.OneTrickPony wrote:Thanks, this is helpful.
Both of you didn't address one of my questions though: is it better to have arrays (for example like the ones you presented) or just fields ...
I like Evert's dense approach to have a struct of two arrays, one for six piece-type- and one for the two color bitboards. In cpw, I have proposed pieceBB[8] with appropriate combined (anonymous) enum for the same purpose:
Code: Select all
enum enumPieceColorOrType {
eWhite, // 0
eBlack, // 1
ePawn, // 2
eKnight,// 3
eBishop,// 4
eRook, // 5
eQueen, // 6
eKing // 7
};
Code: Select all
enum enumPieceCode {
ePCEmpty = 0,
ePCwhitePawn = 2 * ePawn + eWhite, // 4
ePCblackPawn = 2 * ePawn + eBlack, // 5
ePCwhiteKnight = 2 * eKnight + eWhite, // 6
ePCblackKnight = 2 * eKnight + eBlack, // 7
ePCwhiteBishop = 2 * eBishop + eWhite, // 8
ePCblackBishop = 2 * eBishop + eBlack, // 9
ePCwhiteRook = 2 * eRook + eWhite, // 10
ePCblackRook = 2 * eRook + eBlack, // 11
ePCwhiteQueen = 2 * eQueen + eWhite, // 12
ePCblackQueen = 2 * eQueen + eBlack, // 13
ePCwhiteKing = 2 * eKing + eWhite, // 14
ePCblackKing = 2 * eKing + eBlack // 15
};
