Exemple #1
0
bool	RulesChecker::checkEndingCapture(std::pair<int, int> index, GRID_REF grid, eTurn & turn, int & opponentScore, PLAYER_PAWNS_REF container){

	std::pair<PAIR_INT, PAIR_INT> *ptr;

	// Get opponent block
	eBlock opponent = (turn == eTurn::TURN_PLAYER_1 ? eBlock::PLAYER_2 : eBlock::PLAYER_1);
	// int opponentScore = (turn == eTurn::TURN_PLAYER_1 ? _player2Captures : _player1Captures);

	// Iterate through grid
	for (int j = 0; j < GRID_SIZE; j++){
		for (int i = 0; i < GRID_SIZE; i++){

			// If the case is empty
			if (grid[j][i] == eBlock::EMPTY){

				// we set the case at this index to be the opponent (needed by _checkCapture)
				grid[j][i] = opponent;

				// if there is possible capture we return true, the game continue
				if ((ptr = checkCapture(i, j, grid)) != NULL){

					bool res = false;
					if ((res = _checkIfCaptureBreaksAlignement(ptr, index, grid, turn, container))){
						// std::cout << "BREAKS 5 STONES" << std::endl;
					}
					else{

						// check if the opponent can win with this capture
						if (opponentScore >= 8) {
							res = true;
						}
					}

					// We set back the value at the index to empty
					grid[j][i] = eBlock::EMPTY;

					// clean
					delete ptr;

					return res ;
				}

				// We set back the value at the index to empty
				grid[j][i] = eBlock::EMPTY;
			}
		}
	}
	return false ;
}
Exemple #2
0
bool Model::checkPosition(MoveRule moveRule, const Figure& figure, Move& move, int movetype, bool needCheck) const {

    if (myBoard(move.pos2.myX, move.pos2.myY) == -1) {
        return false;
    }
    Position curPos = move.pos2;
    bool accepted = false;

    move.figureId = figure.id;

    if ((movetype & MOVE) && myBoard(move.pos2.myX, move.pos2.myY) == 0 && (moveRule.moveType & MOVE)) {
        accepted = checkMove(moveRule, figure, move);
    } else if ((movetype & CAPTURE) && myBoard(curPos.myX, curPos.myY) > 0 && (moveRule.moveType & CAPTURE)) {
        accepted = checkCapture(moveRule, figure, move);
    } else if ((movetype & CAPTURE) && myBoard(curPos.myX, curPos.myY) == 0 && (moveRule.moveType == INPASSING)) {
        accepted = checkInpassing(moveRule, figure, move);
    }
    if (accepted == true && needCheck == true) {
        accepted = !checkIfCheck(moveRule, figure, move);
    }

    return accepted;
}