Still some really weird behaviour, but stock trading is working a bit better now than before.
This commit is contained in:
parent
2e831adf3a
commit
24951b36be
13
main.py
13
main.py
@ -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:
|
||||||
|
# Update buyer's stock_holdings for investments in other companies
|
||||||
self.stock_holdings[company_id] += amount
|
self.stock_holdings[company_id] += amount
|
||||||
|
else:
|
||||||
# Update the target company's own_stock_ownership to reflect the buyer's new ownership
|
# Update own_stock_ownership when buying own shares
|
||||||
target_company = self._market.companies[company_id]
|
self.own_stock_ownership[self.player_id] += amount
|
||||||
target_company.own_stock_ownership[self.player_id] = target_company.own_stock_ownership.get(self.player_id,
|
|
||||||
0) + amount
|
|
||||||
|
|
||||||
return f"Bought {amount} stocks of {company_id}."
|
return f"Bought {amount} stocks of {company_id}."
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user