59 lines
1.9 KiB
Python
59 lines
1.9 KiB
Python
from mesa import Model, Agent
|
|
from agent import Player
|
|
from mesa.time import RandomActivation
|
|
from mesa.space import MultiGrid
|
|
#from mesa.datacollection import DataCollector
|
|
import random
|
|
|
|
x = 11
|
|
y = 11
|
|
possible_contents = ['gold', 'sword', 'shield', 'potion', 'empty']
|
|
step_counter = 0
|
|
boxes_number = 5
|
|
|
|
|
|
class GameMap(Model):
|
|
def __init__(self, x, y, boxes_number):
|
|
self.grid = MultiGrid(x, y, False)
|
|
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
|
|
player = Player(1, self)
|
|
x = self.random.randrange(self.grid.width)
|
|
y = self.random.randrange(self.grid.height)
|
|
self.grid.place_agent(player, (x, y))
|
|
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)
|
|
try:
|
|
self.grid.place_agent(box, (x, y))
|
|
except:
|
|
pass
|
|
|
|
|
|
# self.datacollector=DataCollector #informacje o stanie planszy, pozycja agenta
|
|
|
|
def step(self):
|
|
self.schedule.step()
|
|
# self.datacollector.collect(self) #na razie niepotrzebne
|
|
|
|
|
|
class Box(Agent):
|
|
def __init__(self, unique_id, model):
|
|
super().__init__(unique_id, model)
|
|
# self.x_coor = random.randrange(1, x + 1) # pola 1-10, zmienić na 0-9?
|
|
# self.y_coor = random.randrange(1, y + 1)
|
|
self.closed = True
|
|
self.content = 'unknown'
|
|
self.isBox=True
|
|
|
|
def open(self):
|
|
self.closed = False
|
|
self.content = random.choice(
|
|
possible_contents) # lepiej od razu przypisać content zamiast w ogóle dawać unknown?
|
|
|
|
def step(self):
|
|
pass
|