コード例 #1
0
def _main():
    if len(sys.argv) == 1:
        # generated example: https://twitter.com/semiexp/status/1223794016593956864
        height, width = 10, 10
        problem = [[None for _ in range(width)] for _ in range(height)]
        problem[1][2] = 3
        problem[2][7] = 2
        problem[2][9] = 0
        problem[3][0] = 1
        problem[3][3] = 3
        problem[4][6] = 3
        problem[5][0] = 2
        problem[5][3] = 2
        problem[6][8] = 2
        problem[9][3] = 2
        problem[9][7] = 0

        is_sat, ans = solve_shakashaka(height, width, problem)
        print('has answer:', is_sat)
        if is_sat:
            print(util.stringify_array(ans, str))
    else:
        height, width = map(int, sys.argv[1:])
        while True:
            problem = generate_shakashaka(height, width, verbose=True)
            if problem is not None:
                print(util.stringify_array(problem, {
                    None: '.',
                    -1: '#',
                    0: '0',
                    1: '1',
                    2: '2',
                    3: '3',
                    4: '4'
                }))
コード例 #2
0
def _main():
    if len(sys.argv) == 1:
        # generated example: https://twitter.com/semiexp/status/1225770511080144896
        height = 10
        width = 10
        problem = [
            [-2, -2,  2, -2, -2, -2, -2, -2, -2, -2],
            [-2, -2, -2, -2, -2, -2, -2, -2,  2, -2],
            [-2, -2, -2, -2, -2, -2, -2, -1, -2, -2],
            [-1, -2, -2, -2,  3, -2, -2, -2, -2, -2],
            [-2, -2, -2, -2, -2, -1, -2, -2, -2, -1],
            [ 2, -2, -2, -2,  2, -2, -2, -2, -2, -2],
            [-2, -2, -2, -2, -2,  3, -2, -2, -2, -1],
            [-2, -2, -1, -2, -2, -2, -2, -2, -2, -2],
            [-2,  2, -2, -2, -2, -2, -2, -2, -2, -2],
            [-2, -2, -2, -2, -2, -2, -2, -1, -2, -2],
        ]
        is_sat, has_light = solve_akari(height, width, problem)
        print('has answer:', is_sat)
        if is_sat:
            print(util.stringify_array(has_light, {
                True: 'O',
                False: '.',
                None: '?'
            }))
    else:
        height, width = map(int, sys.argv[1:])
        while True:
            problem = generate_akari(height, width, verbose=True)
            if problem is not None:
                print(util.stringify_array(problem, {
                    -2: '.', -1: '#', 0: '0', 1: '1', 2: '2', 3: '3', 4: '4'
                }))
                print('', flush=True)
コード例 #3
0
ファイル: nurikabe.py プロジェクト: bay-puz/cspuz
def main():
    if len(sys.argv) == 1:
        # https://twitter.com/semiexp/status/1222541993638678530
        height = 10
        width = 10
        problem = [
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 7, 0, 0, 0, 0, 0],
            [0, 0, 0, 7, 0, 0, 0, 0, 9, 0],
            [0, 0, 0, 0, 0, 0, 0, 7, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 7, 0, 0, 0, 7, 0, 0, 0],
            [0, 0, 0, 0, 0, 7, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        ]
        is_sat, is_white = solve_nurikabe(height, width, problem)
        print('has answer:', is_sat)
        if is_sat:
            print(
                util.stringify_array(is_white, {
                    None: '?',
                    True: '.',
                    False: '#'
                }))
    else:
        parser = argparse.ArgumentParser(add_help=False)
        parser.add_argument('-h', '--height', type=int)
        parser.add_argument('-w', '--width', type=int)
        parser.add_argument('--min-clue', type=int, default=1)
        parser.add_argument('--max-clue', type=int, default=10)
        parser.add_argument('-v', '--verbose', action='store_true')
        args = parser.parse_args()

        height = args.height
        width = args.width
        min_clue = args.min_clue
        max_clue = args.max_clue
        verbose = args.verbose
        cspuz.config.solver_timeout = 1800.0
        while True:
            try:
                problem = generate_nurikabe(height,
                                            width,
                                            min_clue=min_clue,
                                            max_clue=max_clue,
                                            verbose=verbose)
                if problem is not None:
                    print(util.stringify_array(
                        problem, lambda x: '.'
                        if x == 0 else ('?' if x == -1 else str(x))),
                          flush=True)
                    print(flush=True)
            except subprocess.TimeoutExpired:
                print('timeout', file=sys.stderr)
