Skip to content

Commit b20dc56

Browse files
houssam7737houssam-kenshopre-commit-ci[bot]
authored andcommitted
Fix bug boltzman model agent giving money to itself (#28)
* fix bug where agent gives money to itself in the boltzmann model example * [pre-commit.ci] auto fixes from pre-commit.com hooks --------- Co-authored-by: Houssam Kherraz <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 19a2d3e commit b20dc56

File tree

1 file changed

+4
-1
lines changed
  • examples/boltzmann_wealth_model/boltzmann_wealth_model

1 file changed

+4
-1
lines changed

examples/boltzmann_wealth_model/boltzmann_wealth_model/model.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ def move(self):
6262

6363
def give_money(self):
6464
cellmates = self.model.grid.get_cell_list_contents([self.pos])
65-
if len(cellmates) > 1:
65+
cellmates.pop(
66+
cellmates.index(self)
67+
) # Ensure agent is not giving money to itself
68+
if len(cellmates) > 0:
6669
other = self.random.choice(cellmates)
6770
other.wealth += 1
6871
self.wealth -= 1

0 commit comments

Comments
 (0)