96 lines
2.6 KiB
Python
96 lines
2.6 KiB
Python
from michael.icfprequests import LibRequests
|
|
import json
|
|
import os.path
|
|
import sys
|
|
import random
|
|
|
|
class Room:
|
|
|
|
def __init__(self, room_id: str, parent, path:str):
|
|
self.id = room_id
|
|
self.parent = parent
|
|
self.path = path
|
|
self.rooms = [None for _ in range(6)]
|
|
self.double = False
|
|
|
|
def createRoom(self,no: int,id):
|
|
self.rooms[no]=Room(id,self,self.path+str(no))
|
|
|
|
def full_id(self):
|
|
if self.id is None:
|
|
return None
|
|
fullid = self.id
|
|
for room in self.rooms:
|
|
if room is None:
|
|
return None
|
|
fullid = fullid + room.id
|
|
return fullid
|
|
|
|
def rooms_without_id(self):
|
|
none_rooms = []
|
|
for doorcounter, room in enumerate(self.rooms):
|
|
if room is None:
|
|
none_rooms.append(self.path+str(doorcounter))
|
|
return none_rooms
|
|
|
|
|
|
|
|
def setRoomId(self,id:str):
|
|
if self.id is None and self.parent is None and self.path =="":
|
|
self.id =id
|
|
else:
|
|
print("Id can not be set for initial Path Element!")
|
|
|
|
|
|
class LibMapper:
|
|
|
|
def __init__(self, problemName:str, no_of_rooms:int):
|
|
self.no_of_rooms = no_of_rooms
|
|
self.problemName = problemName
|
|
self.requester = LibRequests()
|
|
self.startRoom = Room(None,None,"")
|
|
self.rooms_list = {}
|
|
|
|
def start(self):
|
|
response = self.requester.select(self.problemName)
|
|
if self.problemName != response:
|
|
print("Select Request failed")
|
|
else:
|
|
self.explore_map(self.startRoom)
|
|
self.submit_guess()
|
|
|
|
def explore_map(self, startRoom):
|
|
plans = startRoom.rooms_without_id()
|
|
print("Plans: "+str(plans))
|
|
result = self.requester.explore(plans)
|
|
print(result)
|
|
if startRoom.id is None:
|
|
startRoom.setRoomId(result["results"][0][0])
|
|
for counter,result in enumerate(result["results"]):
|
|
startRoom.createRoom(counter,result[1])
|
|
fullid = startRoom.full_id()
|
|
if not fullid is None:
|
|
if self.rooms_list.get(fullid) is None:
|
|
self.rooms_list[fullid] = startRoom
|
|
else:
|
|
startRoom.double = True
|
|
|
|
|
|
|
|
def submit_guess(self):
|
|
pass
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
problem = sys.argv[1]
|
|
|
|
with open(os.path.join("..", "problems.json")) as h:
|
|
problems = json.loads(h.read())
|
|
|
|
problems = {p["problem"]: {"size": p["size"]} for p in problems}
|
|
|
|
if problem not in problems:
|
|
raise ExploreError(f"unknown problem {problem}")
|
|
mapper = LibMapper(problem,problems[problem]["size"])
|
|
mapper.start() |