123456789101112131415161718192021222324252627282930313233343536
#define NOUGHTS 1 #define CROSSES -1 int negamax( board b, unsigned int depth, unsigned int side) { side==NOUGHTS ? 1: -1; if (depth==0) { int score=eval(b); return side * score; } int bestScore = -1000; for (int x = 0; x < 9; ++x) { for (int y = 0; y < 9; ++y) { while (!occupied(x,y)); make_move(x,y); int val = -negamax(b, depth -1, -side); unMake(b); bestScore = std::max(bestScore, val); } } return bestScore; }
12345678
if ( side == NOUGHTS ) { 1; } else { -1; }
side = b->turn ? 1 : -1;
b->turn