- std::stringstream s;
- bool upcase = false;
-
- // Build up a fen substring with the given pieces, note
- // that the fen string could be of an illegal position.
- for (size_t i = 0; i < keyCode.length(); i++)
- {
- if (keyCode[i] == 'K')
- upcase = !upcase;
-
- s << char(upcase? toupper(keyCode[i]) : tolower(keyCode[i]));
- }
- s << 8 - keyCode.length() << "/8/8/8/8/8/8/8 w -";
- return Position(s.str()).get_material_key();
-}
-
-const string EndgameFunctions::swapColors(const string& keyCode) {
-
- // Build corresponding key for the opposite color: "KBPKN" -> "KNKBP"
- size_t idx = keyCode.find("K", 1);
- return keyCode.substr(idx) + keyCode.substr(0, idx);
-}
-
-template<EndgameType et>
-void EndgameFunctions::add_ef(const string& keyCode) {
-
- EEFmap.insert(std::pair<Key, EF*>(buildKey(keyCode), new EvaluationFunction<et>(WHITE)));
- EEFmap.insert(std::pair<Key, EF*>(buildKey(swapColors(keyCode)), new EvaluationFunction<et>(BLACK)));
-}
-
-template<EndgameType et>
-void EndgameFunctions::add_sf(const string& keyCode) {
-
- ScalingInfo s1 = {WHITE, new ScalingFunction<et>(WHITE)};
- ScalingInfo s2 = {BLACK, new ScalingFunction<et>(BLACK)};
-
- ESFmap.insert(std::pair<Key, ScalingInfo>(buildKey(keyCode), s1));
- ESFmap.insert(std::pair<Key, ScalingInfo>(buildKey(swapColors(keyCode)), s2));