Ejemplo n.º 1
0
def solve():
    selected_level = levels_menu()
    algorithm, heuristic = algorithms_menu()

    board_matrix, max_touches = utils.read_level_file(selected_level)
    board = Board(board_matrix)

    game_state = GameState(board, max_touches)

    print_header(game_state)
    utils.print_board(game_state.board)

    start_time = time.time()
    solution = algorithm.execute(game_state, heuristic)
    end_time = time.time()
    total_time = round(end_time - start_time, 2)

    for move in solution:
        move_row, move_col = move
        game_state.update_board(move_row, move_col)
        print("Move: [", move_row, ",", move_col, "]")
        print_header(game_state)
        utils.print_board(game_state.board)

    if game_state.result == GameResults.Win:
        print("**** You Won! ****")
    else:
        print("**** You Lost! ****")

    print("\nSolved in ", total_time, " seconds", sep="")
    print()
Ejemplo n.º 2
0
    def test_update_board_no_changes(self):
        curr_board = Board([[1, 0, 2, 0], [0, 0, 1, 1], [1, 1, 2, 2],
                            [0, 1, 0, 1]])
        game_state = GameState(curr_board, 1)
        game_state.update_board(0, 1)

        assert game_state.board == curr_board
        assert game_state.result == None
Ejemplo n.º 3
0
    def test_update_board_multiple_red_bubbles(self):
        empty_board = Board()
        curr_board = Board([[1, 0, 1, 0, 1], [0, 0, 0, 0, 0], [1, 0, 1, 0, 1],
                            [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [1, 0, 1, 0, 1]])

        game_state = GameState(curr_board, 1)
        game_state.update_board(0, 0)

        assert game_state.board == empty_board
        assert game_state.result == GameResults.Win
Ejemplo n.º 4
0
    def test_update_board_single_red_bubble(self):
        empty_board = Board()
        curr_board = Board([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 1, 0, 0],
                            [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])

        game_state = GameState(curr_board, 1)
        game_state.update_board(2, 2)

        assert game_state.board == empty_board
        assert game_state.result == GameResults.Win
Ejemplo n.º 5
0
    def test_update_board_level_18(self):
        expected_board = Board()

        curr_board = Board([[0, 3, 2, 4, 0], [1, 1, 1, 2, 0], [0, 1, 4, 1, 2],
                            [0, 4, 2, 0, 1], [1, 1, 1, 2, 2], [0, 4, 0, 1, 1]])

        game_state = GameState(curr_board, 1)
        game_state.update_board(4, 2)

        assert game_state.board == expected_board
        assert game_state.result == GameResults.Win
Ejemplo n.º 6
0
    def test_update_board_level_16(self):
        expected_board = Board([[1, 1, 1, 0, 0], [0, 0, 0, 0, 0],
                                [0, 0, 0, 0, 0], [0, 0, 0, 0, 0],
                                [0, 0, 0, 0, 0], [1, 0, 0, 0, 0]])

        curr_board = Board([[2, 4, 4, 1, 1], [2, 2, 2, 0, 4], [0, 4, 2, 2, 2],
                            [1, 1, 1, 3, 1], [1, 4, 0, 1, 4], [4, 0, 3, 2, 0]])

        game_state = GameState(curr_board, 1)
        game_state.update_board(3, 2)

        assert game_state.board == expected_board
        assert game_state.result == GameResults.Lose
Ejemplo n.º 7
0
    def test_update_board_red_green_bubbles(self):
        expected_board = Board([[0, 0, 0, 0, 0], [0, 1, 0, 1, 0],
                                [1, 1, 0, 1, 1], [0, 2, 0, 2, 0],
                                [0, 1, 0, 1, 0], [0, 0, 0, 0, 0]])

        # level 7
        curr_board = Board([[0, 0, 0, 0, 0], [0, 1, 0, 1, 0], [1, 2, 1, 2, 1],
                            [0, 2, 0, 2, 0], [0, 1, 0, 1, 0], [0, 0, 0, 0, 0]])

        game_state = GameState(curr_board, 2)
        game_state.update_board(2, 2)

        assert game_state.board == expected_board
        assert game_state.result == None
Ejemplo n.º 8
0
    def test_update_board_level_17(self):
        expected_board = Board([[0, 4, 3, 2, 2], [1, 2, 2, 2, 1],
                                [1, 2, 1, 1, 2], [0, 2, 0, 0, 1],
                                [3, 2, 0, 1, 0], [2, 4, 1, 2, 0]])

        curr_board = Board([[0, 4, 3, 2, 2], [1, 2, 2, 2, 1], [1, 2, 2, 2, 2],
                            [0, 3, 1, 1, 3], [3, 2, 0, 2, 0], [2, 4, 2, 2, 0]])

        game_state = GameState(curr_board, 2)
        game_state.update_board(3, 3)

        assert game_state.board == expected_board
        assert game_state.result == None

        expected_board = Board()
        game_state.update_board(4, 3)

        assert game_state.board == expected_board
        assert game_state.result == GameResults.Win