Beispiel #1
0
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();
}
bool RockPaperScissors::placePiece(int playerNumber, const Piece& p, int fromRow, int fromColumn, int toRow, int toColumn, int lineNumber, const string& line, Status& currentStatus) {
	Cell& fromCell = board[fromRow][fromColumn];

	if (currentStatus.getIsPositioningPhase() == true) {
		//empty valid cell
		if (fromCell.getPlayerOwning() == NO_PLAYER) {
			//player has pieces left
			if (getNumberOfPiecesLeftToPlace(playerNumber, p) > 0) {
				decreasePieceFromStock(playerNumber, p);//reduce 1 piece left for player
				increasePieceOnBoard(playerNumber, p);//increase 1 piece on board for player
				fromCell.setCell(p, playerNumber);
				return true;
			}
			//illegal - out of pieces
			else {
				cout << "Player " << playerNumber << " had no more " << p << " pieces at line " << lineNumber + 1 << ":" << endl \
					<< line << endl;
				currentStatus.setStatus(playerNumber, PossibleStatus::input_File_Error, fromRow, line);
				return false;
			}
		}
		//illegal - same place piece
		else if (fromCell.getPlayerOwning() == playerNumber) {
			cout << "Player " << playerNumber << " tried to place a " << p << " in line " << lineNumber + 1 << ":" << endl \
				<< line << endl \
				<< "where he already placed there a " << fromCell.getCellPiece() << " before." << endl;
			currentStatus.setStatus(playerNumber, PossibleStatus::input_File_Error, lineNumber + 1, line);
			return false;
		}
		//legal place - fight
		else {
			decreasePieceFromStock(playerNumber, p);//reduce 1 piece from stock
			increasePieceOnBoard(playerNumber, p);//increase 1 piece on board 
			fight(fromRow, fromColumn, p, playerNumber);
			return true;
		}
	}

	else {//moving phase
		Cell& toCell = board[toRow][toColumn];
		const Piece& newP = fromCell.getCellPiece();
		//empty destination cell
		if (toCell.getPlayerOwning() == NO_PLAYER) {
			toCell.setCell(newP, playerNumber); //move piece to destination
			fromCell.setCell(Piece()); //remove piece from source cell
		}

		//legal place - fight
		else {
			fight(toRow, toColumn, newP, playerNumber);
			setPieceAt(fromRow, fromColumn, NO_PLAYER);//remove piece from original cell
		}
	}
	return true;
}
Beispiel #3
0
Position::Position() 
{
    for (int i = 0; i < 8; i++)
    for (int j = 0; j < 8; j++)
        setPieceAt(i, j, Piece());
}