Exemplo n.º 1
0
    def test_solve_board(self):
        columns, rows = read_example('w')

        board = BlackBoard(columns, rows)

        propagation.solve(board, methods='simpson')
        assert board.is_solved_full
Exemplo n.º 2
0
    def test_smile(self):
        columns, rows = read_example('smile.txt')
        board = BlackBoard(columns, rows)

        propagation.solve(board)
        assert is_close(board.solution_rate, 0.6)
        # assert is_close(board.solution_rate, 407.0 / 625)

        Solver(board).solve()
        assert board.is_solved_full
Exemplo n.º 3
0
    def get_board(cls, _id, create_mode, **renderer_params):
        """Generates a board using given ID and mode"""
        if create_mode == 'local':
            board_def = read_example(_id)
        elif create_mode == 'pbn':
            board_def = Pbn.read(_id)
        elif create_mode == 'nonograms.org':
            board_def = NonogramsOrg.read(_id)
        else:
            raise tornado.web.HTTPError(400, 'Bad mode: %s', create_mode)

        return make_board(*board_def, **renderer_params)
Exemplo n.º 4
0
def main():
    """Main function for setuptools console_scripts"""
    args = cli_args()
    if args.version:
        print(__version__)
        return

    if args.show_examples_folder:
        print(example_file())
        return

    is_windows = platform.system() == 'Windows'
    is_pypy2 = PY2 and platform.python_implementation() == 'PyPy'
    is_curses = args.curses

    if is_curses and is_windows:
        exit('Curses do not supported on Windows')

    _setup_logs(log_level(args.verbose))

    if args.pbn:
        board_def = Pbn.read(args.pbn)
    elif args.local_pbn:
        board_def = PbnLocal.read(args.local_pbn)
    elif args.nonograms_org:
        board_def = NonogramsOrg.read(args.nonograms_org)
    else:
        board_def = read_example(args.board)

    # the Windows does not support Unicode, so does the curses on PyPy2
    if (is_curses and is_pypy2) or is_windows:
        box_symbol = '#'
    else:
        box_symbol = '\u2B1B'

    draw_solution(board_def,
                  box_symbol=box_symbol,
                  draw_final=args.draw_final,
                  draw_probes=args.draw_probes,
                  curses_animation=is_curses,
                  max_solutions=args.max_solutions,
                  timeout=args.timeout,
                  max_depth=args.max_depth)
Exemplo n.º 5
0
    def test_hello(self):
        columns, rows = read_example('hello.txt')

        stream = StringIO()
        board = BlackBoard(columns,
                           rows,
                           renderer=BaseAsciiRenderer,
                           stream=stream)
        propagation.solve(board)
        board.draw()

        assert stream.getvalue().rstrip() == '\n'.join([
            '# # # # # # # # #               1 1                          ',
            '# # # # # # # # #               1 1               1   1     5',
            '# # # # # # # # # 7 1 1 1 7 0 3 1 1 2 0 6 0 6 0 3 1 5 1 3 0 1',
            '            1 1 1 X . . . X . . . . . . . . . . . . . . . . X',
            '        1 1 1 1 1 X . . . X . . . . . . X . X . . . . . . . X',
            '    1 1 2 1 1 3 1 X . . . X . . X X . . X . X . . X X X . . X',
            '5 1 1 1 1 1 1 1 1 X X X X X . X . . X . X . X . X . X . X . X',
            '1 1 4 1 1 1 1 1 1 X . . . X . X X X X . X . X . X . X . X . X',
            '  1 1 1 1 1 1 1 1 X . . . X . X . . . . X . X . X . X . X . .',
            '    1 1 2 1 1 3 1 X . . . X . . X X . . X . X . . X X X . . X',
        ])
        assert board.is_solved_full
Exemplo n.º 6
0
 def board(self):
     board_def = read_example('uk')
     return make_board(*board_def)
Exemplo n.º 7
0
    def test_txt_suffix(self):
        columns1, rows1 = read_example('w.txt')
        columns2, rows2 = read_example('w')

        assert columns1 == columns2
        assert rows1 == rows2