Still some really weird behaviour, but stock trading is working a bit better now than before.
This commit is contained in:
parent
24951b36be
commit
fd647c2407
6
main.py
6
main.py
@ -148,6 +148,7 @@ class Market:
|
||||
self.trend_factor = self.generate_market_trend()
|
||||
self.update_economic_indicators()
|
||||
self.handle_market_events()
|
||||
|
||||
def calculate_price_change(self, product):
|
||||
demand_factor = self.total_bought[product] - self.total_sold[product]
|
||||
# Here you can define how strongly demand affects the price, e.g., 0.05 as in your original code
|
||||
@ -463,13 +464,13 @@ class Company:
|
||||
total_value = stock_price * amount
|
||||
|
||||
if action == 'buy':
|
||||
return self._buy_stock(company_id, amount, total_value, is_ai)
|
||||
return self._buy_stock(company_id, amount)
|
||||
elif action == 'sell':
|
||||
return self._sell_stock(company_id, amount, total_value, is_ai)
|
||||
else:
|
||||
return "Invalid stock action."
|
||||
|
||||
def _buy_stock(self, company_id, amount, total_value, is_ai):
|
||||
def _buy_stock(self, company_id, amount):
|
||||
# Calculate the total number of shares currently owned
|
||||
total_shares_owned = sum(self._market.companies[company_id].own_stock_ownership.values())
|
||||
available_shares = self.total_shares - total_shares_owned
|
||||
@ -487,7 +488,6 @@ class Company:
|
||||
self._market.update_stock_ledger(company_id, self.player_id, amount)
|
||||
|
||||
if company_id != self.player_id:
|
||||
# Update buyer's stock_holdings for investments in other companies
|
||||
self.stock_holdings[company_id] += amount
|
||||
else:
|
||||
# Update own_stock_ownership when buying own shares
|
||||
|
||||
Loading…
Reference in New Issue
Block a user