fixed economic indicators
This commit is contained in:
parent
7b46be7c85
commit
e5b7709ce3
43
main.py
43
main.py
@ -95,9 +95,11 @@ class Market:
|
||||
"recession": self.recession_effect
|
||||
}
|
||||
self.stock_ledger = {}
|
||||
self.inflation_rate = 0.05
|
||||
self.unemployment_rate = 0.05
|
||||
self.inflation_rate = 0.05 # Initial inflation rate
|
||||
self.inflation_growing = True # Start with inflation growing
|
||||
self.inflation_change = random.uniform(0.0001, 0.001) # Initial change rate self.unemployment_rate = 0.05
|
||||
self.gdp = 500000
|
||||
self.unemployment_rate = 0.04
|
||||
self.trade_volume = 0
|
||||
self.total_bought = {'Coal': 0, 'Copper': 0, 'Conductor': 0}
|
||||
self.total_sold = {'Coal': 0, 'Copper': 0, 'Conductor': 0}
|
||||
@ -199,24 +201,21 @@ class Market:
|
||||
self.previous_prices = self.products.copy()
|
||||
|
||||
# Adjust prices based on demand
|
||||
for product in self.products.keys():
|
||||
for product in self.products:
|
||||
demand_factor = self.total_bought[product] - self.total_sold[product]
|
||||
self.products[product] *= (1 + demand_factor * 0.05)
|
||||
|
||||
self.reset_trade_volumes()
|
||||
|
||||
# Update GDP
|
||||
self.gdp += self.trade_volume * 0.1 # Example formula
|
||||
self.trade_volume = 0
|
||||
# Update inflation rate with random fluctuation
|
||||
self.inflation_rate = random.uniform(-0.001, 0.05)
|
||||
|
||||
# Update inflation rate
|
||||
self.inflation_rate += (self.gdp / 500000 - 1) * 0.05 # Example adjustment
|
||||
# GDP update logic - refined for more controlled growth
|
||||
self.gdp *= (1 + self.inflation_rate / 2)
|
||||
|
||||
# Handle market events
|
||||
event = random.choices(self.events, weights=[e["probability"] for e in self.events])[0]
|
||||
self.last_event_name = event["name"] # Update the last event name
|
||||
if event["effect"] in ["new_competitor", "exit_competitor"]:
|
||||
self.handle_competitor_event(event["effect"])
|
||||
else:
|
||||
event = random.choices(self.events, weights=[e["probability"] for e in self.events], k=1)[0]
|
||||
self.last_event_name = event["name"]
|
||||
self.products = {k: self.event_effects[event["effect"]](v) for k, v in self.products.items()}
|
||||
|
||||
# Update other economic indicators after processing the event
|
||||
@ -246,9 +245,23 @@ class Market:
|
||||
|
||||
def update_economic_indicators(self):
|
||||
"""Updates key economic indicators like inflation and unemployment rates."""
|
||||
self.inflation_rate = max(0.5, self.inflation_rate + random.uniform(-0.01, 0.01))
|
||||
|
||||
# Check bounds and change state if necessary
|
||||
if self.inflation_rate <= 0.0001: # Lower bound
|
||||
self.inflation_growing = True
|
||||
self.inflation_change = random.uniform(0.0001, 0.001) # Reset change rate
|
||||
elif self.inflation_rate >= 0.049: # Upper bound
|
||||
self.inflation_growing = False
|
||||
self.inflation_change = random.uniform(0.0001, 0.001) # Reset change rate
|
||||
|
||||
# Adjust inflation rate based on the current state
|
||||
if self.inflation_growing:
|
||||
self.inflation_rate += self.inflation_change
|
||||
else:
|
||||
self.inflation_rate -= self.inflation_change
|
||||
|
||||
# Unemployment rate adjustment with random fluctuation
|
||||
self.unemployment_rate = min(max(self.unemployment_rate + random.uniform(-0.005, 0.005), 0), 1)
|
||||
self.gdp += self.gdp * (random.uniform(-0.01, 0.03) + self.inflation_rate)
|
||||
|
||||
def calculate_final_scores(self):
|
||||
"""Calculates and returns final scores for each company based on value and stock ownership."""
|
||||
|
||||
Loading…
Reference in New Issue
Block a user