Esempio n. 1
0
int Game::maxMove(int depth, int alpha, int beta) {
	
	std::vector<int> allMoves = getAvailableMoves();
	int winner = checkWinner();	
	
	if ((allMoves.size() <= 0 || winner > 0) || depth <= 0) {
		return evaluateState(1, winner);
	}
	
	int* bestMove = NULL;
	int bestScore = INT_MIN;
	
	for (std::vector<int>::const_iterator it = allMoves.begin(); it != allMoves.end(); it++) {
		setCell(*it, 1);
		int score = minMove(depth - 1, alpha, beta);
		std::cout<< "score at " << *it;
		undoMove(*it);
		if (score > bestScore) {
			bestScore = score;
			alpha = score;
		}
		if (beta > alpha) {
			return bestScore;
		}
	}
	
	
}
Esempio n. 2
0
Move Sudoku::findMove()
{
  Move minMove(0,0,0);
  int minCand=9;
  for(int ii = 0;ii<bsize; ii++){
    for(int jj = 0;jj<bsize;jj++){
      if(board[ii][jj] != 0){
        continue;
      }
      int nCand = 0;
      int firstNum = 0;
      for(int kk = 1; kk<=bsize; kk++){
        if(cand[ii][jj][kk]){
          if(firstNum == 0){
            firstNum = kk;
          }
          nCand ++;
        }
      }
      if(minCand>nCand){
        minCand = nCand;
        minMove = Move(ii, jj, firstNum);
      }
    }
  }
  return minMove;
}
Esempio n. 3
0
int AI::maxValue(vector<vector<int>> tempBoard, vector<Piece> teamCopy, vector<Piece> enemyTeamCopy, int depth, Directions direction){

    bool killMove = false;

    if(!checkNode(tempBoard, teamCopy, enemyTeamCopy, direction, false)){
        return OUT_OF_BOUND;
    }
    int x = teamCopy[currentIndex].x;
    int y = teamCopy[currentIndex].y;

    changeWithDirection(x, y, direction, false);
    if(sameTeam(tempBoard[x][y],ENEMY_TEAM_NUMBER)){
        if(!killCheckArea(tempBoard, x, y, direction, false)){
            return OUT_OF_BOUND;
        }
        else{
            changeWithDirection(x, y, direction, false);
            killMove = true;
        }
    }

    //This should move on the tempBoard
    movePiece(tempBoard, teamCopy, currentIndex, x, y);
    updateKings(tempBoard, teamCopy, false);
    if (killMove) {
        updateTeam(tempBoard, enemyTeamCopy, true);
        if (enemyTeamCopy.size()<=0) {
            return WIN_VALUE;
        }
    }

    if (depth <= 0) {
        return valueCalculator(teamCopy, enemyTeamCopy);
    }
    else{
        return minMove(tempBoard, teamCopy, enemyTeamCopy, depth-1);
    }

}