예제 #1
0
def game_loop():
    """No return. Primary game loop."""
    global game_running
    game_running = True
    model.clear_board()
    start_player = random.choice(("You", "The computer"))
    print("{} will go first.".format(start_player))
    player_turn = True if start_player == "You" else False
    strategy.computer_flag = model.O if start_player == "You" else model.X
    strategy.player_flag = model.X if start_player == "You" else model.O
    while game_running:
        print(
            """[{0}][{1}][{2}]
[{3}][{4}][{5}]
[{6}][{7}][{8}]""".format(
                *current_board()
            )
        )
        if " " not in current_board():
            print("Draw game.")
            break
        if player_turn:
            game_control()
            if model.did_player_win(strategy.player_flag):
                print("You won.")
                game_quit()
            else:
                player_turn = not player_turn
        else:
            model.update_square(strategy.computer_flag, strategy.pick_move())
            if model.did_player_win(strategy.computer_flag):
                print("The computer won.")
                game_quit()
            else:
                player_turn = not player_turn
        clear()
예제 #2
0
 def setUp(self):
     model.clear_board()
     model.update_square(model.X, (0, 0))
     model.update_square(model.O, (1, 1))
     model.update_square(model.X, (2, 2))
예제 #3
0
 def test_clear_board(self):
     model.clear_board()
     board_as_list = [square for row in model.board for square in row]
     self.assertEquals(board_as_list, [None, None, None, None, None, None, None, None, None])
예제 #4
0
 def setUp(self):
     model.clear_board()