y
This commit is contained in:
commit
d71c7b6788
2 changed files with 94 additions and 0 deletions
52
crypto.py
Normal file
52
crypto.py
Normal file
|
@ -0,0 +1,52 @@
|
|||
import random
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
# Game parameters
|
||||
# Start price of coin
|
||||
coin_price = 100.0
|
||||
price_sensitivity = 0.5
|
||||
volatility = 0.3
|
||||
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! Type +10 to buy or -10 to sell.")
|
||||
print("Type 'exit' to stop the game.\n")
|
||||
|
||||
while True:
|
||||
print(f"\nCurrent Coin Price: {round(coin_price, 2)}")
|
||||
|
||||
user_input = input("Enter buy/sell amount (e.g., +10 or -10): ").strip()
|
||||
if user_input.lower() == "exit":
|
||||
print("👋 Game Over. Thanks for playing!")
|
||||
break
|
||||
|
||||
try:
|
||||
trade_amount = int(user_input)
|
||||
except ValueError:
|
||||
print("⚠️ Please enter a valid number like +10 or -5.")
|
||||
continue
|
||||
|
||||
user_intput = 10
|
||||
|
||||
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()
|
||||
|
42
test.py
Normal file
42
test.py
Normal file
|
@ -0,0 +1,42 @@
|
|||
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()
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue