seqBench / scripts /spatial.py
emnlp-submission's picture
Upload 3 files
fb0015f verified
from dataclasses import dataclass
from typing import Any, List, Tuple
import random
@dataclass
class CompositeTool:
name: str # name of the composite tool
tools: List[Tool] # tools that make up the composite tool
compatible_keys: List[str] # keys that the composite tool can fix
who_can_build: List[
Tuple[str, int]
] # expertise and count of people in each expertise needed to build the composite tool
def __str__(self):
return f"CompositeTool {self.name}"
def get_description(self):
return f"CompositeTool {self.name} can fix keys: {self.compatible_keys} but consists of tools: {self.tools}"
@dataclass
class Tool:
name: str # name of the tool
compatible_keys: List[str] # keys that the tool can fix
who_can_use: List[str] # expertise needed to use the tool
def __str__(self):
return f"Tool {self.name}"
def get_description(self):
return f"Tool {self.name} can fix keys: {self.compatible_keys}"
@dataclass
class Key:
name: str # name of the key
color: str # color of the key
broken: bool # whether the key is broken
fixable: bool # whether the key is fixable
tools: List[str] # tools or composite tools that are needed to fix the key
who_can_fix: List[
Tuple[str, int]
] # expertise and count of people in each expertise needed to fix the key
def __str__(self):
return f"Key {self.name}"
def description(self):
return f"""Key {self.name} is {self.color}
{'but it is broken and cannot be used' if self.broken else ' and it works'}"""
@dataclass
class Object:
name: str # name of the object
description: str # description of the object
def __str__(self):
return f"item {self.name} ({self.description})"
def get_description(self):
return f"item {self.name} is described as {self.description}"
@dataclass
class Box:
name: str # name of the box
contents: List[
str
] # contents of the box - list of box names or key names or tool names
locked: bool # whether the box is locked
def __str__(self):
return f"Box {self.name}"
def get_description(self):
return f"Box {self.name} contains: {self.contents}"
@dataclass
class Person:
name: str # name of the person
room: None | Any # room that the person is in
boxes: List[Box] # boxes that the person has
keys: List[Key] # keys that the person has
cooperates_with: List[str] # names of people
can_build: List[str] # names of composite tools that the person can build
can_fix: List[str] # names of keys that the person can fix
can_use: List[str] # names of keys that the person can use
def __str__(self):
return f"Person {self.name}"
def get_description(self):
return f"Person {self.name} is in room {self.room.name}"
@dataclass
class Door:
name: str # name of the door
locked: bool # whether the door is locked
key: None | Key # key that can unlock the door
two_way: bool # whether the door is two way
key_hole_outward_facing: bool # whether the key hole is outward facing
def __str__(self):
return f"Door {self.name}"
def get_description(self):
return f"Door {self.name} is {'locked' if self.locked else 'unlocked'}"
@dataclass
class Room:
name: str # name of the room
west: None | Door # door to the west
east: None | Door # door to the east
north: None | Door # door to the north
south: None | Door # door to the south
occupants: list[str] # names of people in the room
west_neighbor: None | Any # room to the west
east_neighbor: None | Any # room to the east
north_neighbor: None | Any # room to the north
south_neighbor: None | Any # room to the south
def __str__(self):
return f"""Room {self.name}"""
def get_description(self):
return f"""Room {self.name} is adjacent to {self.west_neighbor.name
if self.west_neighbor else 'none'} on the west side,
{self.east_neighbor.name if self.east_neighbor else 'none'} on the east side,
{self.north_neighbor.name if self.north_neighbor else 'none'} on the north side,
{self.south_neighbor.name if self.south_neighbor else 'none'} on the south side
{self.occupants} are in the room and there are doors on these sides
{self.west.name if self.west else 'none'} on the west side,
{self.east.name if self.east else 'none'} on the east side,
{self.north.name if self.north else 'none'} on the north side,
{self.south.name if self.south else 'none'} on the south side"""
@dataclass
class World:
rooms: List[Room] # rooms in the world
people: List[Person] # people in the world
boxes: List[Box] # boxes in the world
keys: List[Key] # keys in the world
tools: List[Tool] # tools in the world
def __str__(self):
return f"World"
def get_description(self):
return f"This is the world: {self.rooms} {self.people} {self.boxes} {self.keys} {self.tools}"
def generate_configuration(N_x: int, N_y: int, n_people: int):
# generate a random configuration of people in rooms
# sample larger than population with replacement
walls = [True] + random.choices([True, False], k=3)
random.shuffle(walls)
rooms = [
Room(
name=f"Room {i}",
west=walls[0],
east=walls[1],
north=walls[2],
south=walls[3],
occupants=[],
lattice_position=(i, j),
)
for i in range(N_y)
for j in range(N_x)
]
# generate a random configuration of people in rooms
people = [Person(name=f"Person {i}") for i in range(n_people)]
for person in people:
room = random.choice(rooms)
room.occupants.append(person)
return rooms
def print_walls():
for i in range(10):
print(generate_configuration(10, 10))
if __name__ == "__main__":
print_walls()