File size: 6,207 Bytes
fb0015f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
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()