MCPcopy Create free account
hub / github.com/lazyprogrammer/machine_learning_examples / play_game

Function play_game

rl/tic_tac_toe.py:374–405  ·  view source on GitHub ↗
(p1, p2, env, draw=False)

Source from the content-addressed store, hash-verified

372
373
374def play_game(p1, p2, env, draw=False):
375 # loops until the game is over
376 current_player = None
377 while not env.game_over():
378 # alternate between players
379 # p1 always starts first
380 if current_player == p1:
381 current_player = p2
382 else:
383 current_player = p1
384
385 # draw the board before the user who wants to see it makes a move
386 if draw:
387 if draw == 1 and current_player == p1:
388 env.draw_board()
389 if draw == 2 and current_player == p2:
390 env.draw_board()
391
392 # current player makes a move
393 current_player.take_action(env)
394
395 # update state histories
396 state = env.get_state()
397 p1.update_state_history(state)
398 p2.update_state_history(state)
399
400 if draw:
401 env.draw_board()
402
403 # do the value function update
404 p1.update(env)
405 p2.update(env)
406
407
408if __name__ == '__main__':

Callers 1

tic_tac_toe.pyFile · 0.70

Calls 6

draw_boardMethod · 0.80
get_stateMethod · 0.80
game_overMethod · 0.45
take_actionMethod · 0.45
update_state_historyMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected