"doc/man/git@gitlab.caltech.edu:cs24-19fa/git_rec_nano.git" did not exist on "ad344e9d1d4c1d04582cdb0ada46dfbeb5ec52e0"
  • Skynet0's avatar
    Code · 9f5fe1b7
    Skynet0 authored
    9f5fe1b7
masyu_util.py 1.07 KB
from typing import NamedTuple, List, Tuple
from cs11puzzles.pzpr_helpers import conns_to_str_grid

WHITE = 1
BLACK = 2

WHITE_SYM = ""
BLACK_SYM = ""


class MasyuInstance(NamedTuple):
    pearls: List[List[int]]


def load_puzzle_and_solution(fname: str) -> Tuple[MasyuInstance, List[List[str]]]:
    with open(fname) as f:
        assert f.readline().strip() == "pzprv3"
        assert f.readline().strip() == "mashu"

        height = int(f.readline())
        _ = int(f.readline())  # width

        pearls = [
            [0 if i == "." else int(i) for i in f.readline().strip().split(" ")]
            for _ in range(height)
        ]

        conn_right = [
            [int(n) == 1 for n in f.readline().strip().split(" ")]
            for _ in range(height)
        ]
        conn_down = [
            [int(n) == 1 for n in f.readline().strip().split(" ")]
            for _ in range(height - 1)
        ]

        return MasyuInstance(pearls), conns_to_str_grid(conn_right, conn_down)


def load_puzzle(fname: str):
    puzzle, _ = load_puzzle_and_solution(fname)
    return puzzle