XOBoard negaMaxThink(XOBoard::Player player, XOBoard board) { /* TODO: Fa o miscare si returneaza tabla dupa aceasta miscare. Aceasta * functie de AI trebuie sa respecte acest format pentru ca este data in * constructorul jocului, dar puteti apela aici o functie scrisa de voi. */ int sol = -10, x, y, alpha = -10, beta =10; for (int i = 0; i < 3; ++ i) for (int j = 0; j < 3; ++ j) if (board.is_empty(i,j)) { board.put(player,i,j); int k = -negaMaxMin(OPPONENT(player), board, -beta, -alpha); std::cerr<<i<<" "<<j<<" "<<k<<std::endl; board.erase(i,j); if (k > alpha) { alpha = k; x = i; y = j; } } /* TODO: Stergeti linia de mai jos dupa ce rezolvati. */ board.put(player, x,y); return board; }
/** Un exemplu de functie de gandire care foloseste rezultatele furnizate de * o abordare negaMax exhaustiva. */ int negaMaxMin(XOBoard::Player player, XOBoard& board, int alpha, int beta) { int sol = -10; if( board.is_full()) { return board.get_score(player)-board.get_score(OPPONENT(player)); } for (int i = 0; i < 3; ++ i) for (int j = 0; j < 3; ++ j) if (board.is_empty(i,j)) { board.put(player,i,j); int k = -negaMaxMin(OPPONENT(player), board, -beta, -alpha); board.erase(i,j); if (k >= beta) return beta; if (k > alpha) alpha = k; } return alpha; }