Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 476f5bf

Browse files
committed
Fixed issue 22 and issue 24.
1 parent c5e6a95 commit 476f5bf

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

games.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,9 @@ def make_move(self, move, state):
242242
utility=self.compute_utility(board, move, state.to_move),
243243
board=board, moves=moves)
244244

245-
def utility(self, state):
246-
"Return the value to X; 1 for win, -1 for loss, 0 otherwise."
247-
return state.utility
245+
def utility(self, state, player):
246+
"Return the value to player; 1 for win, -1 for loss, 0 otherwise."
247+
return if_(player == 'X', state.utility, -state.utility)
248248

249249
def terminal_test(self, state):
250250
"A state is terminal if it is won or there are no empty squares."
@@ -296,4 +296,6 @@ def legal_moves(self, state):
296296
__doc__ += random_tests("""
297297
>>> play_game(Fig62Game(), random_player, random_player)
298298
6
299+
>>> play_game(TicTacToe(), random_player, random_player)
300+
0
299301
""")

0 commit comments

Comments
 (0)