2021-03-13 17:41:38 +01:00
|
|
|
from mesa import Model, Agent
|
2021-03-16 23:02:16 +01:00
|
|
|
from agent import Player, Box
|
2021-03-13 17:41:38 +01:00
|
|
|
from mesa.time import RandomActivation
|
2021-03-16 15:36:24 +01:00
|
|
|
from mesa.space import MultiGrid
|
2021-03-13 17:41:38 +01:00
|
|
|
#from mesa.datacollection import DataCollector
|
|
|
|
import random
|
|
|
|
|
2021-03-16 16:06:56 +01:00
|
|
|
x = 10
|
|
|
|
y = 10
|
2021-03-13 17:41:38 +01:00
|
|
|
possible_contents = ['gold', 'sword', 'shield', 'potion', 'empty']
|
|
|
|
step_counter = 0
|
|
|
|
boxes_number = 5
|
|
|
|
|
|
|
|
|
|
|
|
class GameMap(Model):
|
|
|
|
def __init__(self, x, y, boxes_number):
|
2021-03-16 15:36:24 +01:00
|
|
|
self.grid = MultiGrid(x, y, False)
|
2021-03-13 17:41:38 +01:00
|
|
|
self.schedule = RandomActivation(self) # agenci losowo po kolei wykonują swoje akcje
|
|
|
|
# to jest potrzebne przy założeniu, że potwory chodzą?
|
|
|
|
self.boxes_number = boxes_number
|
2021-03-16 16:06:56 +01:00
|
|
|
self.running=True
|
|
|
|
player = Player(1000, self)
|
|
|
|
self.schedule.add(player)
|
2021-03-16 15:36:24 +01:00
|
|
|
x = self.random.randrange(self.grid.width)
|
|
|
|
y = self.random.randrange(self.grid.height)
|
|
|
|
self.grid.place_agent(player, (x, y))
|
2021-03-13 17:41:38 +01:00
|
|
|
for i in range(self.boxes_number):
|
|
|
|
box = Box(i, self)
|
|
|
|
self.schedule.add(box)
|
|
|
|
x = self.random.randrange(self.grid.width)
|
|
|
|
y = self.random.randrange(self.grid.height)
|
2021-03-16 15:36:24 +01:00
|
|
|
try:
|
|
|
|
self.grid.place_agent(box, (x, y))
|
|
|
|
except:
|
|
|
|
pass
|
2021-03-13 17:41:38 +01:00
|
|
|
|
|
|
|
|
|
|
|
# self.datacollector=DataCollector #informacje o stanie planszy, pozycja agenta
|
|
|
|
|
|
|
|
def step(self):
|
|
|
|
self.schedule.step()
|
2021-03-16 23:02:16 +01:00
|
|
|
# self.datacollector.collect(self) #na razie niepotrzebne
|