You have several things going here. You have the agent class. Within that class you have a world class, which is the world as the agent sees it. Is that any different from the world as it really is? In particular, the 5 x 7 grid? Basically, I am wondering whether world can be its own class, independent of agent. I see on line 35 a gd array, which I assume is the 5 x 7 grid. Any reason you want to store the grid as a vector of vectors in the world class rather than an array? I'm just thinking it may be better to have a separate world class which also stores the data as a char array. Presumably each coordinate of the grid can store an empty space, a wall, or a piece of food. And each piece of food has a certain smell intensity? The smell from the agent's point of view is based on the distance to the food and the smell intensity? Perhaps a food class that has a coordinate and an intensity.
Figure out the "rules" of the game, what needs to be stored, what each object type is, and what data members there are. From there, design some function prototypes. You'll likely have many classes. Tackle the sockets later and keep them as separate from the other classes as possible. If there is no need to have a vector of vectors, I would get rid of them
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
I've never mixes structs and classes like that, so I changed the structs to classes and made everything public when I tested them out. It probably doesn't matter though, since there's not much difference between a struct and a class aside from public versus private default permissions (that may be the ONLY difference. I'm not sure.). You can change them back from classes to structs as you had before. I commented a lot out to get it to compile, and this caused it to not compile:
class agent: public SENSE : public SPOT
You already have this:
class SENSE : public SPOT
so it seems you should change this:
class agent: public SENSE : public SPOT
to this:
class agent: public SENSE
since you've already declared that SENSE inherits from SPOT. Therefore you don't need to do it again.
It's not the only problem, but it's one that needed fixing.
As far as this code goes:
#include <netinet/in.h> //do i need this?
#include <sys/socket.h> //do i need this?
#include <arpa/inet.h> //do i need this?
I believe those are Linux socket libraries, so wherever you are handling the sockets, you'll need to include them.
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711