Exemple #1
0
                   ]
"""
# NOTE: This example is used for the mock solution from 'main.py' only.

# Uncomment the following line to generate a random target shape
target, perfect_solution = utils.generate_target(width=100, height=100, density=0.7, forbidden_pieces=the_forbidden_pieces) # NOTE: it is recommended to keep density below 0.8
solution = Tetris(deepcopy(target))
#solution = perfect_solution
valid, missing, excess, error_pieces = utils.check_solution(target, solution, the_forbidden_pieces)  # checks if the solution is valid

if not valid or len(error_pieces)!=0:
    if len(error_pieces) != 0:
        print('WARNING: {} pieces have a wrong shapeID. They are labelled in image of the solution, and their PieceID are: {}.'
                  .format(len(error_pieces), error_pieces))
        print("Displaying solution...")
        utils.visual_perfect(perfect_solution, solution, the_forbidden_pieces)
    print("WARNING: The solution is not valid, no score will be given!")

else:  # if the solution is valid, test time performance and accuracy

    # TIME PERFORMANCE
    # There will be three different 'target' with increasing complexity in real test.

    time_set = timeit.timeit('Tetris({})'.format(target), 'from main import Tetris', number=1)
    
    if time_set > 600:

        print("WARNING: Time is over 10 minutes! The solution is not valid")

    else:
Exemple #2
0
target, limit_tetris, perfect_solution = utils.generate_target(
    width=20, height=20,
    density=0.8)  # NOTE: it is recommended to keep density below 0.8

solution = Tetris(deepcopy(target), deepcopy(limit_tetris))

valid, missing, excess, error_pieces, use_diff = utils.check_solution(
    target, solution, limit_tetris)  # checks if the solution is valid

if not valid or len(error_pieces) != 0:
    if len(error_pieces) != 0:
        print(
            'WARNING: {} pieces have a wrong shapeID. They are labelled in image of the solution, and their PieceID are: {}.'
            .format(len(error_pieces), error_pieces))
        print("Displaying solution...")
        utils.visual_perfect(perfect_solution, solution)
    print("WARNING: The solution is not valid, no score will be given!")

else:  # if the solution is valid, test time performance and accuracy

    # TIME PERFORMANCE
    # There will be three different 'target' with increasing complexity in real test.

    time_set = timeit.timeit('Tetris({},{})'.format(target, limit_tetris),
                             'from main import Tetris',
                             number=1)

    if time_set > 600:

        print("WARNING: Time is over 10 minutes! The solution is not valid")