File size: 6,868 Bytes
bbc1784 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | # Copyright (c) 2026 CtrlAltWin Team
"""
Task Definitions β Easy, Medium, Hard difficulty levels.
Each task defines what food items are on the table, what containers are
available, what constraints are active, and how many steps the agent gets.
"""
from __future__ import annotations
from dataclasses import dataclass, field
from typing import List, Optional
from .simulation.engine import Container, FoodItem
from .vlm.classifier import FoodClassifier
@dataclass
class TaskConfig:
"""Configuration for a single task."""
task_id: str
description: str
food_items: List[FoodItem]
containers: List[Container]
constraints: List[str]
max_steps: int
seed: Optional[int] = None
_vlm = FoodClassifier()
def _make_food(id: int, name: str) -> FoodItem:
"""Create a FoodItem from the VLM database."""
attrs = _vlm.classify(name)
return FoodItem(
id=id,
name=name,
food_type=attrs["type"],
volume_ml=attrs["volume_ml"],
temperature=attrs["temperature"],
fragility=attrs["fragility"],
preferred_container=attrs["preferred_container"],
color=attrs.get("color", "unknown"),
special_notes=attrs.get("special_notes", ""),
)
def get_task_config(task_id: str, seed: Optional[int] = None) -> TaskConfig:
"""Get task configuration by ID."""
tasks = {
"easy": _task_easy,
"medium": _task_medium,
"hard": _task_hard,
}
if task_id not in tasks:
raise ValueError(
f"Unknown task_id '{task_id}'. Available: {list(tasks.keys())}"
)
config = tasks[task_id](seed)
return config
def _task_easy(seed: Optional[int] = None) -> TaskConfig:
"""
Task 1 β Basic Packing (Easy)
2 food items, 2 containers. Just match food type to container type.
Rice (solid) β open/deep container, Sambar (liquid) β sealed container.
"""
return TaskConfig(
task_id="easy",
description=(
"Basic Packing: You have 2 food items (rice and sambar) and "
"2 containers (one sealed, one open). Place each food item in "
"a compatible container. Liquids must go in sealed containers."
),
food_items=[
_make_food(1, "rice"),
_make_food(2, "sambar"),
],
containers=[
Container(
id=1,
name="Sealed Round Container",
container_type="sealed_round",
capacity_ml=300,
),
Container(
id=2,
name="Flat Open Container",
container_type="flat_open",
capacity_ml=400,
),
],
constraints=["type_match"],
max_steps=12,
seed=seed,
)
def _task_medium(seed: Optional[int] = None) -> TaskConfig:
"""
Task 2 β Efficient Packing (Medium)
4 food items, 3 containers. Must match types AND avoid overflow.
Hot/cold separation matters.
"""
return TaskConfig(
task_id="medium",
description=(
"Efficient Packing: You have 4 food items (rice, sambar, chapati, "
"pickle) and 3 containers. Place each item correctly:\n"
"- Match food type to container type (liquids β sealed)\n"
"- Don't overflow containers (check volumes!)\n"
"- Keep hot and cold items separate"
),
food_items=[
_make_food(1, "rice"),
_make_food(2, "sambar"),
_make_food(3, "chapati"),
_make_food(4, "pickle"),
],
containers=[
Container(
id=1,
name="Sealed Round Container",
container_type="sealed_round",
capacity_ml=200,
),
Container(
id=2,
name="Flat Open Container",
container_type="flat_open",
capacity_ml=300,
),
Container(
id=3,
name="Deep Box Container",
container_type="deep_box",
capacity_ml=350,
),
],
constraints=["type_match", "no_overflow", "temperature_separation"],
max_steps=20,
seed=seed,
)
def _task_hard(seed: Optional[int] = None) -> TaskConfig:
"""
Task 3 β Smart Packing (Hard)
6 food items, 4 containers. Full constraint set:
type match, overflow, temperature, fragility, flavor mixing.
Key challenges:
- Curd (cold) β hot items in same container
- Papad (fragility=0.9) must not be crushed
- Curry + sambar both liquid+hot β total 300ml but sealed_round only 250ml!
- Must split liquids across containers
"""
return TaskConfig(
task_id="hard",
description=(
"Smart Packing: You have 6 food items and 4 containers. This is a "
"complex meal with many constraints:\n"
"- Match food type to container type\n"
"- Don't overflow (watch the math!)\n"
"- Separate hot and cold items\n"
"- Don't crush fragile items (papad, chapati)\n"
"- Consider flavor isolation (pickle, chutney)\n"
"\nItems: rice, sambar, curd, chapati, papad, curry\n"
"Containers: sealed_round (250ml), flat_open (200ml), "
"deep_box (400ml), small_sealed (100ml)"
),
food_items=[
_make_food(1, "rice"),
_make_food(2, "sambar"),
_make_food(3, "curd"),
_make_food(4, "chapati"),
_make_food(5, "papad"),
_make_food(6, "curry"),
],
containers=[
Container(
id=1,
name="Sealed Round Container",
container_type="sealed_round",
capacity_ml=250,
),
Container(
id=2,
name="Flat Open Container",
container_type="flat_open",
capacity_ml=200,
),
Container(
id=3,
name="Deep Box Container",
container_type="deep_box",
capacity_ml=400,
),
Container(
id=4,
name="Small Sealed Container",
container_type="small_sealed",
capacity_ml=100,
),
],
constraints=[
"type_match",
"no_overflow",
"temperature_separation",
"fragility_ordering",
"flavor_isolation",
],
max_steps=30,
seed=seed,
)
def list_tasks() -> List[str]:
"""Return list of available task IDs."""
return ["easy", "medium", "hard"]
|