void Game::configure(GameConfiguration config) { if (!config.isValid()) { throw std::invalid_argument("Invalid configuration: " + config.str()); } config.clean(); reset(); curTurn = config.getTurn(); FOR_POSITION_64(pos) { setPieceAt(pos, config.getPieceAt(pos)); if (config.getPieceAt(pos) != Piece::EMPTY()) { toggleBit(config.getOwnerAt(pos), pos, config.getPieceAt(pos)); } } cur = Game_UndoData(); cur.halfMoveClock = config.getHalfMoveClock(); fullMoveCount = config.getMoveNumber(); cur.check = posAttackedBy(getKingPosition(getTurn()), !getTurn()); cur.hash = Game_Hash(config); integrityCheck(); }
void testToggleBit() { cout << endl; cout << "Test toggleBit():" << endl; cout << "=================" << endl; unsigned int n = 0; for (int i = 0; i < 32; ++i) { n = toggleBit(n, i); printBits(n); } for (int i = 0; i < 32; ++i) { n = toggleBit(n, i); printBits(n); } }
void testCountOneBits() { cout << endl; cout << "Test countOneBits():" << endl; cout << "====================" << endl; unsigned int n = 0; for (int i = 0; i < 32; ++i) { n = toggleBit(n, i); printBits(n); cout << "Number of 1 bits = " << countOneBits(n) << endl; } for (int i = 0; i < 32; ++i) { n = toggleBit(n, i); printBits(n); cout << "Number of 1 bits = " << countOneBits(n) << endl; } }
ToggleResult toggleSetting ( unsigned char *setting, int command, const TuneDefinition *offTune, const TuneDefinition *onTune ) { const int bit = 1; int bits = *setting? bit: 0; ToggleResult result = toggleBit(&bits, bit, command, offTune, onTune); *setting = (bits & bit)? 1: 0; return result; }
static ToggleResult toggleSetting ( unsigned char *setting, int command, AlertIdentifier offAlert, AlertIdentifier onAlert ) { const int bit = 1; int bits = *setting? bit: 0; ToggleResult result = toggleBit(&bits, bit, command, offAlert, onAlert); *setting = (bits & bit)? bit: 0; return result; }