This commit is contained in:
2025-03-28 13:13:52 +01:00
parent 16ba19f39f
commit 91235615c9

View File

@@ -90,7 +90,7 @@ class TicTacToe(Game):
def result(self, board, step, player):
if (self.check_triplets(board, step, player, (0,1)) or self.check_triplets(board, step, player, (1,0)) or
self.check_triplets(board, step, player, (1,1)) or self.check_triplets(board, step, player, (-1,1))):
self.check_triplets(board, step, player, (1,1)) or self.check_triplets(board, step, player, (1,-1))):
if player == 'X':
return 1
else:
@@ -99,15 +99,15 @@ class TicTacToe(Game):
def check_triplets(self, board, step, player, direction):
n = -1
dy, dx = direction
dx, dy = direction
x,y = step
while board.get(x,y) == player:
while board.get((x,y)) == player:
x,y = dx + x,dy + y
n += 1
x,y = step
while board.get(x,y) == player:
while board.get((x,y)) == player:
x,y = x - dx,y - dy
n += 1
@@ -157,10 +157,10 @@ play_game(tto, random_player, random_player)
# Demonstrate the power of the search algorithms
# you can comment out the game.print(state) lines in the play_game function for this
for i in range(1):
print(play_game(tto, random_player, random_player)) # outcome will be random (starting player has the edge)
print(play_game(tto, alfabeta_player, random_player)) # X will always win
for i in range(0):
#print(play_game(tto, random_player, random_player)) # outcome will be random (starting player has the edge)
#print(play_game(tto, alfabeta_player, random_player)) # X will always win
print(play_game(tto, minimax_player, alfabeta_player)) # O will most likely win
print(play_game(tto, alfabeta_player, alfabeta_player)) # game will always end in draw
print(play_game(tto, alfabeta_player, minimax_player))
#print(play_game(tto, alfabeta_player, alfabeta_player)) # game will always end in draw
#print(play_game(tto, alfabeta_player, minimax_player))