コード例 #4
0
ファイル: gokigen.py プロジェクト: bay-puz/cspuz
def _main():
    if len(sys.argv) == 1:
        # https://puzsq.sakura.ne.jp/main/puzzle_play.php?pid=7862
        height = 7
        width = 7
        problem = [
            [-1, -1, -1, -1, -1, -1, -1, -1],
            [-1, 3, -1, 2, 3, -1, 3, -1],
            [-1, -1, 1, -1, -1, 1, -1, -1],
            [-1, -1, -1, -1, 3, 2, -1, -1],
            [-1, 3, -1, 3, 2, -1, 3, -1],
            [-1, -1, 1, -1, -1, 1, -1, -1],
            [-1, 3, -1, -1, 3, -1, 3, -1],
            [-1, -1, -1, -1, -1, -1, -1, -1],
        ]
        is_sat, ans = solve_gokigen(height, width, problem)
        print('has answer:', is_sat)
        if is_sat:
            print(
                util.stringify_array(ans, {
                    None: '.',
                    True: '\\',
                    False: '/'
                }))
    else:
        parser = argparse.ArgumentParser(add_help=False)
        parser.add_argument('-h', '--height', type=int, required=True)
        parser.add_argument('-w', '--width', type=int, required=True)
        parser.add_argument('--no-easy', action='store_true')
        parser.add_argument('--no-adjacent', action='store_true')
        parser.add_argument('-v', '--verbose', action='store_true')
        args = parser.parse_args()
        height = args.height
        width = args.width
        no_easy = args.no_easy
        no_adjacent = args.no_adjacent
        verbose = args.verbose
        while True:
            problem = generate_gokigen(height,
                                       width,
                                       no_easy=no_easy,
                                       no_adjacent=no_adjacent,
                                       verbose=verbose)
            if problem is not None:
                print(util.stringify_array(
                    problem, lambda x: '.' if x == -1 else str(x)),
                      flush=True)
                print(flush=True)
コード例 #5
0
def _main():
    if len(sys.argv) == 1:
        # https://puzsq.sakura.ne.jp/main/puzzle_play.php?pid=7919
        height = 6
        width = 6
        b = ['001112', '111132', '413333', '415556', '777756', '888776']
        blocks = defaultdict(list)
        for y in range(height):
            for x in range(width):
                blocks[b[y][x]].append((y, x))
        blocks = list(blocks.values())

        is_sat, is_black = solve_norinori(height, width, blocks)
        print('has answer:', is_sat)
        if is_sat:
            print(
                util.stringify_array(is_black, {
                    None: '?',
                    False: '.',
                    True: '#'
                }))
    else:
        height, width = map(int, sys.argv[1:])
        while True:
            gen = generate_norinori(height,
                                    width,
                                    min_block_size=2,
                                    verbose=True)
            if gen is not None:
                url = problem_to_pzv_url(height, width, gen)
                print(url, flush=True)
コード例 #6
0
ファイル: slitherlink.py プロジェクト: bay-puz/cspuz
def _main():
    if len(sys.argv) == 1:
        # original example: http://pzv.jp/p.html?slither/4/4/dgdh2c7b
        height = 4
        width = 4
        problem = [[3, -1, -1, -1], [3, -1, -1, -1], [-1, 2, 2, -1],
                   [-1, 2, -1, 1]]
        is_sat, is_line = solve_slitherlink(height, width, problem)
        print('has answer:', is_sat)
        if is_sat:
            print(util.stringify_grid_frame(is_line))
    else:
        cspuz.config.solver_timeout = 1800.0
        height, width = map(int, sys.argv[1:])
        while True:
            try:
                problem = generate_slitherlink(height,
                                               width,
                                               symmetry=True,
                                               verbose=True)
                if problem is not None:
                    print(
                        util.stringify_array(problem, {
                            -1: '.',
                            0: '0',
                            1: '1',
                            2: '2',
                            3: '3'
                        }))
                    print(flush=True)
            except subprocess.TimeoutExpired:
                print('timeout', file=sys.stderr)
