1.0.3 • Published 6 years ago
valiant-generate v1.0.3
valiant-generate
Compile Valiant AIs in JavaScript
Install
npm i -S valiant-generate
Usage
const Valiant = require('valiant-generate'),
valiant = new Valiant();
let exampleAI = (properties, memory, pheromone, inFront, hasFood, isEast, isStacked,
random) => {
// Respond to request for properties
if (properties) {
return new valiant.Properties("Example AI",
"Ottomated",
"Wanders randomly")
}
// Use memory functions:
let counter = valiant.decodeInt(memory, 0, 7);
counter++;
valiant.encodeInt(memory, 0, 7, counter);
// Store previous random bits in memory
memory[7] = random;
// Place a pheromone on the ground
if (!pheromone[0]) {
pheromone[0] = true;
let randoms = valiant.decodeInt([memory[7], random], 0, 2);
valiant.encodeInt(pheromone, 1, 2, randoms);
}
if (random && memory[7]) {
action = valiant.Action.MOVE_FORWARD;
} else if (random && !memory[7]) {
action = valiant.Action.TURN_RIGHT;
} else if (!random && memory[7]) {
action = valiant.Action.STAY_STILL;
} else if (!random && !memory[7]) {
action = valiant.Action.TURN_LEFT;
}
return new valiant.Output(memory, pheromone, action);
}
// Write to ./exampleAI.vnt
valiant.compile(exampleAI, 'exampleAI.vnt')