Skip to content

Commit

Permalink
Add default_val function to NetworkGrid
Browse files Browse the repository at this point in the history
  • Loading branch information
Tortar authored and rht committed Nov 2, 2022
1 parent 8d052a1 commit 79f4e99
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions mesa/space.py
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,12 @@ class NetworkGrid:
def __init__(self, G: Any) -> None:
self.G = G
for node_id in self.G.nodes:
G.nodes[node_id]["agent"] = list()
G.nodes[node_id]["agent"] = self.default_val()

@staticmethod
def default_val() -> list:
"""Default value for a new node."""
return []

def place_agent(self, agent: Agent, node_id: int) -> None:
"""Place a agent in a node."""
Expand Down Expand Up @@ -986,7 +991,7 @@ def remove_agent(self, agent: Agent) -> None:

def is_cell_empty(self, node_id: int) -> bool:
"""Returns a bool of the contents of a cell."""
return not self.G.nodes[node_id]["agent"]
return self.G.nodes[node_id]["agent"] == self.default_val()

def get_cell_list_contents(self, cell_list: list[int]) -> list[GridContent]:
"""Returns the contents of a list of cells ((x,y) tuples)
Expand Down

0 comments on commit 79f4e99

Please sign in to comment.