コード例 #7
0
ファイル: firefly.py プロジェクト: bay-puz/cspuz
def _main():
    if len(sys.argv) == 1:
        # http://pzv.jp/p.html?firefly/6/6/a2.k4.b27a45g22i
        height = 6
        width = 6
        problem = [
            ['..', 'v?', '..', '..', '..', '..'],
            ['..', '..', '..', '..', '..', '..'],
            ['..', '>?', '..', '..', 'v7', '..'],
            ['>5', '..', '..', '..', '..', '..'],
            ['..', '..', 'v2', '..', '..', '..'],
            ['..', '..', '..', '..', '..', '..'],
        ]
        is_sat, is_line = solve_firefly(height, width, problem)
        print('has answer:', is_sat)
        if is_sat:
            print(util.stringify_grid_frame(is_line))
    else:
        cspuz.config.solver_timeout = 600.0
        height, width = map(int, sys.argv[1:])
        while True:
            try:
                problem = generate_firefly(height,
                                           width,
                                           min_clue=2,
                                           max_clue=7,
                                           verbose=True)
                if problem is not None:
                    print(util.stringify_array(problem))
                    print(flush=True)
            except subprocess.TimeoutExpired:
                print('timeout', file=sys.stderr)
コード例 #8
0
def _main():
    if len(sys.argv) == 1:
        # https://puzsq.sakura.ne.jp/main/puzzle_play.php?pid=8864
        height = 10
        width = 10
        problem = [
            [5, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 1, 0, 0],
            [0, 0, 0, 5, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 2, 0, 0, 0, 3],
            [0, 0, 0, 0, 0, 0, 0, 0, 4, 0],
            [0, 2, 0, 0, 0, 0, 0, 0, 0, 0],
            [2, 0, 0, 0, 4, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 4, 0, 0, 0],
            [0, 0, 2, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 5],
        ]
        is_sat, is_line = solve_geradeweg(height, width, problem)
        print('has answer:', is_sat)
        if is_sat:
            print(util.stringify_grid_frame(is_line))
    else:
        cspuz.config.solver_timeout = 600.0
        height, width = map(int, sys.argv[1:])
        while True:
            try:
                problem = generate_geradeweg(height, width, symmetry=False, verbose=True)
                if problem is not None:
                    print(util.stringify_array(problem, lambda x: '.' if x == 0 else str(x)))
                    print(flush=True)
            except subprocess.TimeoutExpired:
                print('timeout', file=sys.stderr)
コード例 #9
0
def _main():
    if len(sys.argv) == 1:
        # generated example: http://pzv.jp/p.html?fivecells/5/5/a23i21b3g3
        height = 5
        width = 5
        problem = [
            [-1, 2, 3, -1, -1],
            [-1, -1, -1, -1, -1],
            [-1, -1, 2, 1, -1],
            [-1, 3, -1, -1, -1],
            [-1, -1, -1, -1, 3],
        ]
        is_sat, is_border = solve_fivecells(height, width, problem)
        print('has answer:', is_sat)
        for i, x in enumerate(is_border):
            print(i, x.sol)
    else:
        height, width = map(int, sys.argv[1:])
        while True:
            problem = generate_fivecells(height, width, verbose=True)
            if problem is not None:
                print(util.stringify_array(problem, {
                    -2: '#',
                    -1: '.',
                    0: '0',
                    1: '1',
                    2: '2',
                    3: '3'
                }) + '\n',
                      flush=True)
コード例 #10
0
ファイル: sudoku.py プロジェクト: bay-puz/cspuz
def _main():
    if len(sys.argv) == 1:
        # https://commons.wikimedia.org/wiki/File:Sudoku-by-L2G-20050714.svg
        problem = [
            [5, 3, 0, 0, 7, 0, 0, 0, 0],
            [6, 0, 0, 1, 9, 5, 0, 0, 0],
            [0, 9, 8, 0, 0, 0, 0, 6, 0],
            [8, 0, 0, 0, 6, 0, 0, 0, 3],
            [4, 0, 0, 8, 0, 3, 0, 0, 1],
            [7, 0, 0, 0, 2, 0, 0, 0, 6],
            [0, 6, 0, 0, 0, 0, 2, 8, 0],
            [0, 0, 0, 4, 1, 9, 0, 0, 5],
            [0, 0, 0, 0, 8, 0, 0, 7, 9],
        ]
        is_sat, answer = solve_sudoku(problem)
        if is_sat:
            print(
                util.stringify_array(
                    answer,
                    dict([(None, '?')] + [(i, str(i)) for i in range(1, 10)])))
    elif len(sys.argv[1]) > 3:
        size, problem = parse_puzz_link_sudoku(sys.argv[1])
        is_sat, answer = solve_sudoku(problem, size)
        if is_sat:
            print(
                util.stringify_array(
                    answer,
                    dict([(None, '?')] + [(i, str(i)) for i in range(1, 10)])))
        else:
            print('no answer')
    else:
        n = int(sys.argv[1])
        if len(sys.argv) >= 3:
            max_clue = int(sys.argv[2])
        else:
            max_clue = None
        while True:
            try:
                problem = generate_sudoku(n,
                                          max_clue=max_clue,
                                          symmetry=False,
                                          verbose=True)
                if problem is not None:
                    print(to_puzz_link_sudoku(n, problem))
            except subprocess.TimeoutExpired:
                print('timeout', file=sys.stderr)
