Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ai-agents

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ai-agents - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

lib/aspiradora2/CleanerAgent.js

3

lib/core/Agent.js

@@ -21,2 +21,3 @@ //const tf = require('@tensorflow/tfjs-node');

}
/**

@@ -35,3 +36,3 @@ * Function that receive and store the perception of the world that is sent by the agent controller. This data is stored internally

send() {
return table["deafult"];
return this.table["deafult"];
}

@@ -38,0 +39,0 @@

@@ -6,5 +6,4 @@

this.world0 = null;
this.world = null;
this.actions = [];
this.data = { states: [], world: {} };
this.data = { states: {}, world: {} };
}

@@ -80,2 +79,3 @@ /**

agent.receive(this.problem.perceptionForAgent(this.getData(), agent.getID()));
// Espera
let action = agent.send();

@@ -89,3 +89,3 @@ this.actions.push({ agentID: agent.getID(), action });

if (this.callbacks.onTurn) {
this.callbacks.onTurn({ actions: this.getActions(), data: this.data });
this.callbacks.onTurn({ actions: this.getActions(), data: JSON.parse(JSON.stringify(this.data)) });
}

@@ -92,0 +92,0 @@ if (this.currentAgentIndex >= keys.length - 1) this.currentAgentIndex = 0;else this.currentAgentIndex++;

const Agent = require('../core/Agent');
/**
* Simple reflex agent. Search for an object whithin a labyrinth.
* If the object is found the agen take it.
*/
class CleanerAgent extends Agent {
constructor(value) {
super(value);
//LEFT, UP, RIGHT, DOWN, CELL
this.table = {

@@ -19,3 +24,3 @@ "0,0,0,0,0": "UP",

"1,0,1,1,0": "UP",
"1,1,0,0,0": "RIGTH",
"1,1,0,0,0": "RIGHT",
"1,1,0,1,0": "RIGHT",

@@ -27,4 +32,12 @@ "1,1,1,0,0": "DOWN",

/**
* We override the send method.
* In this case, the state is just obtained as the join of the perceptions
*/
send() {
let viewKey = this.perception.join();
//let action = foo(this.internalState, this.perception)
//this.internalState = updatex(this.internalState, this.perception, action)
//return action;
if (this.table[viewKey]) {

@@ -31,0 +44,0 @@ return this.table[viewKey];

const Problem = require('../core/Problem');
/**
* Simple reflex agent problem. Define a problem to be solved by a simple reflex agent
*/
class CleanerProblem extends Problem {

@@ -10,3 +13,4 @@ constructor(args) {

/**
* Check if the given solution solves the problem. You must override
* Check if the given solution solves the problem. You must override.
* The current state of the enviroment is maintained in data.world
* @param {Object} solution

@@ -24,3 +28,7 @@ */

/**
* The transition model. Tells how to change the state (data) based on the given actions. You must override
* The transition model.
* Tells how to change the state (data) based on the given actions. You must override
* In this case, the actions can be one the four movements or the TAKE action.
* In this case, what changes based on the movement actions is the x or y position of the agent
* or the current cell if the action is TAKE
* @param {} data

@@ -56,3 +64,5 @@ * @param {*} action

/**
* Gives the world representation for the agent at the current stage
* Gives the world representation for the agent at the current stage.
* Notice that the agent don't have access to the whole labyrinth. It only "see"
* the cell around and under it.
* @param {*} agentID

@@ -77,4 +87,4 @@ * @returns and object with the information to be sent to the agent

result = result.map(value => value > 0 ? 1 : 0);
//SMELL
result.push(Math.abs(map[y][x]));

@@ -85,3 +95,3 @@ return result;

/**
* Solve the given problem
* Solve the given problem. We don't need to change in this case
* @param {*} problem

@@ -88,0 +98,0 @@ * @param {*} callbacks

@@ -10,3 +10,3 @@ const CleanerProblem = require('./CleanerProblem');

let agentID = result.actions[result.actions.length - 1].agentID;
console.log("Winner " + agentID);
console.log("agent: " + agentID);
console.log(result.actions);

@@ -16,3 +16,9 @@ let world = JSON.parse(JSON.stringify(result.data.world));

world[agentState.y][agentState.x] = "X";
console.log(world);
status = 1;
for (let line of world) {
console.log(line);
for (let cell of line) if (cell == -1) status = -1;
}
if (status == -1) console.log("Agent cannot solve this problem :(");else console.log("Agent could solve this problem :)");
},

@@ -19,0 +25,0 @@ onTurn: result => {

@@ -10,3 +10,3 @@ const CleanerProblem = require('./CleanerProblem');

let agentID = result.actions[result.actions.length - 1].agentID;
console.log("Winner " + agentID);
console.log("agent: " + agentID);
console.log(result.actions);

@@ -16,3 +16,9 @@ let world = JSON.parse(JSON.stringify(result.data.world));

world[agentState.y][agentState.x] = "X";
console.log(world);
status = 1;
for (let line of world) {
console.log(line);
for (let cell of line) if (cell == -1) status = -1;
}
if (status == -1) console.log("Agent cannot solve this problem :(");else console.log("Agent could solve this problem :)");
},

@@ -24,3 +30,5 @@ onTurn: result => {

iterator.next();
iterator.next();
module.exports = iterator;
// Load in a nodejs console doing:
// const iterator = require('./mainInteractive')
{
"name": "ai-agents",
"version": "0.2.0",
"version": "0.2.1",
"description": "Framework to create virtual agents",

@@ -5,0 +5,0 @@ "keywords": [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc