#include <iostream>
#include <cmath>
using namespace std;

// range : [min, max]
int random(int min, int max) {
   static bool first = true;
   if (first) {  
      srand(time(NULL)); //seeding for the first time only!
      first = false;
   }
   return min + rand() % (max - min + 1);
}

std::pair<int,int> rand_heading_point(int start_x, int start_y, int max_x, int max_y, int heading_dir) {
    int turn_x = 0;
    int turn_y = 0;
    
    // if heading_dir == 0 --> object moves horicontally towards max_x, increment x
    // if heading_dir == 90 --> object moves vertically towards max_y, increment y
    if (heading_dir <= 90) {
      turn_x = random(start_x, max_x);
      turn_y = random(start_y, max_y);
    } else if (heading_dir <= 180) {
      turn_x = random(0, start_x);
      turn_y = random(start_y, max_y);
    } else if (heading_dir <= 270) {
      turn_x = random(0, max_y);
      turn_y = random(0, start_y);
    } else {
      turn_x = random(start_x, max_x);
      turn_y = random(0, start_y);
    }
    
    return std::make_pair(turn_x, turn_y);
}

void change_heading_dir(int curr_x, int curr_y, int turn_x, int turn_y, int &heading_dir) {
	if (curr_x == turn_x || curr_y == turn_y) {
		heading_dir *= 2;
	}
}

// edit: use floats
void move(int &curr_x, int &curr_y, int heading_dir) {
	int heading_rad = heading_dir * (M_PI / 180);
   	int inc_len = 1;
    int x_inc = Math.cos(heading_rad) * inc_len;
    int y_inc = Math.sin(heading_rad) * inc_len;
  	
  	curr_x += x_inc;
  	curr_y += y_inc;
}

int main() {
	// your code goes here
	
	int start_x = 100;
	int start_y = 100;
	int width = 500;
	int height = 500;
	int dir = 0;
	
	auto heading_point = rand_heading_point(start_x, start_y, width, height, dir);
	
	cout << "x: " << heading_point.first << ", y: " << heading_point.second << endl;
	
	return 0;
}