コード例 #11
0
def _main():
    if len(sys.argv) == 1:
        # generated example: http://pzv.jp/p.html?yinyang/6/6/0j40j0060220
        height = 6
        width = 6
        problem = [
            [0, 0, 0, 2, 0, 1],
            [0, 1, 1, 0, 0, 0],
            [2, 0, 1, 0, 0, 0],
            [0, 0, 0, 0, 2, 0],
            [0, 0, 0, 0, 0, 2],
            [0, 0, 2, 0, 0, 0],
        ]
        is_sat, is_black = solve_yinyang(height, width, problem)
        print('has answer:', is_sat)
        if is_sat:
            print(
                util.stringify_array(is_black, {
                    None: '?',
                    True: '#',
                    False: 'o'
                }))
    else:
        cspuz.config.solver_timeout = 1200.0
        height, width = map(int, sys.argv[1:])
        while True:
            try:
                problem = generate_yinyang(height,
                                           width,
                                           disallow_adjacent=False,
                                           verbose=True)
                if problem is not None:
                    print(util.stringify_array(problem, {
                        0: '.',
                        1: 'o',
                        2: '#'
                    }),
                          flush=True)
                    print(flush=True)
            except subprocess.TimeoutExpired:
                print('timeout', file=sys.stderr)
コード例 #12
0
ファイル: view.py プロジェクト: bay-puz/cspuz
def _main():
    height = 8
    width = 8
    problem, number, has_number = generate_view(height, width, True)
    if problem is not None:
        for row in problem:
            for num in row:
                if num < 0:
                    print('.', end=' ')
                else:
                    print(num, end=' ')
            print('')
        for y in range(height):
            for x in range(width):
                if has_number[y, x].sol:
                    print(number[y, x].sol, end='')
                else:
                    print(' ', end='')
            print('')
        return

    # https://twitter.com/semiexp/status/1210955179270393856
    is_sat, nums, has_number = solve_view(8, 8, [
        [-1,  4, -1, -1,  2, -1, -1, -1],
        [-1, -1,  2, -1, -1, -1, -1, -1],
        [-1, -1, -1, -1, -1, -1, -1,  2],
        [-1, -1, -1, -1,  2, -1, -1, -1],
        [-1, -1, -1, -1, -1,  2, -1, -1],
        [-1, -1,  1, -1, -1,  0, -1, -1],
        [-1,  2, -1, -1, -1, -1, -1, -1],
        [-1, -1, -1,  9, -1, -1, -1,  2],
    ])
    print('has_answer:', is_sat)
    if is_sat:
        ans = []
        for y in range(8):
            row = []
            for x in range(8):
                if has_number[y, x].sol is not None:
                    if has_number[y, x].sol:
                        if nums[y, x].sol is not None:
                            row.append(str(nums[y, x].sol))
                        else:
                            row.append('#')
                    else:
                        row.append('.')
                else:
                    row.append('?')
            ans.append(row)
        print(util.stringify_array(ans))
