Fixed validator not getting executed after agent exiting the world due to smelting, by clearing inventories in the end

This commit is contained in:
Ayush Maniar 2025-03-20 12:56:29 -07:00
parent 7b690775ff
commit e0bbd661dd

View file

@ -126,25 +126,16 @@ class CookingCraftingTaskValidator {
this.data = data; this.data = data;
this.agent = agent; this.agent = agent;
} }
validate(has_initiated) { validate() {
if (has_initiated) { const result = checkItemPresence(this.data, this.agent);
let score = 0;
const result = checkItemPresence(this.data, this.agent); if (result.success) {
let score = 0; score = 1;
if (result.success) {
score = 1;
}
return {
"valid": result.success,
"score": score,
};
}
else {
return {
"valid": false,
"score": 0
};
} }
return {
"valid": result.success,
"score": score,
};
} }
} }
@ -202,7 +193,6 @@ export class Task {
this.name = this.agent.name; this.name = this.agent.name;
this.available_agents = settings.profiles.map((p) => JSON.parse(readFileSync(p, 'utf8')).name); this.available_agents = settings.profiles.map((p) => JSON.parse(readFileSync(p, 'utf8')).name);
this.agent_initialized = false;
} }
getAgentGoal() { getAgentGoal() {
@ -213,7 +203,7 @@ export class Task {
let add_string = ''; let add_string = '';
if (this.task_type === 'cooking') { if (this.task_type === 'cooking') {
add_string = '\nIn the end, all the food items should be given to one single player.'; add_string = '\nIn the end, all the food items should be given to one single bot.';
} }
// If goal is a string, all agents share the same goal // If goal is a string, all agents share the same goal
@ -254,8 +244,12 @@ export class Task {
isDone() { isDone() {
let res = null; let res = null;
if (this.validator) if (this.validator)
res = this.validator.validate(this.agent_initialized); res = this.validator.validate();
if (res && res.valid) { if (res && res.valid) {
// Find all the agents and clear their inventories
for (let agent of this.available_agents) {
this.agent.bot.chat(`/clear ${agent}`);
}
return {"message": 'Task successful', "score": res.score}; return {"message": 'Task successful', "score": res.score};
} }
let other_names = this.available_agents.filter(n => n !== this.name); let other_names = this.available_agents.filter(n => n !== this.name);
@ -326,8 +320,6 @@ export class Task {
await new Promise((resolve) => setTimeout(resolve, 500)); await new Promise((resolve) => setTimeout(resolve, 500));
} }
this.agent_initialized = true;
if (this.initiator) { if (this.initiator) {
await this.initiator.init(); await this.initiator.init();
} }