Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. robot& robot::teleport(int num1, int num2) {
  2.  
  3.     int moves = 0;
  4.     do moves = rand() % num2 - rand() % num1;
  5.     while (moves == 0);
  6.  
  7.     (*this).print(); std::cout << " tp ";
  8.     if (_my_position.X + moves >= _my_labirint.x_size() ||
  9.         _my_position.Y + moves >= _my_labirint.y_size() ||
  10.         _my_position.Z + moves >= _my_labirint.z_size())
  11.     {
  12.         std::cout << " no tp: target is on the border" << std::endl;
  13.         return (*this);
  14.     }
  15.  
  16.     if (_my_labirint.isBusy(_my_position.X + moves, _my_position.Y + moves, _my_position.Z + moves)) {
  17.         std::cout << " no tp: target cell is busy" << std::endl;
  18.         return (*this);
  19.     }
  20.  
  21.     _my_position.X += moves;
  22.     _my_position.Y += moves;
  23.     _my_position.Z += moves;
  24.     std::cout << " -> "; (*this).print(); std::cout << std::endl;
  25.     if (_my_labirint.isExit(_my_position.X, _my_position.Y, _my_position.Z)) {
  26.         if (std::find(_visited_exits.begin(), _visited_exits.end(), _my_position) == _visited_exits.end()) {
  27.             _visited_exits.push_back(_my_position);
  28.             std::cout << "EXIT IS FOUND!!! " << '(' << _my_position.X << ',' << _my_position.Y << ',' << _my_position.Z << ')' << std::endl;
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement