Neue events und print_market_events added
This commit is contained in:
parent
4677ed637e
commit
7b46be7c85
96
main.py
96
main.py
@ -38,6 +38,7 @@ def main():
|
|||||||
for turn in range(1, 27):
|
for turn in range(1, 27):
|
||||||
console.print(f"\n--- Turn {turn} ---\n", style="grey50")
|
console.print(f"\n--- Turn {turn} ---\n", style="grey50")
|
||||||
market.update_market()
|
market.update_market()
|
||||||
|
market.print_market_events()
|
||||||
|
|
||||||
for company in [player] + ai_competitors:
|
for company in [player] + ai_competitors:
|
||||||
company.update_crafting()
|
company.update_crafting()
|
||||||
@ -84,8 +85,15 @@ class Market:
|
|||||||
self.products = {'Coal': 10.0, 'Copper': 15.0, 'Conductor': 20.0}
|
self.products = {'Coal': 10.0, 'Copper': 15.0, 'Conductor': 20.0}
|
||||||
self.starting_prices = self.products.copy()
|
self.starting_prices = self.products.copy()
|
||||||
self.events = load_json('market_events.json')["events"]
|
self.events = load_json('market_events.json')["events"]
|
||||||
self.event_effects = {"double": lambda x: x * 2, "halve": lambda x: x / 2, "increase": lambda x: x + 3.0,
|
self.event_effects = {
|
||||||
"decrease": lambda x: max(1, x - 3.0)}
|
"double": lambda x: x * 2,
|
||||||
|
"halve": lambda x: x / 2,
|
||||||
|
"increase": lambda x: x + 3.0,
|
||||||
|
"decrease": lambda x: max(1, x - 3.0),
|
||||||
|
"tech_boost": self.tech_boost_effect,
|
||||||
|
"resource_scarcity": self.resource_scarcity_effect,
|
||||||
|
"recession": self.recession_effect
|
||||||
|
}
|
||||||
self.stock_ledger = {}
|
self.stock_ledger = {}
|
||||||
self.inflation_rate = 0.05
|
self.inflation_rate = 0.05
|
||||||
self.unemployment_rate = 0.05
|
self.unemployment_rate = 0.05
|
||||||
@ -94,6 +102,85 @@ class Market:
|
|||||||
self.total_bought = {'Coal': 0, 'Copper': 0, 'Conductor': 0}
|
self.total_bought = {'Coal': 0, 'Copper': 0, 'Conductor': 0}
|
||||||
self.total_sold = {'Coal': 0, 'Copper': 0, 'Conductor': 0}
|
self.total_sold = {'Coal': 0, 'Copper': 0, 'Conductor': 0}
|
||||||
self.previous_prices = self.products.copy()
|
self.previous_prices = self.products.copy()
|
||||||
|
self.last_event_name = None
|
||||||
|
|
||||||
|
def print_market_events(self):
|
||||||
|
console = Console()
|
||||||
|
panel_text = Text()
|
||||||
|
|
||||||
|
# Event information
|
||||||
|
panel_text.append(f"Last Market Event: {self.last_event_name}\n")
|
||||||
|
|
||||||
|
# Economic indicators
|
||||||
|
panel_text.append(f"Inflation Rate: {self.inflation_rate:.2f}%\n", style="grey70")
|
||||||
|
panel_text.append(f"Unemployment Rate: {self.unemployment_rate:.2f}%\n", style="grey70")
|
||||||
|
panel_text.append(f"GDP: {self.gdp:.2f} €", style="grey70")
|
||||||
|
|
||||||
|
# Display in a panel
|
||||||
|
console.print(Panel(panel_text, title="[bold]Market Events and Indicators", border_style="grey50"))
|
||||||
|
|
||||||
|
def tech_boost_effect(self):
|
||||||
|
"""
|
||||||
|
Handles the effect of a technological boost in the market.
|
||||||
|
This can increase the price of high-tech products.
|
||||||
|
"""
|
||||||
|
self.products['Conductor'] *= 1.2 # Example: Increase by 20%
|
||||||
|
|
||||||
|
def resource_scarcity_effect(self):
|
||||||
|
"""
|
||||||
|
Handles the effect of resource scarcity in the market.
|
||||||
|
This can increase the price of a random basic resource.
|
||||||
|
"""
|
||||||
|
random_resource = random.choice(['Coal', 'Copper'])
|
||||||
|
self.products[random_resource] *= 1.5 # Example: Increase by 50%
|
||||||
|
|
||||||
|
def regulatory_change_effect(self):
|
||||||
|
"""
|
||||||
|
Handles the effect of a regulatory change in the market.
|
||||||
|
This can either increase or decrease the price of all products.
|
||||||
|
"""
|
||||||
|
change_factor = random.uniform(0.9, 1.1) # Example: Change between -10% to +10%
|
||||||
|
for product in self.products:
|
||||||
|
self.products[product] *= change_factor
|
||||||
|
|
||||||
|
def innovation_breakthrough_effect(self):
|
||||||
|
"""
|
||||||
|
Handles the effect of an innovation breakthrough.
|
||||||
|
This can drastically reduce the production cost of a random product.
|
||||||
|
"""
|
||||||
|
breakthrough_product = random.choice(list(self.products.keys()))
|
||||||
|
self.products[breakthrough_product] *= 0.8 # Example: Reduce by 20%
|
||||||
|
|
||||||
|
def global_event_effect(self):
|
||||||
|
"""
|
||||||
|
Handles the effect of a global event (like a pandemic or economic crisis).
|
||||||
|
This can significantly affect all market prices.
|
||||||
|
"""
|
||||||
|
impact_factor = random.uniform(0.7, 1.3) # Example: Change between -30% to +30%
|
||||||
|
for product in self.products:
|
||||||
|
self.products[product] *= impact_factor
|
||||||
|
|
||||||
|
def tech_boost_effect(self, price):
|
||||||
|
"""Handles the effect of a technology boost event on product prices."""
|
||||||
|
# Example: Increases the price of high-tech products like 'Conductor'
|
||||||
|
return price * 1.2 # Increase by 20%
|
||||||
|
|
||||||
|
def resource_scarcity_effect(self, price):
|
||||||
|
"""Handles the effect of a resource scarcity event on product prices."""
|
||||||
|
# Example: Increase the price of a resource due to scarcity
|
||||||
|
return price * 1.5 # Increase by 50%
|
||||||
|
|
||||||
|
def trade_agreement_effect(self, price):
|
||||||
|
"""Handles the effect of a new trade agreement event."""
|
||||||
|
return price * 0.9
|
||||||
|
|
||||||
|
def innovation_breakthrough_effect(self, price):
|
||||||
|
"""Handles the effect of an innovation breakthrough event."""
|
||||||
|
return price * 0.8
|
||||||
|
|
||||||
|
def recession_effect(self, price):
|
||||||
|
"""Handles the effect of a recession event on product prices."""
|
||||||
|
return price * 0.7
|
||||||
|
|
||||||
def update_stock_ledger(self, company_id, owner_id, amount):
|
def update_stock_ledger(self, company_id, owner_id, amount):
|
||||||
"""Updates the stock ledger for a given company and owner based on the transaction amount."""
|
"""Updates the stock ledger for a given company and owner based on the transaction amount."""
|
||||||
@ -110,6 +197,7 @@ class Market:
|
|||||||
def update_market(self):
|
def update_market(self):
|
||||||
self.current_turn += 1
|
self.current_turn += 1
|
||||||
self.previous_prices = self.products.copy()
|
self.previous_prices = self.products.copy()
|
||||||
|
|
||||||
# Adjust prices based on demand
|
# Adjust prices based on demand
|
||||||
for product in self.products.keys():
|
for product in self.products.keys():
|
||||||
demand_factor = self.total_bought[product] - self.total_sold[product]
|
demand_factor = self.total_bought[product] - self.total_sold[product]
|
||||||
@ -125,11 +213,13 @@ class Market:
|
|||||||
|
|
||||||
# Handle market events
|
# Handle market events
|
||||||
event = random.choices(self.events, weights=[e["probability"] for e in self.events])[0]
|
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"]:
|
if event["effect"] in ["new_competitor", "exit_competitor"]:
|
||||||
self.handle_competitor_event(event["effect"])
|
self.handle_competitor_event(event["effect"])
|
||||||
else:
|
else:
|
||||||
self.products = {k: self.event_effects[event["effect"]](v) for k, v in self.products.items()}
|
self.products = {k: self.event_effects[event["effect"]](v) for k, v in self.products.items()}
|
||||||
|
|
||||||
|
# Update other economic indicators after processing the event
|
||||||
self.update_economic_indicators()
|
self.update_economic_indicators()
|
||||||
|
|
||||||
def reset_trade_volumes(self):
|
def reset_trade_volumes(self):
|
||||||
@ -373,7 +463,7 @@ class Company:
|
|||||||
|
|
||||||
def make_decision(self, market, competitors):
|
def make_decision(self, market, competitors):
|
||||||
console = Console()
|
console = Console()
|
||||||
status_table = Table(title=f"[bold cyan]{self.player_id}'s Turn - Turn {market.current_turn}", box=box.ROUNDED)
|
status_table = Table(title=f"\n[bold cyan]{self.player_id}'s Turn - Turn {market.current_turn}", box=box.ROUNDED)
|
||||||
|
|
||||||
# Cash Row
|
# Cash Row
|
||||||
status_table.add_column("Category", style="bold cyan")
|
status_table.add_column("Category", style="bold cyan")
|
||||||
|
|||||||
@ -1,7 +1,11 @@
|
|||||||
{ "events": [
|
{
|
||||||
|
"events": [
|
||||||
{ "name": "Boom in market", "probability": 0.1, "effect": "double" },
|
{ "name": "Boom in market", "probability": 0.1, "effect": "double" },
|
||||||
{ "name": "Market crash", "probability": 0.05, "effect": "halve" },
|
{ "name": "Market crash", "probability": 0.05, "effect": "halve" },
|
||||||
{ "name": "Minor market increase", "probability": 0.2, "effect": "increase" },
|
{ "name": "Minor market increase", "probability": 0.2, "effect": "increase" },
|
||||||
{ "name": "Minor market decrease", "probability": 0.2, "effect": "decrease" }
|
{ "name": "Minor market decrease", "probability": 0.2, "effect": "decrease" },
|
||||||
|
{ "name": "Technological Breakthrough", "probability": 0.05, "effect": "tech_boost" },
|
||||||
|
{ "name": "Resource Scarcity", "probability": 0.07, "effect": "resource_scarcity" },
|
||||||
|
{ "name": "Global Recession", "probability": 0.05, "effect": "recession" }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user