-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmars_lander_niveau_1.cpp
121 lines (109 loc) · 2.5 KB
/
mars_lander_niveau_1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
using namespace std;
int parse_int(stringstream& ss)
{
string val;
getline(ss, val, ' ');
return stoi(val);
}
int power_up(int p)
{
if(p == 4)
return 4;
return p+1;
}
int power_down(int p)
{
if(p == 0)
return 0;
return p-1;;
}
int rotate_left(int r)
{
if(r == -90)
return -45;
return r-15;
}
int rotate_right(int r)
{
if(r == 90)
return 45;
return r+15;
}
int main()
{
// Read init information from standard input, if any
string line;
getline(cin, line);
int n = stoi(line);
int landing_x_min = 0, landing_x_max = 6999;
int landing_y = -1;
bool landing_found = false;
vector<int> ground(n);
for(int i=0; i<n; i++)
{
getline(cin, line);
stringstream ss(line);
int x = parse_int(ss);
int y = parse_int(ss);
//cerr << "x=" << x << " y=" << y << endl;
ground[x] = y;
if(i == 0)
{
landing_x_min = landing_x_max = x;
landing_y = y;
}
else
{
if(y == landing_y)
{
landing_x_max = x;
}
else if(landing_x_min == landing_x_max)
{
landing_x_min = landing_x_max = x;
landing_y = y;
}
}
}
//cerr << "landing_x_min=" << landing_x_min << ", landing_x_max=" << landing_x_max << endl;
while (1) {
// Read information from standard input
getline(cin, line);
stringstream ss(line);
int x = parse_int(ss);
int y = parse_int(ss);
int hs = parse_int(ss);
int vs = parse_int(ss);
int f = parse_int(ss);
int r = parse_int(ss);
int p = parse_int(ss);
int new_r = r, new_p = p;
if(x < landing_x_min)
{
// todo in level 2
}
else if(x > landing_x_max)
{
// todo in level 2
}
else
{
// we are over the landing area
if(vs < -39)
new_p = power_up(p);
else if(p > 3)
new_p = power_down(p);
if(r > 0)
new_r = rotate_left(r);
else if(r < 0)
new_r = rotate_right(r);
}
// Write action to standard output
cout << new_r << " " << new_p << endl;
}
return 0;
}