(p1, p2, env, draw=False)
| 372 | |
| 373 | |
| 374 | def 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 | |
| 408 | if __name__ == '__main__': |
no test coverage detected