I've currently started on my semester project for my programming course- programming a fully autonomous driving simulator. All cars are steered through AI and the map is printed in the console.
The first sheet wants us to create a couple of basic classes: FCCompact (The car), Scanner (AI), ID (terrain), and World (The map).
The Scanner is currently implemented as a "HAS-A" in my FCCompact class like so:
// FCCompact.h
class FCCompact
{
private:
struct fImpl;
fImpl *fImpl_;
/* ... */
// FCCompact.cpp
struct fImpl
{
Scanner scanner_;
/* ... */
};
The scanner function in question is
const ID& scanForID( int fovNumber, // How far it can see
FCCompact::Direction dir, // Direction car is facing
const Location& loc); // Location of car
So far so good. However, the entire map is located in a container vector< deque<ID> >
(1) in the class World; I'm not sure how to access it.
The functions posted so far have been given to us by the teacher, so they should be able to be implemented with the parameters given. I just have no clue how to do that.
My first idea was to call World::getID(Location &)
, but it's not static. Upon making it static, it can no longer access non-static members (duh, I forgot that). I have also made a static function that calls a non-static function; same problem (double duh).
Then I tossed the teacher's guidelines and simply passed in the entire World
object, but that didn't really work either.
What can I do?
Please keep in mind that this is technically homework and that I do not want full, qualified answers that even gives me the entire implementation of what I want to do. I want to learn as much as possible from this project, so please just point me in the right direction.
(1): Weird choice for a container type? I figured if the world is printed on the console, quick access to each row with a vector would be beneficial, since there will be no insertion or deletion of queues and the access time is brilliant.
A deque, on the other hand, is handily for accessing ranges, which is favorable since I will frequently change adjacent columns (cars driving along the x- or y-axis). This choice did not come swiftly; I'm still torn between this, a list, or a simple vector again.
Classes
class World
class ID;
class World
{
typedef std::pair<int, int> Location;
private:
// vector<deque<ID> > map
// int mapHeight, mapWidth
// string mapName
struct wImpl;
wImpl *pimpl_;
public:
World();
~World();
void create(const std::string& name = "FC-City");
int getHeight() const;
int getWidth() const;
ID getID(const Location& loc);
friend std::ostream& operator<<(std::ostream& os, World& world)
{
return os;
}
private:
void loadMap(std::string name = "FC-City");
private:
World(const World& other);
World& operator=(const World& other);
};
class Scanner
class ID;
class Scanner
{
typedef std::pair<int, int> Location;
public:
Scanner();
~Scanner();
const ID& scanForID( int fovNumber,
FCCompact::Direction dir,
const Location& loc);
private:
Scanner(const Scanner& other);
Scanner& operator==(const Scanner& other);
};
class FCCompact
class ID;
class FCCompact
{
typedef std::pair<int, int> Location;
public:
enum Direction
{
N, E, S, W,
NA = -1
};
private:
// Scanner scanner
// Location loc
// Direction dir
// ID id
struct FCCImpl;
FCCImpl *pimpl_;
public:
FCCompact( const ID& id,
const Location& loc,
const Direction& dir);
FCCompact( const char ch,
const Location& loc,
const Direction& dir);
const ID& getID() const;
Location getLoc() const;
Direction getDir() const;
void setDir( Direction& dir );
void step();
void hide();
void show();
};
class ID
class ID
{
public:
enum Trait
{
Traversable,
NotTraversable,
Mobile,
Undef
};
private:
Trait trait_;
char appearance_;
public:
ID( char outputChar, Trait trait )
: appearance_(outputChar), trait_(trait)
{ }
ID( char outputChar )
: appearance_(outputChar), trait_(Trait::Undef)
{ }
char getToken() const { return appearance_; }
Trait getTrait() const { return trait_; }
void setTrait(Trait trait) { trait_ = trait; }
};