WorldHandler

world->WorldHanlder.hpp

WorldHandler will handle the world. Create a world, moving robots around it, do actions, and in short everything related to the world.

Author: Aidin Gharibnavaz

Constructors

WorldHandler(char* address)
Create the world according to a given '.world' file. 'address' is the address of the '.world' file.

Public Methods

int addRobot( int ID, int tribe, int battery, char* name)
Create a robot and add it to the world. Will return 0 on success, -1 otherwise. 'ID' is the ID of the robot, equal to the File Descriptor of the client who control this robot. 'tribe' is the number of the tribe this robot belongs to. 'battery' is the default status of the robot's battery. And obviously 'name' is the name of the robot.

int move(int ID,int dir)
Move the robot with 'ID' to the specific direction. Will return 0 on success and -1 otherwise.

bool isExist(int ID)
Return true if there's a robot with this ID, false if not.

int shoot(int ID, int dir)
Make robot with `ID' identification shoot at the specified direction.

vector<int> getPosition(int ID)
Return the position of the robot with 'ID' id.

string info(int i, int j)
Return information about object in (i,j) in string format. Return an empty string on error.

string sense(int ID)
Return objects around of a certain robot in string format. Will return 'ERROR' if any error occurred.

int pickUp(int ID, int dir)
Pick up an object and hand it to the robot. Return 0 on success, -1 otherwise.

int drop(int ID, int dir)
Drop item in the hands of robot at the specified direction. Return 0 on success, -1 on error.

string getWholeMap()
Return all of the objects in the map in string format. Useful for sending data to the GUIs.

string getSize()
Return size of the world in string format.

int getNumberOfTribes()
Return number of tribes that exist in the game.

int isHeldSth(int ID)
Return 1 if the robot hold something in her hands, 0 if not.

string getBattery(int ID)
Return amount of battery a certain robot have.

string getHonor(int ID)
Return honor a certain robot have.

void reduceHonor(int ID, int amount)
Reduce amount of honor a certain robot have.

int getTribe(int ID)
Return tribe number that this robot belongs to.

string getShield(int ID)
Return shield health of the robot.

string getLifetime(int ID)
Return amount of time the robot have before her death.

Private Methods

void worldReader( char* address)
Read a '.world' file at the 'address' location and add its objects to the 'world'.

int removeRobot(int ID, int position_i, int position_j)
Remove the robot from the world (usually when she dies).