Of course! Here is a Python script that generates simulated monthly leaderboard movement.
Key Features of this Generator:
Customizable: You can easily change the list of players, the number of months to simulate, and the range of score changes.
Clear Output: The output is formatted into a clean, readable table for each month.
Movement Indicators: It visually shows whether a player has moved up (▲), moved down (▼), or stayed in the same position (–). For the first month, it indicates a new position (★).
Realistic Fluctuation: The score changes are random within a defined range, simulating a dynamic environment where players can have good or bad months.
The Python Script
python
import random
# --- Configuration ---
PLAYERS = [
"Alex", "Ben", "Charlie", "Dana", "Eli", "Fiona",
"George", "Hannah", "Ivan", "Jasmine", "Kevin", "Luna"
]
SIMULATION_MONTHS = 6 # Number of months to simulate
INITIAL_SCORE_MIN = 800
INITIAL_SCORE_MAX = 1200
MONTHLY_SCORE_CHANGE_MIN = -75 # A player can lose points
MONTHLY_SCORE_CHANGE_MAX = 150 # A player can gain more points than they lose
# --- Main Logic ---
def get_movement_display(new_rank, old_rank):
"""Generates a formatted string for rank movement."""
if old_rank == 0: # Player is new to the leaderboard
return "★ (new)"
change = old_rank - new_rank
if change > 0:
return f"▲ {change}"
elif change < 0:
return f"▼ {abs(change)}"
else:
return "–"
def run_leaderboard_simulation():
"""Generates and prints monthly leaderboard movements."""
# 1. Initialize the leaderboard with starting scores
leaderboard = []
for player_name in PLAYERS:
leaderboard.append({
"name": player_name,
"score": random.randint(INITIAL_SCORE_MIN, INITIAL_SCORE_MAX),
"rank": 0, # Will be set after the first sort
"previous_rank": 0 # 0 indicates no previous rank
})
month_names = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"]
# 2. Loop through each month to simulate changes
for i in range(SIMULATION_MONTHS):
current_month_name = month_names[i % 12]
# Store previous ranks in a simple dictionary for easy lookup
# This is the "snapshot" of the state before this month's changes
previous_ranks = {player['name']: player['rank'] for player in leaderboard}
# Update scores for the current month
for player in leaderboard:
score_change = random.randint(MONTHLY_SCORE_CHANGE_MIN, MONTHLY_SCORE_CHANGE_MAX)
player['score'] += score_change
# Ensure score doesn't go below zero
player['score'] = max(0, player['score'])
# Update their previous rank from the snapshot
player['previous_rank'] = previous_ranks.get(player['name'], 0)
# Sort the leaderboard by the new scores in descending order
leaderboard.sort(key=lambda p: p['score'], reverse=True)
# Update the rank for each player after sorting
for rank_idx, player in enumerate(leaderboard, 1):
player['rank'] = rank_idx
# 3. Print the leaderboard for the current month
print(f"\n╔{'═' * 50}╗")
print(f"║ LEADERBOARD - {current_month_name.upper()} ║")
print(f"╠{'═' * 50}╣")
print(f"║ {'Rank':<5} | {'Movement':<10} | {'Player':<15} | {'Score':<10} ║")
print(f"╠{'─' * 7}+{'─' * 12}+{'─' * 17}+{'─' * 12}╣")
for player in leaderboard:
rank_str = f"#{player['rank']}"
movement_str = get_movement_display(player['rank'], player['previous_rank'])
score_str = f"{player['score']:,}"
print(f"║ {rank_str:<5} | {movement_str:<10} | {player['name']:<15} | {score_str:<10} ║")
print(f"╚{'═' * 50}╝")
# Add a small delay for better visual flow in a terminal
import time
time.sleep(1)
# --- Run the simulation ---
if __name__ == "__main__":
run_leaderboard_simulation()
How to Use the Script
Save the code: Save the code above as a Python file (e.g., leaderboard_generator.py).
Run from your terminal:
bash
python leaderboard_generator.py
Observe the output: The script will print a formatted leaderboard for each simulated month, showing the rank, movement, player name, and score.