本文整理匯總了Python中mesa.space.SingleGrid.remove_agent方法的典型用法代碼示例。如果您正苦於以下問題:Python SingleGrid.remove_agent方法的具體用法?Python SingleGrid.remove_agent怎麽用?Python SingleGrid.remove_agent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類mesa.space.SingleGrid
的用法示例。
在下文中一共展示了SingleGrid.remove_agent方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: TestSingleGrid
# 需要導入模塊: from mesa.space import SingleGrid [as 別名]
# 或者: from mesa.space.SingleGrid import remove_agent [as 別名]
class TestSingleGrid(unittest.TestCase):
def setUp(self):
self.space = SingleGrid(50, 50, False)
self.agents = []
for i, pos in enumerate(TEST_AGENTS_GRID):
a = MockAgent(i, None)
self.agents.append(a)
self.space.place_agent(a, pos)
def test_agent_positions(self):
'''
Ensure that the agents are all placed properly.
'''
for i, pos in enumerate(TEST_AGENTS_GRID):
a = self.agents[i]
assert a.pos == pos
def test_remove_agent(self):
for i, pos in enumerate(TEST_AGENTS_GRID):
a = self.agents[i]
assert a.pos == pos
assert self.space.grid[pos[0]][pos[1]] == a
self.space.remove_agent(a)
assert a.pos is None
assert self.space.grid[pos[0]][pos[1]] is None
def move_agent(self):
agent_number = 0
initial_pos = TEST_AGENTS_GRID[agent_number]
final_pos = (7, 7)
_agent = self.agents[agent_number]
assert _agent.pos == initial_pos
assert self.space.grid[initial_pos[0]][initial_pos[1]] == _agent
assert self.space.grid[final_pos[0]][final_pos[1]] is None
self.space.move_agent(_agent, final_pos)
assert _agent.pos == final_pos
assert self.space.grid[initial_pos[0]][initial_pos[1]] is None
assert self.space.grid[final_pos[0]][final_pos[1]] == _agent