Negamax算法

时间:2014-12-20 11:04:07

标签: c++

我用tictactoe工作了很多,但从来没有工作过。以下是我到目前为止的情况:

static int evaluate(board b)
{


if (is_win curr_move_noughts)
{
    return 1;
}
else if (is_win crosses)
{
    return -1;
}
else
{
    return 0;
}
}


int evaluateNegamax(board b)

{
    if (curr_move_noughts)                                     // Max player
        return evaluate(b);
    else
        return -evaluate(b);
}


tuple<int, move> Search(int depth, board b)
{
  board combined(); =b;
  int w = 0;
  w = Evaluate(b);
  int move;
  int bestScore = std::numeric_limits<int>::min(); 
  bool bestMove = false;
  if(depth == 0) return w;
  int x=0, int y=0;
  for (int x = 0; x < 9; ++x) {
  for (int y = 0; y < 9; ++y) {
    while (!occupied(x,y));
    make_move(x, y);              
    score = -Search(depth-1,b);       // recursion 
    unMake(b);
    if(score > bestScore) {         
      bestScore = score;
      bestMove = move;
    }
   }
  }

   // return the best move
   return make_tuple(bestScore, bestMove);
}

嗯,显然“移动”需要与XY坐标相关联,但我不知道如何。

我已经定义了make_move:

void make_move( size_t row, size_t col, board & b )
{
    if (free(row, col))
    {
    b[pos(row, col)] = true;
        last_move_row = row ;
        last_move_col = col ;
    } 
}

0 个答案:

没有答案