Question
Mars Lander - Episode 2 The goal for your program is to safely land the Mars Lander shuttle, the landing ship which contains the Opportunity
Mars Lander - Episode 2
The goal for your program is to safely land the "Mars Lander" shuttle, the landing ship which contains the Opportunity rover. Mars Lander is guided by a program, and right now the failure rate for landing on the NASA simulator is unacceptable. This puzzle is the second level of the "Mars Lander" trilogy. The controls are the same as the previous level but you must now control the angle in order to succeed.
Rules
Built as a game, the simulator puts Mars Lander on a limited zone of Mars sky.
The zone is 7000m wide and 3000m high. There is a unique area of flat ground on the surface of Mars, which is at least 1000 meters wide.
Every second, depending on the current flight parameters (location, speed, fuel ...), the program must provide the new desired tilt angle and thrust power of Mars Lander:
Angle goes from -90 to 90 . Thrust power goes from 0 to 4 .
The game simulates a free fall without atmosphere. Gravity on Mars is 3.711 m/s . For a thrust power of X, a push force equivalent to X m/s is generated and X liters of fuelare consumed. As such, a thrust power of 4 in an almost vertical position is needed to compensate for the gravity on Mars. For a landing to be successful, the ship must:
land on flat ground
land in a vertical position (tilt angle = 0)
vertical speed must be limited ( 40m/s in absolute value)
horizontal speed must be limited ( 20m/s in absolute value)
Note
Tests and validators are only slightly different. A program that passes a given test will pass the corresponding validator without any problem.
Game Input
The program must first read the initialization data from standard input. Then, within an infinite loop, the program must read the data from the standard input related to Mars Lander's current state and provide to the standard output the instructions to move Mars Lander.
Initialization input
Line 1: the number surfaceN of points used to draw the surface of Mars. Next surfaceN lines: a couple of integers landX landY providing the coordinates of a ground point. By linking all the points together in a sequential fashion, you form the surface of Mars which is composed of several segments. For the first point, landX = 0and for the last point, landX = 6999
Input for one game turn
A single line with 7 integers: X Y hSpeed vSpeed fuel rotate power
X,Y are the coordinates of Mars Lander (in meters).
hSpeed and vSpeed are the horizontal and vertical speed of Mars Lander (in m/s). These can be negative depending on the direction of Mars Lander.
fuel is the remaining quantity of fuel in liters. When there is no more fuel, the power of thrusters falls to zero.
rotate is the angle of rotation of Mars Lander expressed in degrees.
power is the thrust power of the landing ship.
Output for one game turn
A single line with 2 integers: rotate power :
rotate is the desired rotation angle for Mars Lander. Please note that for each turn the actual value of the angle is limited to the value of the previous turn +/- 15.
power is the desired thrust power. 0 = off. 4 = maximum power. Please note that for each turn the value of the actual power is limited to the value of the previous turn +/- 1.
Constraints
2 surfaceN
Example
Initialization input
6 (surfaceN) Surface made of 6 points 0 1500 (landX landY) 1000 2000 (landX landY) 2000 500 (landX landY) Start of flat ground 3500 500 (landX landY) End of flat ground 5000 1500 (landX landY) 6999 1000 (landX landY)
No output expected
You can ignore this but you need to read the values.
Input for turn 1
5000 2500 -50 0 1000 90 0 (X Y hSpeed vSpeed fuel rotate power)
Output for turn 1
-45 4 (rotate power)
Requested rotation to the right, maximum thrust power
Input for turn 2
4950 2498 -51 -3 999 75 1 (X Y hSpeed vSpeed fuel rotate power)
Tilt angle changed only by 15 and thrust power only by 1
Output for turn 2
-45 4 (rotate power)
Same request as previous turn
Input for turn 3
4898 2493 -53 -6 997 60 2 (X Y hSpeed vSpeed fuel rotate power)
Output for turn 3
-45 4 (rotate power)
CODE:
#include
using namespace std;
/** * Auto-generated code below aims at helping you parse * the standard input according to the problem statement. **/ int main() { int surfaceN; // the number of points used to draw the surface of Mars. cin >> surfaceN; cin.ignore(); for (int i = 0; i > landX >> landY; cin.ignore(); }
// game loop while (1) { int X; int Y; int hSpeed; // the horizontal speed (in m/s), can be negative. int vSpeed; // the vertical speed (in m/s), can be negative. int fuel; // the quantity of remaining fuel in liters. int rotate; // the rotation angle in degrees (-90 to 90). int power; // the thrust power (0 to 4). cin >> X >> Y >> hSpeed >> vSpeed >> fuel >> rotate >> power; cin.ignore();
// Write an action using cout. DON'T FORGET THE "
// rotate power. rotate is the desired rotation angle. power is the desired thrust power. cout
Please help me with this C++ program and make sure its run. You can find the website to test it at (https://www.codingame.com/ide/puzzle/mars-lander-episode-2)
Please do not simply give me the code, please explain ( comments) on all the important code so I can understand what is that line of code function and I can learn from it.
Thank you
R- +30 3000 g3.711m/s? VS =-56m/s (X,Y) position of Mars Lander Mars surface HS =-20m/s Flat ground Landing site 0 0 7000 R- +30 3000 g3.711m/s? VS =-56m/s (X,Y) position of Mars Lander Mars surface HS =-20m/s Flat ground Landing site 0 0 7000
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started