diff --git a/include/BaseRobot.h b/include/BaseRobot.h new file mode 100644 index 0000000..918714c --- /dev/null +++ b/include/BaseRobot.h @@ -0,0 +1,28 @@ +#pragma once + +#include "Robot.h" + +#include + +class BaseRobot : public Robot { + /* A robot base class that implements functions common to all robots. */ + public: + BaseRobot ( std::string name, int startX, int startY ); + + void move ( int direction, const World &world ) override; + int decideNextMove ( const World &world ) const override; + + void setPosition ( int x, int y ) override { + x_ = x; + y_ = y; + } + int getScore () const override { return score_; } + void addScore ( int points ) override { score_ += points; } + int getX () const override { return x_; } + int getY () const override { return y_; } + std::string getName () const override { return name_; } + + protected: + int x_, y_, score_; + std::string name_; +}; diff --git a/include/Robot.h b/include/Robot.h new file mode 100644 index 0000000..280600c --- /dev/null +++ b/include/Robot.h @@ -0,0 +1,31 @@ +#pragma once + +#include +#include +#include + +class World; + +class Robot { + /* A virtual interface for a robot */ + public: + virtual ~Robot () = default; + Robot ( const Robot & ) = default; + Robot &operator= ( const Robot & ) = default; + Robot ( Robot && ) = default; + Robot &operator= ( Robot && ) = default; + + virtual void move ( int direction, const World &world ) = 0; + virtual int mine ( World &world ) = 0; + virtual int decideNextMove ( const World &world ) const = 0; + + virtual void setPosition ( int x, int y ) = 0; + virtual int getScore () const = 0; + virtual void addScore ( int points ) = 0; + virtual int getX () const = 0; + virtual int getY () const = 0; + virtual std::string getName () const = 0; + + protected: + Robot () = default; +}; diff --git a/include/SortBot.h b/include/SortBot.h new file mode 100644 index 0000000..d90127f --- /dev/null +++ b/include/SortBot.h @@ -0,0 +1,9 @@ +#pragma once + +#include "../include/BaseRobot.h" + +class SortBot : public BaseRobot { + public: + SortBot ( int startX, int startY ); + int mine ( World &world ) override; +}; diff --git a/include/World.h b/include/World.h index 21d60d5..5a0a707 100644 --- a/include/World.h +++ b/include/World.h @@ -3,6 +3,9 @@ #include class World { + /* A 3D grid world where robots can mine blocks. + Blocks have a value, some have special effects. */ + public: explicit World ( int x = 5, int y = 5, int z = 10 ); diff --git a/src/BaseRobot.cpp b/src/BaseRobot.cpp new file mode 100644 index 0000000..cf634cb --- /dev/null +++ b/src/BaseRobot.cpp @@ -0,0 +1,30 @@ +#include "../include/BaseRobot.h" +#include "../include/World.h" + +#include + +BaseRobot::BaseRobot ( std::string name, int startX, int startY ) + : x_ ( startX ), y_ ( startY ), score_ ( 0 ), name_ ( std::move ( name ) ) {} + +void BaseRobot::move ( int direction, const World &world ) { + + switch ( direction ) { + case 1: + x_ = std::min ( x_ + 1, world.getSizeX() - 1 ); + break; // right + case 2: + x_ = std::max ( x_ - 1, 0 ); + break; // left + case 3: + y_ = std::min ( y_ + 1, world.getSizeY() - 1 ); + break; // down + case 4: + y_ = std::max ( y_ - 1, 0 ); + break; // up + default: + break; // no move + } +} + +// TODO +// int BaseRobot::decideNextMove ( const World &world ) const diff --git a/src/SortBot.cpp b/src/SortBot.cpp new file mode 100644 index 0000000..585480d --- /dev/null +++ b/src/SortBot.cpp @@ -0,0 +1,7 @@ +#include "../include/SortBot.h" +#include "../include/World.h" + +#include +#include + +SortBot::SortBot ( int startX, int startY ) : BaseRobot ( "SortBot", startX, startY ) {}