コード例 #13
0
def _main():
    if len(sys.argv) == 1:
        # https://twitter.com/semiexp/status/1227192389120356353
        height = 8
        width = 8
        problem = [
            [0, 0, 0, 5, 4, 0, 0, 0],
            [0, 0, 0, 4, 1, 3, 0, 0],
            [1, 0, 0, 0, 0, 0, 0, 4],
            [6, 0, 4, 0, 0, 0, 0, 7],
            [0, 5, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 2],
            [1, 0, 0, 0, 4, 0, 0, 7],
            [7, 0, 0, 6, 2, 0, 7, 0],
        ]
        #        """
        is_sat, ans = solve_fillomino(height, width, problem)
        print('has answer:', is_sat)
        if is_sat:
            print(util.stringify_array(ans, str))
    else:
        cspuz.config.solver_timeout = 1200.0
        height, width = map(int, sys.argv[1:])
        while True:
            try:
                problem = generate_fillomino(height,
                                             width,
                                             disallow_adjacent=True,
                                             symmetry=True,
                                             verbose=True)
                if problem is not None:
                    print(util.stringify_array(
                        problem, lambda x: '.' if x == 0 else str(x)),
                          flush=True)
                    print(flush=True)
            except subprocess.TimeoutExpired:
                print('timeout', file=sys.stderr)
コード例 #14
0
ファイル: star_battle.py プロジェクト: bay-puz/cspuz
def _main():
    if len(sys.argv) == 1:
        # generated example: http://pzv.jp/p.html?starbattle/6/6/1/2u9gn9c9jpmk
        is_sat, has_star = solve_star_battle(6, [
            [0, 0, 0, 0, 1, 1],
            [0, 2, 3, 0, 1, 1],
            [2, 2, 3, 3, 3, 1],
            [2, 1, 1, 1, 1, 1],
            [2, 4, 4, 1, 4, 5],
            [2, 2, 4, 4, 4, 5],
        ], 1)
        print('has answer:', is_sat)
        if is_sat:
            print(
                util.stringify_array(has_star, {
                    None: '?',
                    True: '*',
                    False: '.'
                }))
    elif len(sys.argv) == 2:
        n, k, problem = parse_puzz_link_starbattle(sys.argv[1])
        is_sat, has_star = solve_star_battle(n, problem, k)
        print('has answer:', is_sat)
        if is_sat:
            print(
                util.stringify_array(has_star, {
                    None: '?',
                    True: '*',
                    False: '.'
                }))
    else:
        n, k = map(int, sys.argv[1:])
        while True:
            problem = generate_star_battle(n, k, verbose=True)
            if problem is not None:
                print(to_puzz_link_starbattle(n, k, problem), flush=True)
コード例 #15
0
ファイル: nurimisaki.py プロジェクト: bay-puz/cspuz
def _main():
    if len(sys.argv) == 1:
        # https://twitter.com/semiexp/status/1168898897424633856
        height = 10
        width = 10
        problem = [
            [-1, -1, -1, -1, 3, -1, -1, -1, -1, -1],
            [-1, 3, -1, -1, -1, -1, -1, -1, -1, -1],
            [-1, -1, -1, -1, -1, -1, -1, -1, 2, -1],
            [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1],
            [-1, -1, -1, 2, -1, -1, -1, -1, -1, -1],
            [-1, -1, -1, -1, 0, -1, 2, -1, -1, -1],
            [-1, 2, -1, -1, -1, -1, -1, -1, -1, -1],
            [-1, -1, -1, -1, -1, -1, -1, -1, -1, 2],
            [-1, -1, -1, -1, -1, 2, -1, -1, -1, -1],
            [-1, -1, -1, -1, 3, -1, -1, -1, -1, -1],
        ]
        is_sat, ans = solve_nurimisaki(height, width, problem)
        print('has answer:', is_sat)
        if is_sat:
            print(util.stringify_array(ans, {
                None: '?',
                True: '.',
                False: '#'
            }))
    else:
        height, width = map(int, sys.argv[1:])
        while True:
            problem = generate_fillomino(height, width, verbose=True)
            if problem is not None:
                print(util.stringify_array(problem, {
                    -1: '.',
                    0: 'O'
                }),
                      flush=True)
                print(flush=True)
コード例 #16
0
ファイル: doppelblock.py プロジェクト: bay-puz/cspuz
def _main():
    if len(sys.argv) == 1:
        # https://puzsq.jp/main/puzzle_play.php?pid=10025
        n = 5
        row = [5, -1, 5, -1, -1]
        column = [3, -1, -1, 1, -1]
        is_sat, answer = solve_doppelblock(n, row, column)
        if is_sat:
            print(util.stringify_array(answer, str))
    else:
        n = int(sys.argv[1])
        while True:
            problem = generate_doppelblock(n)
            if problem is not None:
                print(problem, flush=True)
