master
Leo TUAILLON 2 years ago
parent bba3d1a72d
commit a7159cf104

@ -155,7 +155,6 @@ class AI:
else: else:
#minimax algo choice #minimax algo choice
print("AI is thinking...") print("AI is thinking...")
time.sleep(1)
eval, move = self.minimax(main_matrix, False) eval, move = self.minimax(main_matrix, False)
print(f"AI has chosen the pos {move} with an eval of {eval}") print(f"AI has chosen the pos {move} with an eval of {eval}")

@ -63,8 +63,10 @@ class AI {
minimax(matrix, depth, maximizingPlayer) { minimax(matrix, depth, maximizingPlayer) {
const winner = this.check_winner(matrix); const winner = this.check_winner(matrix);
if (winner !== 0) { if (winner === this.player) {
return winner === this.player ? 10 - depth : depth - 10; return 1;
} else if (winner === 3 - this.player) {
return -1;
} }
if (matrix.is_full()) { if (matrix.is_full()) {
@ -96,6 +98,7 @@ class AI {
return bestScore; return bestScore;
} }
check_winner(matrix) { check_winner(matrix) {
for (let player = 1; player <= 2; player++) { for (let player = 1; player <= 2; player++) {
if (matrix.check_win(player)) { if (matrix.check_win(player)) {

Loading…
Cancel
Save