mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-09-08 02:52:59 +02:00
ignoring construction task files bc too big. generation now has variable number of agents and splits inventory evenly
This commit is contained in:
parent
7ca26a70b4
commit
d9b1e4805f
2 changed files with 67 additions and 54 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -26,3 +26,5 @@ server_data_*/*
|
||||||
server_data*
|
server_data*
|
||||||
results/*
|
results/*
|
||||||
>>>>>>> d70491e5974a973b96c47f0515c2722b82c9b253
|
>>>>>>> d70491e5974a973b96c47f0515c2722b82c9b253
|
||||||
|
tasks/construction_tasks/test_multiagent_construction_tasks.json
|
||||||
|
tasks/construction_tasks/train_multiagent_construction_tasks.json
|
|
@ -5,28 +5,17 @@ import {proceduralGeneration} from "../../src/agent/task_types/construction_task
|
||||||
* Helper function to initalize agent inventories
|
* Helper function to initalize agent inventories
|
||||||
* @param blueprint
|
* @param blueprint
|
||||||
* @param agents
|
* @param agents
|
||||||
|
* @param evenlySplit - When true, splits materials evenly across inventories
|
||||||
* @returns {{}}
|
* @returns {{}}
|
||||||
*/
|
*/
|
||||||
function createInitialInventory(blueprint, agents) {
|
function createInitialInventory(blueprint, agents, evenlySplit = true) {
|
||||||
/*
|
|
||||||
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
|
|
||||||
-
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
const inventories = {};
|
const inventories = {};
|
||||||
const materialCounts = {};
|
const materialCounts = {};
|
||||||
let currentAgent = 0;
|
let currentAgent = 0;
|
||||||
|
|
||||||
// Initialize inventories
|
// Initialize inventories
|
||||||
for (let i = 0; i < agents; i++) {
|
for (let i = 0; i < agents; i++) {
|
||||||
inventories[i] = {'diamond_pickaxe':1};
|
inventories[i] = {'diamond_pickaxe': 1};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Count materials in blueprint and replace ladder variants with "ladder"
|
// Count materials in blueprint and replace ladder variants with "ladder"
|
||||||
|
@ -53,13 +42,29 @@ function createInitialInventory(blueprint, agents) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (evenlySplit) {
|
||||||
|
// Distribute materials evenly among agents
|
||||||
|
for (const [material, count] of Object.entries(materialCounts)) {
|
||||||
|
const baseAmount = Math.floor(count / agents);
|
||||||
|
const remainder = count % agents;
|
||||||
|
|
||||||
// Distribute materials among agents
|
// Give each agent the base amount
|
||||||
for (const [material, count] of Object.entries(materialCounts)) {
|
for (let i = 0; i < agents; i++) {
|
||||||
inventories[currentAgent][material] = count;
|
inventories[i][material] = baseAmount;
|
||||||
currentAgent = (currentAgent + 1) % agents;
|
}
|
||||||
|
|
||||||
|
// Distribute remainder one by one to agents
|
||||||
|
for (let i = 0; i < remainder; i++) {
|
||||||
|
inventories[i][material]++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Original distribution - one material type to one agent
|
||||||
|
for (const [material, count] of Object.entries(materialCounts)) {
|
||||||
|
inventories[currentAgent][material] = count;
|
||||||
|
currentAgent = (currentAgent + 1) % agents;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return inventories;
|
return inventories;
|
||||||
}
|
}
|
||||||
|
@ -78,13 +83,13 @@ function calculateSpaceNeeded(rooms) {
|
||||||
/**
|
/**
|
||||||
* MAIN GENERATION FUNCTION
|
* MAIN GENERATION FUNCTION
|
||||||
*
|
*
|
||||||
* Varies materials, room count, windows and carpets to create different complexities of construction tasks.
|
* Varies agents, materials, room count, windows and carpets to create different complexities of construction tasks.
|
||||||
* @param variants is the number of variants within each complexity level you want.
|
* @param variants is the number of variants within each complexity level you want.
|
||||||
* @returns The tasks as nested JSON {{}}
|
* @returns The tasks as nested JSON {{}}
|
||||||
*/
|
*/
|
||||||
function generateConstructionTasks(variants) {
|
function generateConstructionTasks(variants) {
|
||||||
const materialLevels = 5;
|
const materialLevels = 5;
|
||||||
const agentCount = 2
|
const agentCount = 5
|
||||||
const roomCounts = [4, 6, 8];
|
const roomCounts = [4, 6, 8];
|
||||||
const windowStyles = [0, 1, 2];
|
const windowStyles = [0, 1, 2];
|
||||||
const carpetStyles = [0, 1, 2];
|
const carpetStyles = [0, 1, 2];
|
||||||
|
@ -96,37 +101,40 @@ function generateConstructionTasks(variants) {
|
||||||
for (let r = 0; r < roomCounts.length; r++) {
|
for (let r = 0; r < roomCounts.length; r++) {
|
||||||
for (let w = 0; w < windowStyles.length; w++) {
|
for (let w = 0; w < windowStyles.length; w++) {
|
||||||
for (let c = 0; c < carpetStyles.length; c++) {
|
for (let c = 0; c < carpetStyles.length; c++) {
|
||||||
for (let variant = 0; variant < variants; variant++) {
|
for (let agent = 2; agent <= agentCount; agent++) {
|
||||||
const rooms = roomCounts[r];
|
for (let variant = 0; variant < variants; variant++) {
|
||||||
const spaceSize = calculateSpaceNeeded(rooms);
|
|
||||||
|
|
||||||
const blueprint = proceduralGeneration(
|
const rooms = roomCounts[r];
|
||||||
spaceSize,
|
const spaceSize = calculateSpaceNeeded(rooms);
|
||||||
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}`;
|
const blueprint = proceduralGeneration(
|
||||||
|
spaceSize,
|
||||||
|
spaceSize,
|
||||||
|
spaceSize,
|
||||||
|
rooms,
|
||||||
|
4,
|
||||||
|
4,
|
||||||
|
4,
|
||||||
|
5,
|
||||||
|
"air",
|
||||||
|
carpetStyles[c],
|
||||||
|
windowStyles[w],
|
||||||
|
m + 1
|
||||||
|
);
|
||||||
|
|
||||||
tasks[taskName] = {
|
const taskName = `agents_${agent}_materials_${m}_rooms_${r}_window_${w}_carpet_${c}_variant_${variant}`;
|
||||||
type: "construction",
|
|
||||||
goal: "Make a house with the blueprint",
|
|
||||||
conversation: "Let's share materials and make a house with the blueprint",
|
|
||||||
agent_count: agentCount,
|
|
||||||
initial_inventory: createInitialInventory(blueprint, agentCount),
|
|
||||||
timeout: timeout+(300*r), // 5 minute per additional level of complexity
|
|
||||||
blueprint: blueprint,
|
|
||||||
|
|
||||||
};
|
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: agent,
|
||||||
|
initial_inventory: createInitialInventory(blueprint, agent),
|
||||||
|
timeout: timeout + (300 * r), // 5 minute per additional level of complexity
|
||||||
|
blueprint: blueprint,
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -137,15 +145,18 @@ function generateConstructionTasks(variants) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Main: writes the generated tasks to a file.
|
//Main: writes the generated tasks to a file.
|
||||||
const tasks = generateConstructionTasks(5);
|
|
||||||
|
// VARIABLES TO CHANGE HERE
|
||||||
|
const variants = 1
|
||||||
|
const file = './test_multiagent_construction_tasks.json'
|
||||||
|
|
||||||
|
const tasks = generateConstructionTasks(variants);
|
||||||
// Clear existing file content
|
// Clear existing file content
|
||||||
fs.writeFileSync('./train_multiagent_construction_tasks.json', '');
|
fs.writeFileSync(file, '');
|
||||||
// re-add
|
// re-add
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
'./train_multiagent_construction_tasks.json',
|
file,
|
||||||
JSON.stringify(tasks, null, 2)
|
JSON.stringify(tasks, null, 2)
|
||||||
);
|
);
|
||||||
|
console.log("Generated tasks saved to ",file);
|
||||||
console.log("Generated tasks saved to test_multiagent_construction_tasks.json");
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue