示例#1
0
 private Boards CopyAndMove(Boards boards, Move move)
 {
     Boards newBoards = new Boards(boards);
     newBoards.SetTile_Small(move);
     if (newBoards.GetWinner(move.board) != Game.EMPTY)
         newBoards.SetTile_Big(move.board);
     newBoards.lastmove = newBoards.GetWinner(move.tile)
         == Game.EMPTY ? move.tile : -1;
     newBoards.FillMoves();
     return newBoards;
 }
示例#2
0
 private int NegaMax(Boards boards, int depth, int alpha, int beta)
 {
     int bigBoardRating = boards.GetWinner(9);
     if (bigBoardRating == Game.DRAW)
         return 0;
     if (bigBoardRating == Game.X)
         return 100000 * (boards.turn ? -1 : 1);
     if (bigBoardRating == Game.O)
         return -100000 * (boards.turn ? -1 : 1);
     if (depth == 0)
         return Eval(boards) * (boards.turn ? -1 : 1);
     int best = -1000000;
     foreach (Move m in boards.moves)
     {
         int score = -NegaMax(CopyAndMove(boards, m),
                             depth - 1, -beta, -alpha);
         if (score > best)
             best = score;
         if (best > alpha)
             alpha = best;
         if (alpha >= beta)
             return alpha;
     }
     return best;
 }