Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] authored and tpike3 committed Jan 29, 2024
1 parent 062f46a commit 2dc485f
Showing 1 changed file with 32 additions and 19 deletions.
51 changes: 32 additions & 19 deletions benchmarks/WolfSheep/wolf_sheep.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@
Center for Connected Learning and Computer-Based Modeling,
Northwestern University, Evanston, IL.
"""
import math

from mesa import Model, Agent
from mesa import Agent, Model
from mesa.space import MultiGrid
from mesa.time import RandomActivationByType


class Animal(Agent):

def __init__(self, unique_id, model, moore, energy, p_reproduce, energy_from_food):
super().__init__(unique_id, model)
self.energy = energy
Expand All @@ -33,7 +31,12 @@ def random_move(self):
def spawn_offspring(self):
self.energy /= 2
offspring = self.__class__(
self.model.next_id(), self.model, self.moore, self.energy, self.p_reproduce, self.energy_from_food
self.model.next_id(),
self.model,
self.moore,
self.energy,
self.p_reproduce,
self.energy_from_food,
)
self.model.grid.place_agent(offspring, self.pos)
self.model.schedule.add(offspring)
Expand Down Expand Up @@ -72,6 +75,7 @@ def feed(self):
self.energy += self.energy_from_food
grass_patch.fully_grown = False


class Wolf(Animal):
"""
A wolf that walks around, reproduces (asexually) and eats sheep.
Expand Down Expand Up @@ -123,18 +127,18 @@ class WolfSheep(Model):
"""

def __init__(
self,
seed,
height,
width,
initial_sheep,
initial_wolves,
sheep_reproduce,
wolf_reproduce,
grass_regrowth_time,
wolf_gain_from_food=13,
sheep_gain_from_food=5,
moore=False
self,
seed,
height,
width,
initial_sheep,
initial_wolves,
sheep_reproduce,
wolf_reproduce,
grass_regrowth_time,
wolf_gain_from_food=13,
sheep_gain_from_food=5,
moore=False,
):
"""
Create a new Wolf-Sheep model with the given parameters.
Expand Down Expand Up @@ -168,7 +172,14 @@ def __init__(
self.random.randrange(self.height),
)
energy = self.random.randrange(2 * sheep_gain_from_food)
sheep = Sheep(self.next_id(), self, moore, energy, sheep_reproduce, sheep_gain_from_food)
sheep = Sheep(
self.next_id(),
self,
moore,
energy,
sheep_reproduce,
sheep_gain_from_food,
)
self.grid.place_agent(sheep, pos)
self.schedule.add(sheep)

Expand All @@ -179,7 +190,9 @@ def __init__(
self.random.randrange(self.height),
)
energy = self.random.randrange(2 * wolf_gain_from_food)
wolf = Wolf(self.next_id(), self, moore, energy, wolf_reproduce, wolf_gain_from_food)
wolf = Wolf(
self.next_id(), self, moore, energy, wolf_reproduce, wolf_gain_from_food
)
self.grid.place_agent(wolf, pos)
self.schedule.add(wolf)

Expand Down Expand Up @@ -207,4 +220,4 @@ def step(self):
start_time = time.perf_counter()
for _ in range(100):
model.step()
print("Time:", time.perf_counter() - start_time)
print("Time:", time.perf_counter() - start_time)

0 comments on commit 2dc485f

Please sign in to comment.