Exemplo n.º 1
0
def test_is_complete():
    board = [[7, 8, 5, 9, 1, 6, 4, 2, 3], [1, 3, 4, 5, 7, 2, 9, 8, 6],
             [6, 9, 2, 8, 4, 3, 7, 5, 1], [8, 5, 7, 3, 6, 1, 2, 4, 9],
             [9, 4, 6, 2, 8, 7, 1, 3, 5], [3, 2, 1, 4, 5, 9, 8, 6, 7],
             [2, 6, 9, 1, 3, 4, 5, 7, 8], [5, 1, 3, 7, 2, 8, 6, 9, 4],
             [4, 7, 8, 6, 9, 5, 3, 1, 2]]
    assert is_complete(board) == True, "is_complete test #1 failed"

    board = [[4, 6, 3, 8, 9, 5, 1, 7, 2], [2, 1, 9, 7, 4, 6, 5, 8, 3],
             [7, 8, 5, 2, 3, 1, 9, 6, 4], [6, 2, 4, 3, 5, 8, 7, 1, 9],
             [3, 5, 7, 6, 0, 9, 4, 2, 8], [8, 9, 1, 4, 2, 7, 3, 5, 6],
             [9, 7, 2, 5, 6, 3, 8, 4, 1], [1, 4, 8, 9, 7, 2, 6, 3, 5],
             [5, 3, 6, 1, 8, 4, 2, 9, 7]]
    assert is_complete(board) == False, "is_complete test #2 failed"

    board = [[4, 3, 0, 1, 0, 0, 0, 0, 0], [0, 6, 0, 0, 0, 0, 0, 0, 0],
             [9, 0, 0, 0, 8, 0, 0, 2, 0], [3, 0, 0, 0, 0, 7, 5, 8, 1],
             [0, 0, 0, 5, 0, 4, 0, 0, 0], [6, 5, 7, 8, 0, 0, 0, 0, 4],
             [0, 9, 0, 0, 6, 0, 0, 0, 3], [0, 0, 0, 0, 0, 0, 0, 1, 0],
             [0, 0, 0, 0, 0, 2, 0, 7, 5]]
    assert is_complete(board) == False, "is_complete test #3 failed"
Exemplo n.º 2
0
        break

    # validate cell contents
    if type(event) == tuple:
        cell_contents = values[event]
        if (len(cell_contents) > 1 or len(cell_contents) == 1
                and cell_contents not in "0123456789"):
            window[event].update(cell_contents[:-1])

    if event == "Clear":
        clear_display(window)

    if event == "Solve":
        puzzle = convert(values.values())
        puzzle = chunk(puzzle)
        solution = solve_puzzle(puzzle)
        # Hard puzzles need another approach
        if not is_complete(solution):
            backtrack(solution)
        display(window, solution)

    if event == "Store":
        puzzle = convert(values.values())
        puzzle = chunk(puzzle)
        save(puzzle)

    if event == "Restore":
        load_puzzle()

window.close()
Exemplo n.º 3
0
def test_game_1():
    board = numpy.loadtxt('games/001.txt')
    play_game(board)
    assert is_complete(board)
Exemplo n.º 4
0
             if event.key == pygame.K_2:
                 key = 2
             if event.key == pygame.K_3:
                 key = 3
             if event.key == pygame.K_4:
                 key = 4
             if event.key == pygame.K_5:
                 key = 5
             if event.key == pygame.K_6:
                 key = 6
             if event.key == pygame.K_7:
                 key = 7
             if event.key == pygame.K_8:
                 key = 8
             if event.key == pygame.K_9:
                 key = 9
             if key != 0:
                 game_board.set_temp(key)
                 key = 0
             if event.key == pygame.K_BACKSPACE:
                 game_board.set_temp(0)
             if event.key == pygame.K_RETURN:
                 score += game_board.set_val()
                 if is_complete(game_board.board_array):
                     finish_time = time.time() - start_time
                     win = True
                     running = False
     draw_window(window, game_board, score, current_time)
 if win:
     formatted_finish_time = str(int(finish_time//60)) + ":" + "{:0>2d}".format(int(finish_time%60))
     print('Game Completed in ' + formatted_finish_time + '! Score: ' + str(score) + '.')