added coward mode

This commit is contained in:
Maximus 2024-04-13 22:56:18 -05:00
parent 03b449d763
commit bf4163fcaa
4 changed files with 52 additions and 6 deletions

View file

@ -1,11 +1,11 @@
{
"name": "andy",
"model": "gpt-3.5-turbo",
"model": "gpt-4-0125-preview",
"conversing": "You are a playful Minecraft bot named $NAME that can converse with players, see, move, mine, build, and interact with the world by using commands. Act human-like as if you were a typical Minecraft player, rather than an AI. Be very brief in your responses, don't apologize constantly, don't give instructions or make lists unless asked, and don't refuse requests. Don't pretend to act, use commands immediately when requested. Do NOT say this: 'Sure, I've stopped.', instead say this: 'Sure, I'll stop. !stop'. Do NOT say this: 'On my way! Give me a moment.', instead say this: 'On my way! !goToPlayer('playername', 3)'. This is extremely important to me, take a deep breath and have fun :)\n$STATS\n$INVENTORY\n$COMMAND_DOCS\n$EXAMPLES\nConversation Begin:",
"coding": "You are an intelligent mineflayer bot $NAME that plays minecraft by writing javascript codeblocks. Given the conversation between you and the user, use the provided skills and world functions to write a js codeblock that controls the mineflayer bot ``` // using this syntax ```. The code will be executed and you will recieve it's output. If you are satisfied with the response, respond without a codeblock in a conversational way. If something major went wrong, like an error or complete failure, write another codeblock and try to fix the problem. Minor mistakes are acceptable. Be maximally efficient, creative, and clear. Do not use commands !likeThis, only use codeblocks. Make sure everything is properly awaited, if you define an async function, make sure to call it with `await`. Don't write long paragraphs and lists in your responses unless explicitly asked! Only summarize the code you write with a sentence or two when done. This is extremely important to me, take a deep breath and good luck! \n$STATS\n$INVENTORY\n$CODE_DOCS\n$EXAMPLES\nBegin coding:",
"coding": "You are an intelligent mineflayer bot $NAME that plays minecraft by writing javascript codeblocks. Given the conversation between you and the user, use the provided skills and world functions to write a js codeblock that controls the mineflayer bot ``` // using this syntax ```. The code will be executed and you will recieve it's output. If you are satisfied with the response, respond without a codeblock in a conversational way. If something major went wrong, like an error or complete failure, write another codeblock and try to fix the problem. Minor mistakes are acceptable. Be maximally efficient, creative, and clear. Do not use commands !likeThis, only use codeblocks. The code is asynchronous and MUST CALL AWAIT for all async function calls. DO NOT write an immediately-invoked function expression without using `await`!! DO NOT WRITE LIKE THIS: ```(async () => {console.log('not properly awaited')})();``` Don't write long paragraphs and lists in your responses unless explicitly asked! Only summarize the code you write with a sentence or two when done. This is extremely important to me, take a deep breath and good luck! \n$STATS\n$INVENTORY\n$CODE_DOCS\n$EXAMPLES\nBegin coding:",
"saving_memory": "You are a minecraft bot named $NAME that has been talking and playing minecraft by using commands. Update your memory by summarizing the following conversation in your next response. Store information that will help you improve as a Minecraft bot. Include details about your interactions with other players that you need to remember and what you've learned through player feedback or by executing code. Do not include command syntax or things that you got right on the first try. Be extremely brief and use as few words as possible.\nOld Memory: '$MEMORY'\nRecent conversation: \n$TO_SUMMARIZE\nSummarize your old memory and recent conversation into a new memory, and respond only with the memory text: ",
@ -116,7 +116,7 @@
],
[
{"role": "user", "content": "bobby: cook some chicken"},
{"role": "assistant", "content": "```\nawait skills.smeltItem(bot, 'chicken', 8);\n```"},
{"role": "assistant", "content": "```await skills.smeltItem(bot, 'chicken', 8);\n```"},
{"role": "system", "content": "Successfully smelted 8 chicken into 8 cooked_chicken."},
{"role": "assistant", "content": "I have cooked 8 chicken."}
],

View file

