#!/usr/bin/env python3
"""
CraftCore: Universal crafting engine.
A + B = C. O(1) lookup. No spreadsheet. No database. Just a hash table.

No dependencies. Pure Python.
"""
import time

# === THE LATTICE: 50 crafting recipes ===
RECIPES = {
    ("wood", "stone"): "stone_axe",
    ("iron", "wood"): "iron_sword",
    ("iron", "stone"): "hammer",
    ("wood", "iron"): "iron_pickaxe",
    ("leather", "wood"): "wood_bow",
    ("string", "wood"): "wood_bow",
    ("leather", "string"): "leather_armor",
    ("iron", "leather"): "iron_armor",
    ("diamond", "stick"): "diamond_sword",
    ("diamond", "wood"): "diamond_pickaxe",
    ("gold", "stick"): "gold_sword",
    ("gold", "wood"): "gold_pickaxe",
    ("obsidian", "diamond"): "obsidian_blade",
    ("netherite", "diamond"): "netherite_sword",
    ("fire", "wood"): "torch",
    ("fire", "iron"): "heated_iron",
    ("water", "fire"): "steam",
    ("water", "dirt"): "mud",
    ("water", "seed"): "planted_seed",
    ("seed", "dirt"): "planted_seed",
    ("planted_seed", "water"): "growing_plant",
    ("growing_plant", "time"): "harvest",
    ("wheat", "water"): "dough",
    ("dough", "fire"): "bread",
    ("flour", "water"): "dough",
    ("flour", "egg"): "cake_batter",
    ("cake_batter", "fire"): "cake",
    ("sugar", "egg"): "cake_batter",
    ("cocoa", "milk"): "chocolate",
    ("milk", "sugar"): "sweet_milk",
    ("apple", "sugar"): "candy",
    ("pumpkin", "fire"): "pumpkin_pie",
    ("egg", "fire"): "fried_egg",
    ("fish", "fire"): "cooked_fish",
    ("beef", "fire"): "steak",
    ("pork", "fire"): "bacon",
    ("chicken", "fire"): "roasted_chicken",
    ("wood", "wood"): "planks",
    ("planks", "planks"): "crafting_table",
    ("cobblestone", "cobblestone"): "furnace",
    ("iron_ingot", "iron_ingot"): "iron_block",
    ("gold_ingot", "gold_ingot"): "gold_block",
    ("diamond", "diamond"): "diamond_block",
    ("emerald", "emerald"): "emerald_block",
    ("redstone", "redstone"): "redstone_block",
    ("glass", "glass"): "glass_pane",
    ("stick", "stick"): "ladder",
    ("paper", "paper"): "book",
    ("book", "leather"): "enchanted_book",
    ("arrow", "feather"): "flight_arrow"
}

ITEM_TYPES = {
    "stone_axe": "tool", "iron_sword": "weapon", "hammer": "tool",
    "iron_pickaxe": "tool", "wood_bow": "weapon", "leather_armor": "armor",
    "iron_armor": "armor", "diamond_sword": "weapon", "diamond_pickaxe": "tool",
    "gold_sword": "weapon", "gold_pickaxe": "tool", "obsidian_blade": "weapon",
    "netherite_sword": "weapon", "torch": "light", "heated_iron": "material",
    "steam": "effect", "mud": "material", "planted_seed": "item",
    "growing_plant": "item", "harvest": "food", "dough": "food",
    "bread": "food", "flour": "material", "cake_batter": "food",
    "cake": "food", "chocolate": "food", "sweet_milk": "food",
    "candy": "food", "pumpkin_pie": "food", "fried_egg": "food",
    "cooked_fish": "food", "steak": "food", "bacon": "food",
    "roasted_chicken": "food", "planks": "material", "crafting_table": "block",
    "furnace": "block", "iron_block": "block", "gold_block": "block",
    "diamond_block": "block", "emerald_block": "block",
    "redstone_block": "block", "glass_pane": "block", "ladder": "block",
    "book": "item", "enchanted_book": "magic", "flight_arrow": "weapon"
}

ITEM_ICONS = {
    "stone_axe": "[STONE AXE]", "iron_sword": "[IRON SWD]", "hammer": "[HAMMR]",
    "iron_pickaxe": "[IRON PCK]", "wood_bow": "[WOOD BOW]", "leather_armor": "[LTHR ARM]",
    "iron_armor": "[IRON ARM]", "diamond_sword": "[DMND SWD]", "diamond_pickaxe": "[DMND PCK]",
    "gold_sword": "[GOLD SWD]", "gold_pickaxe": "[GOLD PCK]", "obsidian_blade": "[OBS BLADE]",
    "netherite_sword": "[NETH SWD]", "torch": "[TORCH]", "heated_iron": "[HOT IRON]",
    "steam": "[STEAM!]", "mud": "[MUD]", "planted_seed": "[PLANTED]",
    "growing_plant": "[GROWING]", "harvest": "[HARVEST]", "dough": "[DOUGH]",
    "bread": "[BREAD]", "flour": "[FLOUR]", "cake_batter": "[BATTER]",
    "cake": "[CAKE!]", "chocolate": "[CHOC]", "sweet_milk": "[MILK]",
    "candy": "[CANDY]", "pumpkin_pie": "[PIE]", "fried_egg": "[EGG]",
    "cooked_fish": "[FISH]", "steak": "[STEAK]", "bacon": "[BACON]",
    "roasted_chicken": "[CHK]", "planks": "[PLNKS]", "crafting_table": "[TBL]",
    "furnace": "[FRNC]", "iron_block": "[FE BLK]", "gold_block": "[AU BLK]",
    "diamond_block": "[DM BLK]", "emerald_block": "[EM BLK]",
    "redstone_block": "[RS BLK]", "glass_pane": "[GLASS]", "ladder": "[LADDER]",
    "book": "[BOOK]", "enchanted_book": "[ENCH BOOK]", "flight_arrow": "[ARROW]"
}

def craft(item_a: str, item_b: str) -> str:
    """A + B = C. O(1) lookup."""
    result = RECIPES.get((item_a, item_b), RECIPES.get((item_b, item_a), "nothing"))
    return result

def item_info(item: str) -> dict:
    """O(1) item metadata."""
    return {
        "name": item,
        "type": ITEM_TYPES.get(item, "unknown"),
        "icon": ITEM_ICONS.get(item, f"[{item.upper()}]")
    }

# === DEMO ===
def demo():
    print("=" * 50)
    print("  CraftCore: Universal crafting engine")
    print("=" * 50)
    print()
    print("  RECIPES:")
    print()

    test_combos = [
        ("wood", "stone"), ("iron", "wood"), ("leather", "wood"),
        ("diamond", "stick"), ("fire", "wood"), ("water", "seed"),
        ("dough", "fire"), ("iron_ingot", "iron_ingot"),
        ("wood", "wood"), ("cocoa", "milk"), ("gold", "wood"),
        ("pumpkin", "fire"), ("string", "wood")
    ]

    for a, b in test_combos:
        start = time.perf_counter_ns()
        result = craft(a, b)
        elapsed = time.perf_counter_ns() - start

        if result == "nothing":
            print(f"  {a:12s} + {b:12s} = [nothing]  [{elapsed}ns]")
        else:
            info = item_info(result)
            print(f"  {a:12s} + {b:12s} = {info['icon']:12s} {result} ({info['type']})  [{elapsed}ns]")

    print()
    print("=" * 50)
    print("  50 recipes. 1 file. O(1) craft. Polyglot.")
    print("=" * 50)

if __name__ == "__main__":
    demo()
