-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.py
More file actions
40 lines (29 loc) · 1006 Bytes
/
game.py
File metadata and controls
40 lines (29 loc) · 1006 Bytes
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
from world import World
import random
from wumpus import Wumpus
from agent import Agent
from pit import Pit
HEIGHT = 4
WIDTH = 4
ENTITIES = [Agent, *[Wumpus]*2, *[Pit]*2]
class Game:
def __init__(self) -> None:
self.world = World(WIDTH, HEIGHT, self.gameOver)
self.agents = []
self.spawnEntities()
def spawnEntities(self):
all_rooms = [(i, j) for i in range(HEIGHT) for j in range(WIDTH)]
assert len(ENTITIES) < len(all_rooms), "Not enough rooms for entities"
rooms = random.sample(all_rooms, len(ENTITIES))
for index, entity in enumerate(ENTITIES):
if entity == Agent:
self.agents.append(entity(*rooms[index], self.world))
else:
entity(*rooms[index], self.world)
def gameOver(self):
print("GAME OVER")
exit(0)
if __name__ == "__main__":
game = Game()
for agent in game.agents:
agent.loop()