tests = [
        ([
            [*"____"],
            [*"_W__"],
            [*"___G"],
            [*"P___"]
        ], True),
        
        ([
            [*"____"],
            [*"_P__"],
            [*"____"],
            [*"_W_G"]
        ]
        , True),
        
        ([
            [*"____"],
            [*"____"],
            [*"W__P"],
            [*"__PG"]
        ]
        , False),
        
        ([
            [*"__GP"],
            [*"_P__"],
            [*"W___"],
            [*"____"]
        ]
        , True),
        
        ([
            [*"__W_"],
            [*"____"],
            [*"___P"],
            [*"___G"]
        ]
        , True),
        
        ([
            [*"__W_"],
            [*"____"],
            [*"__PP"],
            [*"___G"]
        ]
        , True),
        
        ([
            [*"__W_"],
            [*"____"],
            [*"_PPP"],
            [*"___G"]
        ]
        , True),
        
        ([
            [*"___P"],
            [*"__PG"],
            [*"___P"],
            [*"W___"]
        ]
        , False),
        
        ([
            [*"__P_"],
            [*"____"],
            [*"__P_"],
            [*"__WG"]
        ]
        , True),
        
        ([
            [*"____"],
            [*"__PW"],
            [*"PG__"],
            [*"____"]
        ]
        , True),
        
        ([
            [*"__P_"],
            [*"____"],
            [*"WP__"],
            [*"_G__"]
        ]
        , True),
        
        ([
            [*"__PG"],
            [*"____"],
            [*"__WP"],
            [*"____"]
        ]
        , True),
        
        ([
            [*"___W"],
            [*"__P_"],
            [*"__G_"],
            [*"P___"]
        ]
        , True),
        
        ([
            [*"__WP"],
            [*"_P__"],
            [*"____"],
            [*"_G__"]
        ]
        , True),
        
        ([
            [*"__WP"],
            [*"____"],
            [*"__P_"],
            [*"P_G_"]
        ]
        , True),
        
        ([
            [*"__PG"],
            [*"___W"],
            [*"__PP"],
            [*"____"]
        ], True)
]
from itertools import permutations
DIRS = ((1, 0), (-1, 0), (0, 1), (0, -1))
# def get_adj(x, y):
#     for dx, dy in DIRS:
#         u, v = x + dx, y + dy
#         if 
t, ans = tests[-1]
N = 4
pits_count = 0
pits = set()
wumpus = set()
for i in range(N):
    for j in range(N):
        if t[i][j] in 'PW':
            pits_count += 1
            for di, dj in DIRS:
                x, y = i + di, j + dj
                if 0 <= x < N and 0 <= y < N:
                    if t[i][j] == 'P':
                        pits.add((x, y))
                    else:
                        wumpus.add((x, y))

poss = set(permutations(range(1, 16), r=pits_count + 1))
x, y = 0, 0
print(pits)
print(wumpus)
print(t)

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: