Help with minimax in OSO game

0

I have a problem, I am developing the AI paper game AI OSO, it turns out that minimax is designed for players in turns in which whatever the player's move the next turn will correspond to the next, so in the game of BEAR this is not fulfilled because if you get a point you follow with the turn, the pseudo code that I am using is the following:

a = alpha , b = beta , d = deph , baoard = board , t = turn 
pg1 = player1 points , pg2 = player2 points.

int alphaBeta(a,b,d,board,t,p1g,p2g)
{
  if board is end , or d == 0  then :
    return eval of board.

  mvs <- generate all movements.
  mvs <- sort mvs (heruristc sort)

  for mv in mvs :
    board <- do mv.

    if optain point then :
      if t == 1 then : // if turn is of player 1
        value <- alphaBeta(a,b,d-1,board,t,pg1+1,pg2) // maximize
      else then : // turn is of player 2
        value <- alphaBeta(a,b,d-1,board,t,pg1,pg2+1) // maximize

    else then :
       value <-  -alphaBeta(a,b,d-1,board,changeTurn(t),pg1,pg2) //minimize

    board <- undo mv

    if value >= b then :
      return b
    if value > a then :
      a <- value
  endfor

  return a
}

but this code does not work and I do not know why.

Here what you code is in c ++.

/* @brief main function of the AI , based on the algorithm of cut alpha-beta.
* @param a , integer representing the below limit search in alpa-beta  algorithm.
* @param b , integer representing the upper limit search in alpa-beta algorithm.
* @param d , search deph. 
* @param board , the current to apply algorithm.
* @param t , the current player turn , 1 for player1 , -1 for player2.
* @param PG1 , points of player1.
* @param PG2 , points of player2.
* @return integer representing the value of the board.
*/
int alphaBeta(int a ,int b ,int d ,Board& board, int t , int PG1, int PG2)
{
  if(board.statusGame() == GAME_STATUS::END or d == 0)
    return evalBoard(board,PG1,PG2);

  QList<Move> mvs = generateMoves(board);
  int value =0 , maxValue =1000;

  sortMoves(mvs,board);

  for(auto it : mvs)
  {
    board.setState(it);

    if(board.osoWordAround(it.row,it.col))
      if(PG1 == 1)
        value = alphaBeta(a,b,d-1,board,t,PG1+1,PG2);
      else
        value = alphaBeta(a,b,d-1,board,t,PG1,PG2+1);
    else
      value = -alphaBeta(-b,-a,d-1,board,playerToggle(t),PG1,PG2);

    board.unSetState(it);

    if(value >= b)
      return b;

    if(value > a)
      a = value;
  }
  return a;
}

I expect to get a score for a certain position on a board, basically, they give me the board and the scores of the players, I check if the board is a terminal node, or if the search depth is 0, in that case I evaluate the board, otherwise I generate the possible movements and I order them according to an established heuristic to generate more cuts, for each generated movement I do: I make the move, if I get a point that is to say if the word OSO exists around I keep maximizing that is to say I call alphaBeta function with the parameters shown above, I must take into account who owns the turn to increase your score, on the other hand if I do not optengo point should minimize, I call -alphaBeta with the parameters set above, I keep the points and I change the player's turn. the function that evaluates the board is based on the scores of each player, what I hope is that whatever the turn it is to the computer this will generate me the highest possible score, the problem is that when I run it does not generate me the highest possible score, for example if I pass a developed board with certain scores this does not return a better score than the one that has been up until now, although if I run it in cold minimum I should return the score that already has.

    
asked by Andress Hoyo 04.07.2017 в 01:42
source

0 answers