{"tool": "voxel.exec", "input": {"code": "// MineBench Competitive Build: The Iron Horse\n// A massive, detailed steam locomotive with tender and passenger cars.\n\nconst BLOCK = {\n  IRON: 'iron_block',\n  GOLD: 'gold_block',\n  GLASS: 'glass',\n  STEAM: 'stone',\n  STONE_BRICK: 'stone_bricks',\n  COBBLE: 'cobblestone',\n  WOOD_PLANK: 'oak_planks',\n  WOOD_LOG: 'oak_log',\n  WOOL_RED: 'red_wool',\n  WOOL_BLUE: 'blue_wool',\n  WOOL_GREEN: 'green_wool',\n  WOOL_WHITE: 'white_wool',\n  WOOL_BLACK: 'black_wool',\n  WOOL_YELLOW: 'yellow_wool',\n  WOOL_BROWN: 'brown_wool',\n  COAL: 'gray_wool',\n  DIRT: 'dirt',\n  GRASS: 'grass_block'\n};\n\n// Helper: Set a block if within grid bounds\nfunction place(x, y, z, type) {\n  if (x >= 0 && x < 256 && y >= 0 && y < 256 && z >= 0 && z < 256) {\n    block(x, y, z, type);\n  }\n}\n\n// Helper: Draw a filled ellipse in the XZ plane at height Y\nfunction drawEllipseXZ(cx, cy, cz, rx, rz, rType) {\n  for (let x = cx - rx; x <= cx + rx; x++) {\n    for (let z = cz - rz; z <= cz + rz; z++) {\n      let dx = (x - cx) / rx;\n      let dz = (z - cz) / rz;\n      if (dx * dx + dz * dz <= 1.0) {\n        place(x, cy, z, rType);\n      }\n    }\n  }\n}\n\n// Helper: Draw a ring in the XZ plane (hollow ellipse)\nfunction drawRingXZ(cx, cy, cz, rx, rz, rType) {\n  for (let x = cx - rx; x <= cx + rx; x++) {\n    for (let z = cz - rz; z <= cz + rz; z++) {\n      let dx = (x - cx) / rx;\n      let dz = (z - cz) / rz;\n      let dist = dx * dx + dz * dz;\n      if (dist <= 1.0 && dist >= 0.85) {\n        place(x, cy, z, rType);\n      }\n    }\n  }\n}\n\n// Helper: Draw a filled circle in XY plane at Z\nfunction drawCircleXY(cx, cy, cz, r, rType) {\n  for (let x = cx - Math.ceil(r); x <= cx + Math.ceil(r); x++) {\n    for (let y = cy - Math.ceil(r); y <= cy + Math.ceil(r); y++) {\n      let dx = (x - cx) / r;\n      let dy = (y - cy) / r;\n      if (dx * dx + dy * dy <= 1.0) {\n        place(x, y, cz, rType);\n      }\n    }\n  }\n}\n\n// Helper: Draw a ring in XY plane at Z\nfunction drawRingXY(cx, cy, cz, r, rType) {\n  for (let x = cx - Math.ceil(r); x <= cx + Math.ceil(r); x++) {\n    for (let y = cy - Math.ceil(r); y <= cy + Math.ceil(r); y++) {\n      let dx = (x - cx) / r;\n      let dy = (y - cy) / r;\n      let dist = dx * dx + dy * dy;\n      if (dist <= 1.0 && dist >= 0.85) {\n        place(x, y, cz, rType);\n      }\n    }\n  }\n}\n\n// Helper: Draw a line between two points\nfunction drawLine(x1, y1, z1, x2, y2, z2, type) {\n  let dx = Math.abs(x2 - x1);\n  let dy = Math.abs(y2 - y1);\n  let dz = Math.abs(z2 - z1);\n  let steps = Math.max(dx, Math.max(dy, dz));\n  if (steps === 0) return;\n  \n  for (let i = 0; i <= steps; i++) {\n    let t = i / steps;\n    let x = Math.round(x1 + (x2 - x1) * t);\n    let y = Math.round(y1 + (y2 - y1) * t);\n    let z = Math.round(z1 + (z2 - z1) * t);\n    place(x, y, z, type);\n  }\n}\n\n// Helper: Draw a smooth curve using quadratic bezier approximation\nfunction drawCurve(x0, y0, z0, x1, y1, z1, x2, y2, z2, steps, type) {\n  for (let i = 0; i <= steps; i++) {\n    let t = i / steps;\n    let x = Math.round((1-t)*(1-t)*x0 + 2*(1-t)*t*x1 + t*t*x2);\n    let y = Math.round((1-t)*(1-t)*y0 + 2*(1-t)*t*y1 + t*t*y2);\n    let z = Math.round((1-t)*(1-t)*z0 + 2*(1-t)*t*z1 + t*t*z2);\n    place(x, y, z, type);\n  }\n}\n\n// --- BUILD FUNCTIONS ---\n\nfunction buildTrack(baseZ) {\n  // Rails and sleepers\n  let trackWidth = 4;\n  let trackLength = 800;\n  \n  for (let z = baseZ; z < baseZ + trackLength; z++) {\n    // Sleepers (ties)\n    if ((z - baseZ) % 3 === 0) {\n      box(120, 4, z, 136, 5, z, BLOCK.WOOD_LOG);\n    }\n    \n    // Rails\n    let railY = 6;\n    place(122, railY, z, BLOCK.IRON);\n    place(134, railY, z, BLOCK.IRON);\n    \n    // Ballast (gravel/stone bed)\n    box(118, 3, z - 1, 138, 3, z + 1, BLOCK.STONE);\n    box(119, 4, z - 1, 137, 5, z + 1, BLOCK.COBBLE);\n  }\n}\n\nfunction buildTender(xStart) {\n  let x = xStart;\n  let y = 6;\n  let z = 0; // Local Z for tender\n  \n  // Main body: Coal bunker\n  box(x, y + 2, z, x + 14, y + 8, z + 16, BLOCK.WOOL_BROWN);\n  \n  // Roof\n  for (let dx = 0; dx <= 14; dx++) {\n    for (let dz = 0; dz <= 16; dz++) {\n      let h = Math.floor(Math.sin((dx / 14) * Math.PI) * 2);\n      place(x + dx, y + 8 + h, z + dz, BLOCK.WOOL_BLACK);\n    }\n  }\n  \n  // Coal pile (inside)\n  box(x + 1, y + 3, z + 1, x + 13, y + 7, z + 15, BLOCK.COAL);\n  \n  // Water tanks on sides\n  for (let dz = 0; dz <= 16; dz++) {\n    let w = Math.floor(Math.sin((dz / 16) * Math.PI) * 3);\n    box(x - 2, y + 2, z + dz, x - 2, y + 7, z + dz, BLOCK.IRON);\n    box(x + 16, y + 2, z + dz, x + 16, y + 7, z + dz, BLOCK.IRON);\n  }\n  \n  // Buffer beam\n  box(x, y + 3, z - 1, x + 14, y + 5, z - 1, BLOCK.WOOL_BLACK);\n  place(x + 2, y + 4, z - 2, BLOCK.IRON);\n  place(x + 12, y + 4, z - 2, BLOCK.IRON);\n}\n\nfunction buildEngine(xStart) {\n  let x = xStart;\n  let y = 6; // Wheel base level\n  let z = 0; // Local Z\n  \n  // --- WHEELS ---\n  // 3 sets of driving wheels: Front, Middle, Rear\n  let wheelPositions = [8, 14, 20]; // Relative to engine front x\n  let wheelRadius = 4;\n  \n  for (let wx of wheelPositions) {\n    let cx = x + wx;\n    let cy = y + wheelRadius;\n    \n    // Left Wheel\n    drawRingXY(cx, cy, z - 2, wheelRadius, BLOCK.IRON);\n    place(cx, cy, z - 2, BLOCK.GOLD); // Hub\n    \n    // Right Wheel\n    drawRingXY(cx, cy, z + 2, wheelRadius, BLOCK.IRON);\n    place(cx, cy, z + 2, BLOCK.GOLD); // Hub\n    \n    // Axle connecting them\n    line(cx, cy, z - 2, cx, cy, z + 2, BLOCK.STONE_BRICK);\n  }\n  \n  // --- BOILER ---\n  // Tapered cylinder. Length ~40 blocks. Radius decreases from back to front.\n  let boilerLength = 36;\n  let maxRadius = 7;\n  let minRadius = 5;\n  \n  for (let i = 0; i <= boilerLength; i++) {\n    let t = i / boilerLength;\n    // Radius: wider at back (t=1), narrower at front (t=0)\n    let r = minRadius + (maxRadius - minRadius) * Math.pow(t, 0.5); \n    \n    let cx = x + i;\n    let cy = y + maxRadius; // Center of boiler vertically\n    \n    // Draw slice\n    for (let dx = -Math.ceil(r); dx <= Math.ceil(r); dx++) {\n      for (let dz = -Math.ceil(r); dz <= Math.ceil(r); dz++) {\n        if (dx*dx + dz*dz <= r*r) {\n          place(cx, cy + dx, z + dz, BLOCK.STEAM);\n        }\n      }\n    }\n  }\n  \n  // --- SMOKEBOX (Front of boiler) ---\n  let sbX = x;\n  box(sbX - 2, y + 4, z - 5, sbX - 2, y + 10, z + 5, BLOCK.STEAM);\n  drawCircleXY(sbX - 3, y + 7, z, 6, BLOCK.WOOL_BLACK); // Smokebox door\n  \n  // --- COWCATCHER (Pilot) ---\n  for (let i = 0; i < 8; i++) {\n    let width = 4 + i;\n    let height = 2 - (i/4);\n    place(sbX - 3 - i, y + 2, z - width, BLOCK.IRON);\n    place(sbX - 3 - i, y + 2, z + width, BLOCK.IRON);\n    drawLine(sbX - 3 - i, y + 2, z - width, sbX - 3 - i, y + 2, z + width, BLOCK.IRON);\n  }\n  \n  // --- CHIMNEY (Smokestack) ---\n  let chimneyX = x + 4;\n  let chimneyY = y + 15;\n  box(chimneyX - 2, chimneyY, z - 2, chimneyX + 2, chimneyY + 6, z + 2, BLOCK.IRON);\n  // Top flare\n  box(chimneyX - 3, chimneyY + 6, z - 3, chimneyX + 3, chimneyY + 8, z + 3, BLOCK.WOOL_BLACK);\n  \n  // --- DOME (Steam Dome) ---\n  drawCircleXY(x + 20, y + maxRadius + 1, z, 4, BLOCK.GOLD);\n  box(x + 17, y + maxRadius + 1, z - 1, x + 23, y + maxRadius + 1, z + 1, BLOCK.GOLD);\n  \n  // --- CAB (Rear) ---\n  let cabX = x + boilerLength;\n  box(cabX, y + 4, z - 6, cabX + 10, y + 12, z + 6, BLOCK.WOOD_PLANK);\n  \n  // Cab Roof (Curved)\n  for (let dx = 0; dx <= 10; dx++) {\n    for (let dz = -6; dz <= 6; dz++) {\n      let h = Math.floor(Math.sin((dx / 10) * Math.PI) * 3);\n      place(cabX + dx, y + 12 + h, z + dz, BLOCK.WOOL_BLACK);\n    }\n  }\n  \n  // Cab Windows\n  box(cabX, y + 7, z - 6, cabX + 8, y + 9, z - 6, BLOCK.GLASS);\n  box(cabX, y + 7, z + 6, cabX + 8, y + 9, z + 6, BLOCK.GLASS);\n  \n  // --- CONNECTING RODS ---\n  // Connects wheels to piston (front)\n  let rodY = y + 2;\n  for (let wx of wheelPositions) {\n    let cx = x + wx;\n    drawLine(cx, rodY, z - 1, cx + 4, rodY, z - 1, BLOCK.IRON);\n    drawLine(cx, rodY, z + 1, cx + 4, rodY, z + 1, BLOCK.IRON);\n  }\n  \n  // Buffer beam at rear\n  box(cabX + 10, y + 3, z - 6, cabX + 10, y + 5, z + 6, BLOCK.WOOL_BLACK);\n}\n\nfunction buildCar(xStart, color) {\n  let x = xStart;\n  let y = 6;\n  let z = 0;\n  \n  // Body\n  box(x, y + 2, z, x + 30, y + 8, z + 10, color);\n  \n  // Roof\n  for (let dx = 0; dx <= 30; dx++) {\n    for (let dz = 0; dz <= 10; dz++) {\n      let h = Math.floor(Math.sin((dx / 30) * Math.PI) * 2);\n      place(x + dx, y + 8 + h, z + dz, BLOCK.WOOL_BLACK);\n    }\n  }\n  \n  // Windows\n  for (let i = 2; i < 28; i += 4) {\n    box(x + i, y + 4, z - 1, x + i + 2, y + 6, z - 1, BLOCK.GLASS);\n    box(x + i, y + 4, z + 1, x + i + 2, y + 6, z + 1, BLOCK.GLASS);\n  }\n  \n  // Buffers\n  place(x - 1, y + 4, z - 3, BLOCK.IRON);\n  place(x - 1, y + 4, z + 3, BLOCK.IRON);\n  place(x + 31, y + 4, z - 3, BLOCK.IRON);\n  place(x + 31, y + 4, z + 3, BLOCK.IRON);\n}\n\n// --- MAIN EXECUTION ---\n\nfunction main() {\n  // 1. Build the Track\n  buildTrack(0);\n  \n  // 2. Build the Landscape (Simple base)\n  box(110, 0, -50, 146, 2, 900, BLOCK.GRASS);\n  box(110, 3, -50, 146, 3, 900, BLOCK.DIRT);\n  \n  // 3. Build the Train Components\n  // Engine is at Z=0, facing +Z\n  buildEngine(120); // X center ~128\n  \n  // Tender connects to rear of engine (Engine ends approx at Z=36)\n  buildTender(120);\n  \n  // Passenger Cars\n  // Car 1 starts after tender (Tender length ~16)\n  buildCar(120, BLOCK.WOOL_RED);\n  \n  // Car 2\n  buildCar(155, BLOCK.WOOL_BLUE);\n  \n  // Car 3\n  buildCar(190, BLOCK.WOOL_GREEN);\n  \n  // 4. Add Smoke Particles (Using Gray Wool)\n  let engineZ = 2; // Chimney Z\n  let chimneyX = 124;\n  let chimneyY = 27;\n  \n  for (let i = 0; i < 50; i++) {\n    let px = chimneyX + Math.floor((Math.random() - 0.5) * 6);\n    let py = chimneyY + Math.floor(Math.random() * 15);\n    let pz = engineZ + Math.floor((Math.random() - 0.5) * 4);\n    place(px, py, pz, BLOCK.WOOL_BLACK);\n  }\n}\n\nmain();", "gridSize": 256, "palette": "simple", "seed": 123}}