|
|
|
@ -1,6 +1,5 @@
|
|
|
|
#!/usr/bin/env python3
|
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
|
|
|
|
import api
|
|
|
|
|
|
|
|
import functools
|
|
|
|
import functools
|
|
|
|
import json
|
|
|
|
import json
|
|
|
|
import os.path
|
|
|
|
import os.path
|
|
|
|
@ -8,6 +7,9 @@ import sys
|
|
|
|
import random
|
|
|
|
import random
|
|
|
|
from collections import defaultdict
|
|
|
|
from collections import defaultdict
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import api
|
|
|
|
|
|
|
|
import graph
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ExploreError(Exception):
|
|
|
|
class ExploreError(Exception):
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
@ -261,21 +263,24 @@ class Explore:
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def guess(self):
|
|
|
|
def guess(self):
|
|
|
|
|
|
|
|
aedi = graph.Aedificium(self.problem)
|
|
|
|
|
|
|
|
|
|
|
|
ids = {}
|
|
|
|
ids = {}
|
|
|
|
for i, rid in enumerate(self.room_ids.keys()):
|
|
|
|
for i, p in enumerate(self.rooms.keys()):
|
|
|
|
ids[rid] = i
|
|
|
|
ids[p] = i
|
|
|
|
|
|
|
|
aedi.add_node(str(p))
|
|
|
|
|
|
|
|
|
|
|
|
connected = set()
|
|
|
|
connected = set()
|
|
|
|
connections = []
|
|
|
|
connections = []
|
|
|
|
for path, ns in self.neighbors.items():
|
|
|
|
for path, ns in self.neighbors.items():
|
|
|
|
src_id = self.rooms[path]
|
|
|
|
src_path = path
|
|
|
|
for src_door, (trg_path, trg_id) in enumerate(ns):
|
|
|
|
for src_door, (trg_path, _) in enumerate(ns):
|
|
|
|
src = (src_id, src_door)
|
|
|
|
src = (src_path, src_door)
|
|
|
|
trg_door = next(
|
|
|
|
trg_door = next(
|
|
|
|
(
|
|
|
|
(
|
|
|
|
j
|
|
|
|
j
|
|
|
|
for j, (p, rid) in enumerate(self.neighbors[trg_path])
|
|
|
|
for j, (p, rid) in enumerate(self.neighbors[trg_path])
|
|
|
|
if rid == src_id
|
|
|
|
if p == src_path
|
|
|
|
),
|
|
|
|
),
|
|
|
|
None,
|
|
|
|
None,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
@ -283,7 +288,7 @@ class Explore:
|
|
|
|
raise ExploreError(
|
|
|
|
raise ExploreError(
|
|
|
|
f"backlink not found: {(src, trg_path, self.neighbors[trg_path])}"
|
|
|
|
f"backlink not found: {(src, trg_path, self.neighbors[trg_path])}"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
trg = (trg_id, trg_door)
|
|
|
|
trg = (trg_path, trg_door)
|
|
|
|
|
|
|
|
|
|
|
|
if (src, trg) in connected or (trg, src) in connected:
|
|
|
|
if (src, trg) in connected or (trg, src) in connected:
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
@ -295,18 +300,21 @@ class Explore:
|
|
|
|
"to": {"room": ids[trg[0]], "door": trg[1]},
|
|
|
|
"to": {"room": ids[trg[0]], "door": trg[1]},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
aedi.add_edge(src[0], src[1], trg[0], trg[1])
|
|
|
|
|
|
|
|
|
|
|
|
layout = {
|
|
|
|
layout = {
|
|
|
|
"rooms": [int(rid[0]) for rid in ids.keys()],
|
|
|
|
"rooms": [int(self.rooms[p][0]) for p in ids.keys()],
|
|
|
|
"startingRoom": ids[self.rooms[Path()]],
|
|
|
|
"startingRoom": ids[Path()],
|
|
|
|
"connections": connections,
|
|
|
|
"connections": connections,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# print(layout)
|
|
|
|
# print(layout)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
aedi.render()
|
|
|
|
return api.guess(layout)
|
|
|
|
return api.guess(layout)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def room_solve(problem, nrooms, plen):
|
|
|
|
def room_solve(problem, nrooms, plen):
|
|
|
|
ex = Explore(problem, [d+d+d+d+d+d for d in DOORS[:plen]])
|
|
|
|
ex = Explore(problem, [d + d + d + d + d + d for d in DOORS[:plen]])
|
|
|
|
print(ex.probes)
|
|
|
|
print(ex.probes)
|
|
|
|
api.select(ex.problem)
|
|
|
|
api.select(ex.problem)
|
|
|
|
res = ex.explore(Path())
|
|
|
|
res = ex.explore(Path())
|
|
|
|
|