I could use a representation where blank is 0, king =1, ... but for code simplicity, I preferred to keep the FEN symbols in here.
In order to be able to define static arrays that are not huge (see eval.cpp) and only occupy 13 elements, that can be coded easily, I want to map the piece symbols into integers in the fastest possible way, and came up with a 128 byte array in which some elements are filled in with index values. Coding this in C++11 resulted in below implementation. I really like this mapper implementation as it is just one deference away from the real value and easy to understand.
This generates some compile warning (and probably the crash at exit on Mac OS X could be related to that).
Code: Select all
// .cpp code, create mapper array
vector<int> bPieceIndex = [] {
vector<int> bIndex(128);
bIndex['K'] = 1;
// and so on
return bIndex;
}();
// warning: declaration requires an exit-time destructor
// warning: requires a global destructor
static int piecevalues[13] = { 0, 2000 };
// dereferencing is as simple as that
int somevar = piecevalues[bPieceIndex['K']];
I will probably move to bitboards but this would be avoiding the problem instead of resolving it. I want to resolve.