import pandas as pd
import numpy as np
import random
import os

# Create directory for dataset
os.makedirs("data", exist_ok=True)

# Generate synthetic game data
np.random.seed(42)
n_samples = 1000
player_level = np.random.randint(1, 50, n_samples)  # Player level
game_time = np.random.uniform(0, 3600, n_samples)  # Time in game (seconds)
score = np.random.randint(0, 10000, n_samples)  # Player score
action_history = np.random.uniform(0, 1, n_samples)  # Simplified action feature

# Simulate next move (0 = attack, 1 = defend, 2 = retreat)
next_move = []
for i in range(n_samples):
    if player_level[i] > 30 and score[i] > 5000:
        prob = [0.6, 0.3, 0.1]  # Favor attack
    else:
        prob = [0.3, 0.4, 0.3]  # Balanced
    next_move.append(np.random.choice([0, 1, 2], p=prob))

# Create DataFrame
data = {
    'player_level': player_level,
    'game_time': game_time,
    'score': score,
    'action_history': action_history,
    'next_move': next_move
}
df = pd.DataFrame(data)
csv_path = "data/game_data.csv"
df.to_csv(csv_path, index=False)
print(f"Created {csv_path} with {len(df)} entries.")

# Print sample
print("\nSample of game_data.csv:")
print(df.head())