Skip to content

Commit

Permalink
examples: Convert boid_flockers to simple namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
rht authored and tpike3 committed May 17, 2022
1 parent c82b347 commit 47ee1d8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from mesa.visualization.ModularVisualization import VisualizationElement
import mesa


class SimpleCanvas(VisualizationElement):
class SimpleCanvas(mesa.visualization.VisualizationElement):
local_includes = ["boid_flockers/simple_continuous_canvas.js"]
portrayal_method = None
canvas_height = 500
Expand Down
5 changes: 2 additions & 3 deletions examples/boid_flockers/boid_flockers/boid.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import mesa
import numpy as np

from mesa import Agent


class Boid(Agent):
class Boid(mesa.Agent):
"""
A Boid-style flocker agent.
Expand Down
11 changes: 4 additions & 7 deletions examples/boid_flockers/boid_flockers/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@
Uses numpy arrays to represent vectors.
"""

import mesa
import numpy as np

from mesa import Model
from mesa.space import ContinuousSpace
from mesa.time import RandomActivation

from .boid import Boid


class BoidFlockers(Model):
class BoidFlockers(mesa.Model):
"""
Flocker model class. Handles agent creation, placement and scheduling.
"""
Expand Down Expand Up @@ -47,8 +44,8 @@ def __init__(
self.vision = vision
self.speed = speed
self.separation = separation
self.schedule = RandomActivation(self)
self.space = ContinuousSpace(width, height, True)
self.schedule = mesa.time.RandomActivation(self)
self.space = mesa.space.ContinuousSpace(width, height, True)
self.factors = dict(cohere=cohere, separate=separate, match=match)
self.make_agents()
self.running = True
Expand Down
6 changes: 4 additions & 2 deletions examples/boid_flockers/boid_flockers/server.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from mesa.visualization.ModularVisualization import ModularServer
import mesa

from .model import BoidFlockers
from .SimpleContinuousModule import SimpleCanvas
Expand All @@ -18,4 +18,6 @@ def boid_draw(agent):
"separation": 2,
}

server = ModularServer(BoidFlockers, [boid_canvas], "Boids", model_params)
server = mesa.visualization.ModularServer(
BoidFlockers, [boid_canvas], "Boids", model_params
)

0 comments on commit 47ee1d8

Please sign in to comment.