# New composition written after the core abstractions; no library changes needed.
import argparse
from pathlib import Path
from hearth.components.building import Blueprint, RoomSpec
from hearth.programs import building_scene
from hearth.randomness import Scope
from hearth.persistence import export_scene


def build(seed):
    rng = Scope(seed).stream('courtyard')
    ring = ((0, 0), (1, 0), (2, 0), (2, 1), (2, 2), (1, 2), (0, 2), (0, 1))
    functions = ('living', 'library', 'workshop', 'storage', 'kitchen', 'bedroom', 'bedroom', 'storage')
    rooms = [RoomSpec(x, z, 0, purpose) for (x, z), purpose in zip(ring, functions)]
    for x, z in rng.sample(((0, 0), (2, 0), (0, 2), (2, 2)), rng.choice((1, 2))):
        rooms.append(RoomSpec(x, z, 1, 'bedroom'))
    return building_scene(Blueprint(tuple(rooms), bay=9, porch=True, roof_axis='auto'), seed)


if __name__ == '__main__':
    p = argparse.ArgumentParser()
    p.add_argument('--seed', type=int, default=0)
    p.add_argument('--output', type=Path, default=Path('samples/courtyard.litematic'))
    a = p.parse_args()
    export_scene(build(a.seed), a.output)