コード例 #17
0
def _main():
    if len(sys.argv) == 1:
        # generated example: https://twitter.com/semiexp/status/1223911674941296641
        n = 6
        u = [0, 0, 0, 2, 0, 3]
        d = [0, 6, 3, 3, 2, 0]
        l = [2, 0, 0, 3, 3, 3]
        r = [0, 6, 3, 0, 2, 0]
        is_sat, answer = solve_building(n, u, d, l, r)
        if is_sat:
            print(util.stringify_array(answer, str))
    else:
        n = int(sys.argv[1])
        while True:
            problem = generate_building(n, verbose=True)
            if problem is not None:
                print(problem)
コード例 #18
0
def _main():
    if len(sys.argv) == 1:
        pass
    else:
        cspuz.config.solver_timeout = 1200.0
        height, width = map(int, sys.argv[1:])
        while True:
            try:
                problem = generate_simpleloop(height, width, verbose=True)
                if problem is not None:
                    print(util.stringify_array(problem, {
                        0: '.',
                        1: '#'
                    }),
                          flush=True)
                    print('', flush=True)
            except subprocess.TimeoutExpired:
                print('timeout', file=sys.stderr)
コード例 #19
0
def _main():
    if len(sys.argv) == 1:
        # https://twitter.com/semiexp/status/1206956338556764161
        height = 10
        width = 10
        problem = [
            ['..', '..', '..', '..', '..', '..', '..', '..', '..', '..'],
            ['..', '..', '..', '..', '..', '..', '..', '..', '..', '..'],
            ['..', '..', 'v0', '..', '..', '>2', '..', '..', '..', '..'],
            ['..', '..', '..', '..', '..', '..', '..', '..', '..', '..'],
            ['..', '..', '..', '..', '..', '..', '..', '..', '..', '..'],
            ['..', '..', '..', '..', '..', '..', '..', '..', '^1', '..'],
            ['..', '..', '..', '..', '..', '..', '..', '..', '..', '..'],
            ['..', '..', '^0', '..', '^3', '..', '..', '>1', '..', '..'],
            ['..', '..', '..', '..', '..', '..', '..', '..', '..', '..'],
            ['..', '..', '..', '..', '..', '..', '..', '>0', '..', '..'],
        ]
        is_sat, is_line, black_cell = solve_yajilin(height, width, problem)
        print('has answer:', is_sat)
        if is_sat:
            print(util.stringify_grid_frame(is_line))
    else:
        parser = argparse.ArgumentParser(add_help=False)
        parser.add_argument('-h', '--height', type=int, required=True)
        parser.add_argument('-w', '--width', type=int, required=True)
        parser.add_argument('--no-zero', action='store_true')
        parser.add_argument('--no-max-clue', action='store_true')
        parser.add_argument('-v', '--verbose', action='store_true')
        args = parser.parse_args()

        height = args.height
        width = args.width
        no_zero = args.no_zero
        no_max_clue = args.no_max_clue
        verbose = args.verbose
        while True:
            problem = generate_yajilin(height,
                                       width,
                                       no_zero=no_zero,
                                       no_max_clue=no_max_clue,
                                       verbose=verbose)
            if problem is not None:
                print(util.stringify_array(problem, str), flush=True)
                print(flush=True)
コード例 #20
0
ファイル: lits.py プロジェクト: bay-puz/cspuz
def _main():
    if len(sys.argv) == 1:
        height = 10
        width = 10
        b = [
            '0000000222',
            '0010002222',
            '1113332222',
            '5563444288',
            '5663422228',
            '5663223338',
            '5633333338',
            '6673339aaa',
            '6773999aab',
            '77bbbbbbbb',
        ]
        blocks = defaultdict(list)
        for y in range(height):
            for x in range(width):
                blocks[b[y][x]].append((y, x))
        blocks = list(blocks.values())

        is_sat, is_black = solve_lits(height, width, blocks)
        print('has answer:', is_sat)
        if is_sat:
            print(util.stringify_array(is_black, {
                None: '?',
                True: '#',
                False: '.'
            }))
    else:
        height, width = map(int, sys.argv[1:])
        while True:
            gen = generate_lits(height, width, verbose=True)
            if gen is not None:
                a = [[-1 for _ in range(width)] for _ in range(height)]
                for i, block in enumerate(gen):
                    for y, x in block:
                        a[y][x] = i
                for y in range(height):
                    for x in range(width):
                        print('{:2}'.format(a[y][x]), end='', file=sys.stderr)
                    print(file=sys.stderr)
                print(problem_to_pzv_url(height, width, gen), flush=True)