@ -26,6 +26,8 @@ export class Coder {
code = code.replaceAll('console.log(', 'log(bot,');
code = code.replaceAll('log("', 'log(bot,"');
console.log(`Generated code: """${code}"""`);
// this may cause problems in callback functions
code = code.replaceAll(';\n', '; if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}\n');
for (let line of code.split('\n')) {
@ -33,8 +35,6 @@ export class Coder {
}
src = this.code_template.replace('/* CODE HERE */', src);
console.log("writing to file...", src)
let filename = this.file_counter + '.js';
// if (this.file_counter > 0) {
// let prev_filename = this.fp + (this.file_counter-1) + '.js';

View file

@ -256,6 +256,7 @@ export async function attackNearest(bot, mobType, kill=true) {
* @example
* await skills.attackNearest(bot, "zombie", true);
**/
bot.modes.pause('cowardice');
const mob = bot.nearestEntity(entity => entity.name && entity.name.toLowerCase() === mobType.toLowerCase());
if (mob) {
return await attackEntity(bot, mob, kill);
@ -312,6 +313,7 @@ export async function defendSelf(bot, range=9) {
* await skills.defendSelf(bot);
* **/
bot.modes.pause('self_defense');
bot.modes.pause('cowardice');
let attacked = false;
let enemy = world.getNearestEntityWhere(bot, entity => mc.isHostile(entity), range);
while (enemy) {
@ -759,6 +761,32 @@ export async function moveAway(bot, distance) {
return true;
}
export async function avoidEnemies(bot, distance=16) {
/**
* Move a given distance away from all nearby enemy mobs.
* @param {MinecraftBot} bot, reference to the minecraft bot.
* @param {number} distance, the distance to move away.
* @returns {Promise<boolean>} true if the bot moved away, false otherwise.
* @example
* await skills.avoidEnemies(bot, 8);
**/
let enemy = world.getNearestEntityWhere(bot, entity => mc.isHostile(entity), distance);
while (enemy) {
const follow = new pf.goals.GoalFollow(enemy, distance+1); // move a little further away
const inverted_goal = new pf.goals.GoalInvert(follow);
bot.pathfinder.setMovements(new pf.Movements(bot));
bot.pathfinder.setGoal(inverted_goal, true);
await new Promise(resolve => setTimeout(resolve, 500));
enemy = world.getNearestEntityWhere(bot, entity => mc.isHostile(entity), distance);
if (bot.interrupt_code) {
return false;
}
}
log(bot, `Moved ${distance} away from enemies.`);
return true;
}
export async function stay(bot) {
/**
* Stay in the current position until interrupted. Disables all modes.
@ -767,6 +795,7 @@ export async function stay(bot) {
* @example
* await skills.stay(bot);
**/
bot.modes.pause('cowardice');
bot.modes.pause('self_defense');
bot.modes.pause('hunting');
bot.modes.pause('torch_placing');

View file

@ -15,6 +15,23 @@ import * as mc from '../utils/mcdata.js';
// while update functions are async, they should *not* be awaited longer than ~100ms as it will block the update loop
// to perform longer actions, use the execute function which won't block the update loop
const modes = [
{
name: 'cowardice',
description: 'Automatically run away from enemies. Interrupts other actions.',
interrupts: ['all'], // Todo: don't interrupt attack actions
dont_interrupt: ['followPlayer'],
on: true,
active: false,
update: async function (agent) {
const enemy = world.getNearestEntityWhere(agent.bot, entity => mc.isHostile(entity), 16);
if (enemy && await world.isClearPath(agent.bot, enemy)) {
agent.bot.chat(`Aaa! A ${enemy.name}!`);
execute(this, agent, async () => {
await skills.avoidEnemies(agent.bot, 16);
});
}
}
},
{
name: 'self_defense',
description: 'Automatically attack nearby enemies. Interrupts other actions.',
@ -87,7 +104,7 @@ const modes = [
// TODO: check light level instead of nearby torches, block.light is broken
const near_torch = world.getNearestBlock(agent.bot, 'torch', 6);
if (!near_torch) {
let torches = agent.bot.inventory.items().filter(item => item.name.includes('torch'));
let torches = agent.bot.inventory.items().filter(item => item.name === 'torch');
if (torches.length > 0) {
const torch = torches[0];
const pos = agent.bot.entity.position;