@@ -136,6 +136,10 @@ def min_value(state, alpha, beta, depth):
136136
137137def query_player (game , state ):
138138 """Make a move by querying standard input."""
139+ print ("current state:" )
140+ game .display (state )
141+ print ("available moves: {}" .format (game .actions (state )))
142+ print ("" )
139143 move_string = input ('Your move? ' )
140144 try :
141145 move = eval (move_string )
@@ -153,18 +157,6 @@ def alphabeta_player(game, state):
153157 return alphabeta_full_search (state , game )
154158
155159
156- def play_game (game , * players ):
157- """Play an n-person, move-alternating game."""
158-
159- state = game .initial
160- while True :
161- for player in players :
162- move = player (game , state )
163- state = game .result (state , move )
164- if game .terminal_test (state ):
165- game .display (state )
166- return game .utility (state , game .to_move (game .initial ))
167-
168160# ______________________________________________________________________________
169161# Some Sample Games
170162
@@ -204,6 +196,17 @@ def display(self, state):
204196
205197 def __repr__ (self ):
206198 return '<{}>' .format (self .__class__ .__name__ )
199+
200+ def play_game (self , * players ):
201+ """Play an n-person, move-alternating game."""
202+ state = self .initial
203+ while True :
204+ for player in players :
205+ move = player (self , state )
206+ state = self .result (state , move )
207+ if self .terminal_test (state ):
208+ self .display (state )
209+ return self .utility (state , self .to_move (self .initial ))
207210
208211
209212class Fig52Game (Game ):
@@ -255,7 +258,9 @@ def actions(self, state):
255258
256259 def result (self , state , move ):
257260 if move not in state .moves :
258- return state # Illegal move has no effect
261+ return GameState (to_move = ('O' if state .to_move == 'X' else 'X' ),
262+ utility = self .compute_utility (state .board , move , state .to_move ),
263+ board = state .board , moves = state .moves ) # Illegal move has no effect
259264 board = state .board .copy ()
260265 board [move ] = state .to_move
261266 moves = list (state .moves )
0 commit comments