The agent's only objective is to find a single piece of food stored in the world. The agent can only sense the direction of the food relative to its on orientation in the world- this is represented by the 'gradient' member which stores either 'f', 'b', 'l', or 'r' for directions: forward, back, left, or right. These are also the key characters for the agent's navigation commands. Other sensory data members updated each time a move is made are; char onGround (stores what is underneath the agent), bool blocked()(stores whether there is a wall blocking the spot or not), char agent(later on there will be multiple agents in the world which help the first find the food, this member will store the agent's id if there is an agent on the spot), bool onCheese ( true if the agent is on the same coordinate as the food), and inventory is a stack of items the agent has picked up(useful for more involved navigation with keys to doors and the like).
The world itself is already implemented in java and the main.cpp connects to it's server via socket(all of which is implemented in a "connection.cpp" file) .
Right now I am still having trouble integrating the agent class with the main program. Is there a glaring error that is making my updateSenses function not able to read the data members? -these are the main errors that my compiler is giving me. I have attached a snapshot of my x-code compile errors. Thanks for your help!
Code: c++
/*
* agent.h
*/
#ifndef AGENT_H
#define AGENT_H
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <vector>
#include <stack>
using namespace std;
#define COLS 5
#define ROWs 7
struct SPOT
{
char obj; // contains object on the SPOT
char agent; // agent id if there is an agent on the SPOT
bool blocked;
//refer to neighboring SPOTs on map maybe will make a map class when I can figure out how to make member functions read these
SPOT* north;
SPOT* south;
SPOT* east;
SPOT* west;
};
struct SENSE : public SPOT
{
char gradient;
bool onCheese;
char inventory;
char onGround;
};
class agent: public SENSE
{
public:
/**utility functions**/
string role() const { return myRole; }
char id() const {return myId; }
char energy() const { return myEnergy; }
string myRole;
char myId;
char myEnergy;
struct SENSE : public SPOT
{
char gradient;
bool onCheese;
char inventory;
char onGround;
SPOT* me;
SPOT* myLeft;
SPOT* myRight;
SPOT* myBack;
SPOT* myFront;
//function updateSenses is having trouble reading this
vector<vector<SPOT> > map();
};
void updateSenses (string Message)
{
myId = Message.at(0);
gradient = Message.at(2);
stack<char> inventory;
char gd[35];
string message("");
stack<char> s;
int endlines = 0;
int it = 0;
/* get input */
for (int i = 1; i < Message.size(); i++)
{
if ( Message.at(i) == '\n') { endlines++; }
if ( Message.at(i) == '"' && !s.empty()) { s.pop(); }
if ( Message.at(i) == '"' && s.empty() )
{
s.push( Message.at(i));
if( endlines == 2 && Message.at(i+1) != '(' && Message.at(i+1) != ')') { inventory.push( Message.at(i+1) );}
/* what do we see? */
if( endlines == 3 && Message.at(i+1) != '(' && Message.at(i+1) != ')' ) //fill grid array up with data
{
{
gd[it] = (Message.at(i+1));
it++;
}
}
}
/* what's on the ground? */
if ( endlines == 4 && Message.at(i+1) != '(' )
{
if (Message.at(i+1) == ')') onGround = ' ';
else onGround = Message.at(i+1);
}
}
vector< vector<SPOT> > view (5, vector<SPOT> (7));
int i = 0;
while (i < it)
{
for ( int k = 0; k < 5; k++ )
{
for (int j = 0; j < 7; ++j)
{
if (gd[i] == " ") { view[k][j].blocked = false; }//if empty space, SPOT is not blocked
if (gd[i]== "0") // if this is me
{
me = view[k][j];
myRight = view[k][j+1];
myLeft = view[k][j-1];
myFront = view[k-1][j];
myBack = view[k+1][j];
}
//north, south.. etc implemented in larger grid
i++;
}
}
}
//cout grid
for ( int i = 0; i < 5; i++ )
{
for ( int j = 0; j < 7; j++ )
cout << '|' << view[i][j]. <<'|';
cout<<'\n';
}
}
//string chooseWisely()
//{
// /*** this will contain all the if/else statements
//}
};
#endif /*"agent.h"*/
/** Main **/
using namespace std;
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <iomanip>
#include "connection.cpp"
#include "agent.h"
int main( )
{
/* to connect to the environment of Maeden, connect to the Madenport server
by creating an intance of the socket class and sending your role.
Socket constructer returns the agent's id. */
int sock;
string role = "base\n";
sock = connect(role);
string Message = Receive(sock);
agent mouse();
mouse.updateSenses(Message);
Send("r\n", sock);
Receive(sock);
return 0;
}

