int AI::checkBlock(const int& x, const int& y) { std::vector<int> tab; int ret = 0; tab.push_back(checkWinDiagonalOne(y, x, invertTeam(_initTeam))); tab.push_back(checkWinDiagonalTwo(y, x, invertTeam(_initTeam))); tab.push_back(checkWinHorizontal(y, x, invertTeam(_initTeam))); tab.push_back(checkWinVertical(y, x, invertTeam(_initTeam))); for (std::vector<int>::iterator it = tab.begin(); it != tab.end(); ++it) { if ((*it) < 0 && (*it) >= -5) ret += ((*it) * -1) * 200; else if ((*it) < -5 && (*it) >= -10) ret += ((*it) * -1) * 200; } return ret; }
// Function checks if the passed (r, c) position created a win situation // for the player represented by the passed piece. This function calls // the private functions to check for a win horizontally, vertically, // and diagonally. // Parameters: int r: the value that represents the row // of the last move // int c: the value that represents the // column of the last move // piece p: the player to check for a win // Returns: true if the passed move created a win // situation for the player represented // by piece p; returns false if position // is invalid or if a win is checked for // an empty piece bool Board::checkWin(int r, int c, piece p) const { if (p == EMPTY) { std::cout << "Board::checkWin: Error, cannot check win for empty piece." << std::endl; return false; } if (r > -1 && r < rows && c > -1 && c < columns) { return checkWinHorizontal(r, c, p) || checkWinVertical(r, c, p) || checkWinPosDiag(r, c, p) || checkWinNegDiag(r, c, p); } std::cout << "Board::CheckWin: Error, invalid board location." << std::endl; return false; }
int AI::howManyCoin(const int& x, const int& y) { std::vector<int> tab; t_flag teams; int ret; if (_mapRule[y][x] == _initTeam) teams = _initTeam; else teams = invertTeam(_initTeam); tab.push_back(checkWinDiagonalOne(y, x, teams)); tab.push_back(checkWinDiagonalTwo(y, x, teams)); tab.push_back(checkWinHorizontal(y, x, teams)); tab.push_back(checkWinVertical(y, x, teams)); ret = verifAlign(tab); ret = ret * 100; return ret; }