コード例 #21
0
def _main():
    if len(sys.argv) == 1:
        pass
    else:
        height, width = map(int, sys.argv[1:])
        cspuz.config.solver_timeout = 1200.0
        while True:
            try:
                problem = generate_creek(height,
                                         width,
                                         no_easy=True,
                                         verbose=True)
                if problem is not None:
                    print(util.stringify_array(
                        problem, lambda x: '.' if x == -1 else str(x)),
                          flush=True)
                    print(flush=True)
            except subprocess.TimeoutExpired:
                print('timeout', file=sys.stderr)
コード例 #22
0
ファイル: masyu.py プロジェクト: bay-puz/cspuz
def _main():
    if len(sys.argv) == 1:
        # https://puzsq.jp/main/puzzle_play.php?pid=9833
        height = 10
        width = 10
        problem = [
            [0, 0, 0, 0, 2, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
            [0, 2, 0, 0, 0, 0, 0, 0, 2, 0],
            [1, 0, 2, 0, 0, 1, 0, 1, 0, 0],
            [0, 0, 0, 0, 0, 0, 2, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 1, 0, 1, 0, 1, 0, 0],
            [0, 0, 0, 2, 0, 0, 0, 0, 0, 0],
            [0, 2, 0, 0, 0, 0, 0, 1, 0, 0],
            [0, 0, 0, 0, 1, 0, 0, 1, 0, 0],
        ]
        is_sat, is_line = solve_masyu(height, width, problem)
        print('has answer:', is_sat)
        if is_sat:
            print(util.stringify_grid_frame(is_line))
    else:
        cspuz.config.solver_timeout = 600.0
        height, width = map(int, sys.argv[1:])
        while True:
            try:
                problem = generate_masyu(height,
                                         width,
                                         symmetry=False,
                                         verbose=False)
                if problem is not None:
                    print(
                        util.stringify_array(problem, {
                            0: '.',
                            1: 'O',
                            2: '#'
                        }))
                    print(flush=True)
            except subprocess.TimeoutExpired:
                print('timeout', file=sys.stderr)
コード例 #23
0
def _main():
    if len(sys.argv) == 1:
        # generated example: https://puzz.link/p?compass/5/5/m..1.i25.1g53..i1..1m
        height = 5
        width = 5
        problem = [(1, 2, -1, 1, -1, -1), (2, 1, 2, -1, 5, 1),
                   (2, 3, 5, -1, 3, -1), (3, 2, 1, -1, -1, 1)]
        is_sat, ans = solve_compass(height, width, problem)
        print('has answer:', is_sat)
        if is_sat:
            print(util.stringify_array(ans, str))
    else:
        height, width, nlo, nhi = map(int, sys.argv[1:])
        while True:
            pos = generate_placement(height, width, nlo, nhi)
            problem = generate_compass(height,
                                       width,
                                       pos,
                                       prefer_large_blocks=True,
                                       verbose=True)
            if problem is not None:
                print(to_puzz_link_url(height, width, problem), flush=True)
コード例 #24
0
ファイル: sukoro.py プロジェクト: bay-puz/cspuz
def _main():
    if len(sys.argv) < 3:
        puzz_link = 'http://puzz.link/p?sukoro/8/8/j3d1b2a4b33c2b2d3a13h1a2b1d1d1'
        if len(sys.argv) == 2:
            puzz_link = sys.argv[1]
        print('problem: {}'.format(puzz_link))
        height, width, problem = parse_puzz_link_sukoro(puzz_link)
        is_sat, nums, has_number = solve_sukoro(height, width, problem)
        print('has_answer:', is_sat)
        if is_sat:
            ans = []
            for y in range(height):
                row = []
                for x in range(width):
                    if has_number[y, x].sol is not None:
                        if has_number[y, x].sol:
                            if nums[y, x].sol is not None:
                                row.append(str(nums[y, x].sol))
                            else:
                                row.append('o')
                        else:
                            row.append('x')
                    else:
                        row.append('?')
                ans.append(row)
            print(util.stringify_array(ans))
    elif len(sys.argv) == 3:
        height, width = map(int, sys.argv[1:])
        problem = generate_sukoro(height, width, True)
        if problem is not None:
            print(to_puzz_link_sukoro(height, width, problem))
    elif len(sys.argv) == 5:
        height, width, set, limit = map(int, sys.argv[1:])
        problem = generate_sukoro_numbers_set(height, width, True, set, limit)
        if problem is not None:
            print(to_puzz_link_sukoro(height, width, problem))
コード例 #25
0
ファイル: nurimaze.py プロジェクト: bay-puz/cspuz
def _main():
    if len(sys.argv) == 1:
        # https://twitter.com/semiexp/status/1229769178623574026
        height = 10
        width = 10
        wall_vertical = [[0, 1, 1, 1, 0, 1, 0, 1, 1],
                         [1, 0, 0, 1, 0, 1, 1, 0, 1],
                         [1, 0, 1, 1, 1, 1, 1, 1, 1],
                         [1, 1, 1, 1, 1, 1, 1, 1, 1],
                         [0, 1, 1, 1, 1, 0, 1, 1, 1],
                         [1, 1, 0, 0, 1, 0, 1, 1, 1],
                         [1, 1, 1, 1, 1, 1, 1, 1, 1],
                         [0, 1, 1, 1, 1, 1, 1, 1, 1],
                         [1, 1, 1, 1, 1, 1, 1, 0, 1],
                         [1, 0, 1, 1, 1, 0, 1, 0, 1]]
        wall_horizontal = [[1, 1, 1, 1, 1, 1, 0, 1, 1, 1],
                           [1, 1, 1, 0, 1, 1, 1, 1, 1, 1],
                           [1, 1, 1, 1, 1, 1, 0, 0, 1, 1],
                           [0, 1, 1, 1, 1, 1, 1, 1, 1, 1],
                           [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
                           [1, 1, 1, 0, 1, 1, 1, 1, 1, 1],
                           [1, 1, 1, 0, 1, 1, 1, 1, 1, 1],
                           [1, 1, 1, 1, 0, 1, 0, 1, 1, 1],
                           [1, 1, 0, 1, 1, 1, 1, 1, 1, 0]]
        mark = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 2, 0, 0, 0],
                [1, 0, 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, 0, 0, 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, 2, 0, 0, 0, 0, 2, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0, 0, 0]]
        start = (6, 5)
        goal = (7, 8)
        is_sat, is_white = solve_nurimaze(height, width, wall_vertical,
                                          wall_horizontal, mark, start, goal)
        print('has answer:', is_sat)
        if is_sat:
            print(
                util.stringify_array(is_white, {
                    None: '?',
                    True: '.',
                    False: '#'
                }))
    else:
        height, width = map(int, sys.argv[1:])
        while True:
            generated = generate_nurimaze(height, width, verbose=True)
            if generated is not None:
                wall_vertical, wall_horizontal, mark, start, goal = generated
                for y in range(height * 2 + 1):
                    for x in range(width * 2 + 1):
                        if y % 2 == 0 and x % 2 == 0:
                            print('+', end='')
                        elif y % 2 == 1 and x % 2 == 1:
                            cy = y // 2
                            cx = x // 2
                            if mark[cy][cx] == 0:
                                if (cy, cx) == start:
                                    c = 'S'
                                elif (cy, cx) == goal:
                                    c = 'G'
                                else:
                                    c = ' '
                            elif mark[cy][cx] == 1:
                                c = 'O'
                            elif mark[cy][cx] == 2:
                                c = 'X'
                            print(c, end='')
                        elif y % 2 == 0 and x % 2 == 1:
                            if y == 0 or y == height * 2 or wall_horizontal[
                                    y // 2 - 1][x // 2] == 1:
                                print('-', end='')
                            else:
                                print(' ', end='')
                        elif y % 2 == 1 and x % 2 == 0:
                            if x == 0 or x == width * 2 or wall_vertical[
                                    y // 2][x // 2 - 1] == 1:
                                print('|', end='')
                            else:
                                print(' ', end='')
                    print()
                print()
                print(problem_to_pzv_url(height, width, wall_vertical,
                                         wall_horizontal, mark, start, goal),
                      flush=True)