@@ -65,29 +65,26 @@ def __init__(self, model, moore, bank, rich_threshold):
6565 def do_business (self ):
6666 """check if person has any savings, any money in wallet, or if the
6767 bank can loan them any money"""
68- if self .savings > 0 or self .wallet > 0 or self .bank .bank_to_loan > 0 :
68+ if ( self .savings > 0 or self .wallet > 0 or self .bank .bank_to_loan > 0 ) and len ( self . cell . agents ) > 1 :
6969 # create list of people at my location (includes self)
70-
71- # check if other people are at my location
72- if len (self .cell .agents ) > 1 :
73- # set customer to self for while loop condition
74- customer = self
75- while customer == self :
76- customer = self .random .choice (self .cell .agents )
77- # 50% chance of trading with customer
70+ # set customer to self for while loop condition
71+ customer = self
72+ while customer == self :
73+ customer = self .random .choice (self .cell .agents )
74+ # 50% chance of trading with customer
75+ if self .random .randint (0 , 1 ) == 0 :
76+ # 50% chance of trading $5
7877 if self .random .randint (0 , 1 ) == 0 :
79- # 50% chance of trading $5
80- if self .random .randint (0 , 1 ) == 0 :
81- # give customer $5 from my wallet
82- # (may result in negative wallet)
83- customer .wallet += 5
84- self .wallet -= 5
85- # 50% chance of trading $2
86- else :
87- # give customer $2 from my wallet
88- # (may result in negative wallet)
89- customer .wallet += 2
90- self .wallet -= 2
78+ # give customer $5 from my wallet
79+ # (may result in negative wallet)
80+ customer .wallet += 5
81+ self .wallet -= 5
82+ # 50% chance of trading $2
83+ else :
84+ # give customer $2 from my wallet
85+ # (may result in negative wallet)
86+ customer .wallet += 2
87+ self .wallet -= 2
9188
9289 def balance_books (self ):
9390 # check if wallet is negative from trading with customer
0 commit comments