Skip to content

Commit

Permalink
Refactor: Remove step/agent_act function from MoneyAgent class
Browse files Browse the repository at this point in the history
  • Loading branch information
Spartan-71 authored and tpike3 committed Nov 25, 2024
1 parent ced8a7f commit ca53a86
Showing 1 changed file with 5 additions and 25 deletions.
30 changes: 5 additions & 25 deletions docs/tutorials/intro_tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -682,17 +682,6 @@
" self.wealth -= 1\n",
"```\n",
"\n",
"And with those two methods, the agent's ``agent_act`` method becomes:\n",
"\n",
"```python\n",
"class MoneyAgent(mesa.Agent):\n",
" # ...\n",
" def agent_act(self):\n",
" self.move()\n",
" if self.wealth > 0:\n",
" self.give_money()\n",
"```\n",
"\n",
"Now, putting that all together should look like this:"
]
},
Expand Down Expand Up @@ -725,11 +714,6 @@
" other_agent.wealth += 1\n",
" self.wealth -= 1\n",
"\n",
" def agent_act(self):\n",
" self.move()\n",
" if self.wealth > 0:\n",
" self.give_money()\n",
"\n",
"\n",
"class MoneyModel(mesa.Model):\n",
" \"\"\"A model with some number of agents.\"\"\"\n",
Expand All @@ -748,7 +732,8 @@
" self.grid.place_agent(a, (x, y))\n",
"\n",
" def step(self):\n",
" self.agents.shuffle_do(\"agent_act\")"
" self.agents.shuffle_do(\"move\")\n",
" self.agents.do(\"give_money\")"
]
},
{
Expand Down Expand Up @@ -867,13 +852,7 @@
" other = self.random.choice(cellmates)\n",
" other.wealth += 1\n",
" self.wealth -= 1\n",
"\n",
" # There are several ways in which one can combine functions to execute the model\n",
" def agent_act(self):\n",
" self.move()\n",
" if self.wealth > 0:\n",
" self.give_money()\n",
"\n",
" \n",
"\n",
"class MoneyModel(mesa.Model):\n",
" \"\"\"A model with some number of agents.\"\"\"\n",
Expand All @@ -898,7 +877,8 @@
"\n",
" def step(self):\n",
" self.datacollector.collect(self)\n",
" self.agents.shuffle_do(\"agent_act\")"
" self.agents.shuffle_do(\"move\")\n",
" self.agents.do(\"give_money\")"
]
},
{
Expand Down

0 comments on commit ca53a86

Please sign in to comment.