Exemplo n.º 1
0
 def test_diagonal_victory_in_1(self):
     board = Board()
     checker = LogicChecker(board)
     checker.turn = 9
     board.game_board = [[' ', '|', 'X', '|', 'O'],
                         ['--', '+', '--', '+', '--'],
                         ['O', '|', 'X', '|', 'X'],
                         ['--', '+', '--', '+', '--'],
                         ['O', '|', 'O', '|', 'X']]
     assert checker.would_this_be_a_draw('X', [(0,0)]) == False
Exemplo n.º 2
0
 def test_one_remaining_2(self):
     board = Board()
     checker = LogicChecker(board)
     checker.turn = 9
     board.game_board = [['X', '|', 'X', '|', 'O'],
                         ['--', '+', '--', '+', '--'],
                         ['O', '|', ' ', '|', 'X'],
                         ['--', '+', '--', '+', '--'],
                         ['X', '|', 'O', '|', 'O']]
     assert checker.would_this_be_a_draw('X', [(2,2)]) == True
Exemplo n.º 3
0
 def test_two_remaining(self):
     board = Board()
     checker = LogicChecker(board)
     checker.turn = 8
     board.game_board = [['X', '|', 'O', '|', 'X'],
                         ['--', '+', '--', '+', '--'],
                         ['X', '|', 'O', '|', ' '],
                         ['--', '+', '--', '+', '--'],
                         ['O', '|', 'X', '|', ' ']]
     assert checker.would_this_be_a_draw('O', [(4,2), (4,4)]) == True
Exemplo n.º 4
0
 def test_empty_board(self):
     board = Board()
     checker = LogicChecker(board)
     board.game_board = [[' ', '|', ' ', '|', ' '],
                         ['--', '+', '--', '+', '--'],
                         [' ', '|', ' ', '|', ' '],
                         ['--', '+', '--', '+', '--'],
                         [' ', '|', ' ', '|', ' ']]
     assert checker.would_this_be_a_draw('X', [(0,0),(2,0),(4,0),
                                               (0,2),(2,2),(4,2),
                                               (0,4),(2,4),(4,4)]) == False
Exemplo n.º 5
0
    def test_mistake_possible_2(self):
        board = Board()
        checker = LogicChecker(board)
        checker.turn = 8

        board.game_board = [['X', '|', ' ', '|', 'X'],
                            ['--', '+', '--', '+', '--'],
                            ['X', '|', 'X', '|', 'O'],
                            ['--', '+', '--', '+', '--'],
                            ['O', '|', 'O', '|', ' ']]

        checker.board.draw()

        assert checker.would_this_be_a_draw('O', [(2,0), (4,4)]) == False
Exemplo n.º 6
0
    player_choice = in_handler.get_player_choice(current_player)

    if player_choice == 'surrender':
        break
    else:
        board.insert(current_player, *player_choice)

    if logic.is_this_move_a_victory(current_player, *player_choice):
        board.draw()
        print("\n-------------------------------------------------")
        print("\nPlayer", current_player, "has won after",
              math.ceil(logic.turn / 2), "rounds!!\nAll hail the victor!\n")
        print("-------------------------------------------------\n\n")
        break

    if logic.turn >= 7:
        if logic.would_this_be_a_draw(current_player,
                                      board.empty_tile_coordinates()):
            board.draw()
            print("\n-------------------------------------------------")
            print("\nA draw after", math.ceil(logic.turn / 2),
                  "rounds!!\nGood work both!\n")
            print("-------------------------------------------------\n\n\n")
            break

    if current_player == 'X':
        current_player = 'O'
    else:
        current_player = 'X'

    logic.turn += 1