#!/usr/bin/env -S uv run --script
"""Demo script to visualize terrain generation."""

from mudlib.render.ansi import colorize_map
from mudlib.world.terrain import World


def main():
    print("Generating world (seed=42, 100x100)...")
    world = World(seed=42, width=100, height=100)

    print("\nTerrain distribution:")
    terrain_counts = {".": 0, "^": 0, "~": 0, "T": 0, ":": 0}
    for y in range(100):
        for x in range(100):
            tile = world.get_tile(x, y)
            terrain_counts[tile] += 1

    for char, name in [
        (".", "grass"),
        ("^", "mountain"),
        ("~", "water"),
        ("T", "forest"),
        (":", "sand"),
    ]:
        count = terrain_counts[char]
        percentage = (count / 10000) * 100
        print(f"  {char} {name:10} {count:5} tiles ({percentage:5.1f}%)")

    print("\nViewport at center (50, 50) - 40x20:")
    viewport = world.get_viewport(50, 50, width=40, height=20)
    colored = colorize_map(viewport)
    print(colored)

    print("\nViewport at (25, 25) - 40x20:")
    viewport = world.get_viewport(25, 25, width=40, height=20)
    colored = colorize_map(viewport)
    print(colored)


if __name__ == "__main__":
    main()
