Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Map.cpp
- *
- * Created on : Apr 21, 2017
- * Author : skatsner
- */
- #include <iostream>
- #include "Map.h"
- #include <string>
- /** this module contain the map.h and all the functions that changes elements of the map
- and move the robot along the map by changing the robots vectors.
- is uses robotDB.h to access the robots vectors, and to change them acording to the moves, and uses printer.h to print
- the new location. **/
- using namespace std;
- #define S_HIGH (7) // define the numbers of rows
- #define S_WIDTH (7) // define the numbers of columns
- //this is the map that contains the wall and the pathes
- int gmap[S_HIGH][S_WIDTH] =
- {
- { 0 , 1 , 1 , 1 , 1 , 1 , 1 },
- { 1 , 0 , 0 , 0 , 1 , 0 , 1 },
- { 0 , 0 , 1 , 1 , 1 , 0 , 1 },
- { 1 , 0 , 0 , 0 , 0 , 0 , 1 },
- { 1 , 1 , 1 , 0 , 1 , 0 , 1 },
- { 1 , 0 , 0 , 0 , 0 , 0 , 1 },
- { 1 , 0 , 1 , 1 , 1 , 1 , 1 }
- };
- /**
- * ###################### Module functions ######################
- */
- /** a function to add a dirt anywhere in the location (x,y) on the map**/
- void addDirt(const int x, const int y)
- {
- if (isRobot(x, y)) {
- if (inMapLimit(x, y)) {
- gmap[x][y] = 1;
- }
- }
- }
- /** a help function to check if is robot in location (x,y) on the map**/
- bool isRobot(const int x, const int y) {
- vector<int> *R_X, *R_Y;
- R_X = getX();
- R_Y = getY();
- for (int i = 0; i < R_X->size(); i++) {
- if (R_X->at(i) == x && R_Y->at(i) == y) {
- return false;
- }
- }
- return true;
- }
- //####################################################################################################
- bool inMapLimit(const int x, const int y)
- {
- if (x >= 0 && x<S_HIGH && y >= 0 && y<S_WIDTH)
- return true;
- else
- return false;
- }
- /** a function to clean anywhere in the location (x,y) on the map**/
- void Clean(const string RobotName)
- {
- vector<string> Rnames;
- vector<int> *R_X, *R_Y, *Ranks1, *Tanks1;
- getNames(Rnames);
- R_X = getX();
- R_Y = getY();
- Ranks1 = getRanks();
- Tanks1 = getTanks();
- for (int i = 0; i < Rnames.size(); i++) {
- string name = Rnames[i];
- if (name == RobotName)
- if (inMapLimit((R_X->at(i)), (R_Y->at(i)))) {
- if (Tanks1->at(i) == 5) {
- R_X->at(i) = 0;
- R_Y->at(i) = 0;
- Tanks1->at(i) = 0;
- }
- if ((gmap[R_Y->at(i)][R_X->at(i)]) == 0) {
- Tanks1->at(i)++;
- PrintClean(Rnames[i], R_X->at(i), R_Y->at(i));
- }
- if ((gmap[R_Y->at(i)][R_X->at(i)]) == 1) {
- Tanks1->at(i)++;
- Ranks1->at(i)++;
- gmap[R_Y->at(i)][R_X->at(i)] = 0;
- PrintClean(Rnames[i], R_X->at(i), R_Y->at(i));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement