Still some really weird behaviour, but stock trading is working a bit better now than before.

This commit is contained in:
Isaak Buslovich 2023-11-20 00:21:21 +01:00
parent 2e831adf3a
commit 24951b36be
Signed by: Isaak
GPG Key ID: EEC31D6437FBCC63

15
main.py
View File

@ -193,7 +193,7 @@ class Market:
self.unemployment_rate = max(0, min(self.unemployment_rate + fluctuation, 1)) self.unemployment_rate = max(0, min(self.unemployment_rate + fluctuation, 1))
def handle_market_events(self): def handle_market_events(self):
event = random.choices(self.events, weights=[e["probability"] for e in self.events], k=1)[0] event = random.choices(self.events, weights=[e["probability"] for e in self.events])[0]
self.last_event_name = event["name"] self.last_event_name = event["name"]
getattr(self, event["effect"])() if event["effect"] in dir(self) else None getattr(self, event["effect"])() if event["effect"] in dir(self) else None
@ -486,13 +486,12 @@ class Company:
self.cash -= total_value self.cash -= total_value
self._market.update_stock_ledger(company_id, self.player_id, amount) self._market.update_stock_ledger(company_id, self.player_id, amount)
# Update buyer's stock_holdings if company_id != self.player_id:
self.stock_holdings[company_id] += amount # Update buyer's stock_holdings for investments in other companies
self.stock_holdings[company_id] += amount
# Update the target company's own_stock_ownership to reflect the buyer's new ownership else:
target_company = self._market.companies[company_id] # Update own_stock_ownership when buying own shares
target_company.own_stock_ownership[self.player_id] = target_company.own_stock_ownership.get(self.player_id, self.own_stock_ownership[self.player_id] += amount
0) + amount
return f"Bought {amount} stocks of {company_id}." return f"Bought {amount} stocks of {company_id}."