2025-02-13 14:49:03 -08:00
|
|
|
import fs from 'fs';
|
|
|
|
import {proceduralGeneration} from "../../src/agent/construction_tasks.js";
|
|
|
|
|
|
|
|
function createInitialInventory(blueprint, agents) {
|
2025-02-13 14:51:21 -08:00
|
|
|
/*
|
|
|
|
params:
|
|
|
|
- blueprint object
|
|
|
|
- number of agents (for inventory initialization)
|
|
|
|
|
|
|
|
logic of the function:
|
|
|
|
- loop matrix
|
|
|
|
- every time a new material is hit, put it in a different agents inventory
|
|
|
|
-
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2025-02-13 14:49:03 -08:00
|
|
|
const inventories = {};
|
|
|
|
const materialCounts = {};
|
|
|
|
let currentAgent = 0;
|
|
|
|
|
2025-02-13 14:51:21 -08:00
|
|
|
// Initialize inventories
|
2025-02-13 14:49:03 -08:00
|
|
|
for (let i = 0; i < agents; i++) {
|
|
|
|
inventories[i] = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Count materials in blueprint
|
|
|
|
for (const level of blueprint.levels) {
|
|
|
|
for (const row of level.placement) {
|
|
|
|
for (const block of row) {
|
|
|
|
if (block !== 'air') {
|
2025-02-25 15:39:26 -08:00
|
|
|
// Check if material contains 'door' in the name, convert to oak_door
|
|
|
|
const materialKey = block.includes('door') ? 'oak_door' : block;
|
|
|
|
materialCounts[materialKey] = (materialCounts[materialKey] || 0) + 1;
|
2025-02-13 14:49:03 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Distribute materials among agents
|
|
|
|
for (const [material, count] of Object.entries(materialCounts)) {
|
|
|
|
inventories[currentAgent][material] = count;
|
|
|
|
currentAgent = (currentAgent + 1) % agents;
|
|
|
|
}
|
|
|
|
|
|
|
|
return inventories;
|
|
|
|
}
|
|
|
|
|
|
|
|
function calculateSpaceNeeded(rooms) {
|
|
|
|
const baseSize = 10;
|
|
|
|
const scaleFactor = Math.floor(rooms / 4) * 5;
|
|
|
|
return baseSize + scaleFactor;
|
|
|
|
}
|
|
|
|
|
|
|
|
function generateConstructionTasks() {
|
|
|
|
const tasks = {};
|
2025-02-19 18:34:12 -08:00
|
|
|
const variants = 1
|
2025-02-13 14:49:03 -08:00
|
|
|
const materialLevels = 5;
|
|
|
|
const roomCounts = [4, 6, 8];
|
|
|
|
const windowStyles = [0, 1, 2];
|
|
|
|
const carpetStyles = [0, 1, 2];
|
2025-02-19 18:25:59 -08:00
|
|
|
const timeout = 600 // 10 min base?
|
2025-02-13 14:49:03 -08:00
|
|
|
|
|
|
|
for (let m = 0; m < materialLevels; m++) {
|
|
|
|
for (let r = 0; r < roomCounts.length; r++) {
|
|
|
|
for (let w = 0; w < windowStyles.length; w++) {
|
|
|
|
for (let c = 0; c < carpetStyles.length; c++) {
|
2025-02-19 18:34:12 -08:00
|
|
|
for (let variant = 0; variant < variants; variant++) {
|
2025-02-13 14:49:03 -08:00
|
|
|
const rooms = roomCounts[r];
|
|
|
|
const spaceSize = calculateSpaceNeeded(rooms);
|
|
|
|
|
|
|
|
const blueprint = proceduralGeneration(
|
|
|
|
spaceSize,
|
|
|
|
spaceSize,
|
|
|
|
spaceSize,
|
|
|
|
rooms,
|
|
|
|
4,
|
|
|
|
4,
|
|
|
|
4,
|
|
|
|
5,
|
|
|
|
"air",
|
|
|
|
carpetStyles[c],
|
|
|
|
windowStyles[w],
|
|
|
|
m + 1
|
|
|
|
);
|
|
|
|
|
|
|
|
const taskName = `materials_${m}_rooms_${r}_window_${w}_carpet_${c}_variant_${variant}`;
|
|
|
|
|
|
|
|
tasks[taskName] = {
|
|
|
|
type: "construction",
|
|
|
|
goal: "Make a house with the blueprint",
|
|
|
|
conversation: "Let's share materials and make a house with the blueprint",
|
|
|
|
agent_count: 2,
|
2025-02-19 18:25:59 -08:00
|
|
|
initial_inventory: createInitialInventory(blueprint, 2),
|
|
|
|
timeout: timeout+(300*r), // 5 minute per additional level of complexity
|
|
|
|
blueprint: blueprint, //todo: make a pointer?
|
|
|
|
|
2025-02-13 14:49:03 -08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return tasks;
|
|
|
|
}
|
|
|
|
|
|
|
|
const tasks = generateConstructionTasks();
|
|
|
|
// Clear existing file content
|
|
|
|
fs.writeFileSync('./example_multiagent_construction_tasks.json', '');
|
|
|
|
// re-add
|
|
|
|
fs.writeFileSync(
|
|
|
|
'./example_multiagent_construction_tasks.json',
|
|
|
|
JSON.stringify(tasks, null, 2)
|
|
|
|
);
|
|
|
|
|
|
|
|
console.log("Generated tasks saved to example_multiagent_construction_tasks.json");
|