42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
import random
|
|
import matplotlib.pyplot as plt
|
|
|
|
# Game parameters
|
|
coin_price = 100.0
|
|
price_sensitivity = 0.5 # How much the price reacts to user demand
|
|
volatility = 0.3 # Maximum % of price change due to randomness
|
|
price_history = [coin_price]
|
|
|
|
def save_graph():
|
|
plt.clf()
|
|
plt.plot(price_history, label="Coin Price")
|
|
plt.title("Coin Price Over Time")
|
|
plt.xlabel("Turn")
|
|
plt.ylabel("Price")
|
|
plt.legend()
|
|
plt.grid(True)
|
|
plt.savefig("coin_price.png")
|
|
print("📊 Graph saved as 'coin_price.png'")
|
|
|
|
print("💰 Welcome to Crypto Kids! Simulating user input of 0 each round for testing purposes.\n")
|
|
|
|
# Run for 10 rounds
|
|
for turn in range(1, 21):
|
|
print(f"\nTurn {turn} - Current Coin Price: {round(coin_price, 2)}")
|
|
|
|
# Simulated user input: always 0
|
|
trade_amount = 0
|
|
print(f"Simulated input: {trade_amount}")
|
|
|
|
buys = trade_amount if trade_amount > 0 else 0
|
|
sells = -trade_amount if trade_amount < 0 else 0
|
|
net_demand = buys - sells
|
|
|
|
price_change_from_demand = net_demand * price_sensitivity
|
|
random_factor = random.uniform(-volatility, volatility) * coin_price
|
|
coin_price += price_change_from_demand + random_factor
|
|
coin_price = max(1, coin_price)
|
|
|
|
price_history.append(coin_price)
|
|
save_graph()
|
|
|