forked from projectmesa/mesa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathagent.py
44 lines (33 loc) · 1.06 KB
/
agent.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""
The agent class for Mesa framework.
Core Objects: Agent
"""
# Mypy; for the `|` operator purpose
# Remove this __future__ import once the oldest supported Python is 3.10
from __future__ import annotations
from random import Random
# mypy
from typing import TYPE_CHECKING
if TYPE_CHECKING:
# We ensure that these are not imported during runtime to prevent cyclic
# dependency.
from mesa.model import Model
from mesa.space import Position
class Agent:
"""Base class for a model agent."""
def __init__(self, unique_id: int, model: Model) -> None:
"""Create a new agent.
Args:
unique_id (int): A unique numeric identified for the agent
model: (Model): Instance of the model that contains the agent
"""
self.unique_id = unique_id
self.model = model
self.pos: Position | None = None
def step(self) -> None:
"""A single step of the agent."""
def advance(self) -> None:
pass
@property
def random(self) -> Random:
return self.model.random