Exemplo n.º 1
0
def main():
    cube = Cube()
    print '=========== initial ============'
    cube.show()
    print cube.calculate_feature_string()
    print cube.check()
    print ''
    command = raw_input("Command: ").upper()
    while command != 'Q':
        if command not in command_map:
            print("Invalid input. Input again.")
            continue
        cube.transform(command_map[command])
        print '=========== %s ============' % command
        print ''
        cube.show()
        print ''
        command = raw_input("Command: ").upper()
Exemplo n.º 2
0
def test_transform():
    result_file = 'tmp_result.txt'
    benchmark_file = 'ut_result.txt'
    cube = Cube()
    with open(result_file, 'w') as result_fp:
        cube.show(result_fp)
        for command in command_list:
            for i in range(0, 4):
                result_fp.write('=========== %s ============\n' % command)
                cube.transform(command_list[command])
                cube.show(result_fp)

    benchmark = open(result_file, 'U').readlines()
    result = open(benchmark_file, 'U').readlines()

    diff = unified_diff(benchmark, result, benchmark_file, result_file)

    print 'Diff between benchmark and result.\n'
    stdout.writelines(diff)
    print '\nTest transform done.'
Exemplo n.º 3
0
def test_shuffle():
    cube = Cube()
    game = Game(cube)
    game.shuffle()
    step = len(game.shuffle_full_steps)
    print '=========== initialized with %s-step shuffle ============' % step
    cube.show()
    print ''
    print 'Feature string is ', cube.calculate_feature_string()
    print 'Is standard? ', cube.check()
    command = raw_input("Command: ").upper()
    while command != 'Q':
        if command not in command_map:
            print("Invalid input. Input again.")
            continue
        cube.transform(command_map[command])
        print '=========== %s ============' % command
        print ''
        cube.show()
        print ''
        command = raw_input("Command: ").upper()
Exemplo n.º 4
0
def test_train_and_solve():
    cube = Cube()
    game = Game(cube)
    game.shuffle()
    step = len(game.shuffle_full_steps)
    print '=========== initialized with %s-step shuffle ============' % step
    cube.show()
    print 'Solving . . . . . . '
    game.solve()
    cube.show()
    if game.is_solved:
        print 'Congratulations!!!! Solved after %s steps!' % len(
            game.solve_steps)
        print(
            'Steps: %s' % ''.join([
                DIRECTIONS[step.direction + DIRECTION_OFFSET]
                for step in game.solve_steps
            ]))
    else:
        print 'Stupid!!!! Cannot solve a cube in %s steps!' % len(
            game.solve_steps)