2021-04-13 23:08:57 +02:00
|
|
|
from mesa import Model
|
|
|
|
from hero import Player
|
|
|
|
from othercharacters import Creature, Box, Wall, dice
|
2021-03-30 14:17:54 +02:00
|
|
|
from armory import WM1, A1, WR1, S1, WM2, A2
|
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-04-13 23:08:57 +02:00
|
|
|
# from mesa.datacollection import DataCollector
|
2021-03-13 17:41:38 +01:00
|
|
|
import random
|
|
|
|
|
2021-03-16 16:06:56 +01:00
|
|
|
x = 10
|
|
|
|
y = 10
|
2021-03-13 17:41:38 +01:00
|
|
|
step_counter = 0
|
2021-04-14 02:48:54 +02:00
|
|
|
boxes_number = 4
|
2021-04-13 23:08:57 +02:00
|
|
|
creatures_number = 5
|
2021-03-13 17:41:38 +01:00
|
|
|
|
|
|
|
|
|
|
|
class GameMap(Model):
|
2021-03-30 23:36:19 +02:00
|
|
|
def __init__(self, x, y):
|
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-30 14:17:54 +02:00
|
|
|
self.creatures_number = creatures_number
|
2021-04-13 23:08:57 +02:00
|
|
|
self.running = True
|
|
|
|
# player = Player(1000, self)
|
|
|
|
player = Player(1000, self, "Janusz", 3, 3, 3, 20, 20, WM1, A1, 0, WR1, S1)
|
2021-03-16 16:06:56 +01:00
|
|
|
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-30 14:17:54 +02:00
|
|
|
|
2021-03-13 17:41:38 +01:00
|
|
|
for i in range(self.boxes_number):
|
|
|
|
box = Box(i, self)
|
2021-04-13 23:08:57 +02:00
|
|
|
# self.schedule.add(box)
|
2021-03-13 17:41:38 +01:00
|
|
|
x = self.random.randrange(self.grid.width)
|
|
|
|
y = self.random.randrange(self.grid.height)
|
2021-03-30 23:36:19 +02:00
|
|
|
if self.grid.is_cell_empty((x, y)):
|
2021-03-16 15:36:24 +01:00
|
|
|
self.grid.place_agent(box, (x, y))
|
2021-03-30 23:36:19 +02:00
|
|
|
self.schedule.add(box)
|
|
|
|
else:
|
2021-03-16 15:36:24 +01:00
|
|
|
pass
|
2021-03-13 17:41:38 +01:00
|
|
|
|
2021-04-13 23:08:57 +02:00
|
|
|
for i in range(self.boxes_number,
|
|
|
|
self.boxes_number + self.creatures_number): # taki range, żeby każdy agent miał poprawne unique_id
|
|
|
|
# creature = Creature(i, self)
|
|
|
|
creature = Creature(i, self, "Goblin", 1, 1, 1, 1, 1, WM2, A2, dice(6))
|
2021-03-30 14:17:54 +02:00
|
|
|
x = self.random.randrange(self.grid.width)
|
|
|
|
y = self.random.randrange(self.grid.height)
|
2021-03-30 23:36:19 +02:00
|
|
|
if self.grid.is_cell_empty((x, y)):
|
2021-03-30 14:17:54 +02:00
|
|
|
self.grid.place_agent(creature, (x, y))
|
2021-03-30 23:36:19 +02:00
|
|
|
self.schedule.add(creature)
|
|
|
|
else:
|
2021-03-30 14:17:54 +02:00
|
|
|
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-04-13 23:08:57 +02:00
|
|
|
# self.datacollector.collect(self) #na razie niepotrzebne
|