Mars Lander - Puzzle discussion

@fededevi, thanks for this message that help me for two things.

First I’ve spent 1h trying to compute the values of X and Y on my own to do some optimizations, but I didn’t thought about using the mean of the previous and new values for the accelleration. That’s why I was always a bit off.

And also I was wondering how some people were doing to use programs that “learned” for all their attempts. From what I understand, the trick is to use external tools.

Thanks again!

1 Like

Hi all. I cant pass the 300L challenge. I get 306L left, but the game reacts the same, nothing new happens. On the Achievements page I can see a text telling me to pass it again with more than 300L left, but it doesn’t work…

Anyone knows why?

Brake advance. You do not spend a lot of fuel if

help me to fix my physics simulator - it’s having an error in calculations, and it’s growing fast with turns

dir = vector(-sin(newRotationInRadians), cos(newRotationInRadians))*newPower;
newPos = pos+(dir+(GravityVec+velocity)/2).rounded();
newVelocity = GravityVec+velocity;

looks like newVelocity is the same as in Game Info for all the time, but newPos’s getting a huge error in 30 turns

1 Like

The formula for position is x = x0 + v0t + 0.5at^2
t in this case is 1
so newPos = pos + velocity + (dir+GravityVec)/2

This is inaccurate since you use the new velocity to calculate the updated position, when in reality you should use the old velocity. (Also not sure why you are subtracting acceleration)


Edit: After some testing, I have made a strange discovery…
I took the starting coords and velocity and simulated about 100 moves ahead and compared the results and what I found is that
new.x = old.x + new.hs + 0.5accx
new.y = old.y + old.vs + 0.5
accy
gives the correct values.

Perhaps someone can verify this?

1 Like

No, the physic is OK ; this gives correct x, y, vx & vy along the whole simulation for all cases:

[code]#include <stdio.h>
#include <math.h>
#ifndef M_PI
#define M_PI 3.1415926535898
#endif
#define G 3.711

int main()
{
int surfaceN; // the number of points used to draw the surface of Mars.
scanf("%d", &surfaceN);
for(int i=0;i<surfaceN;++i) {
int landX; // X coordinate of a surface point. (0 to 6999)
int landY; // Y coordinate of a surface point. By linking all the points together in a sequential fashion, you form the surface of Mars.
scanf("%d%d", &landX, &landY);
}
// game loop
long double x,y,vx,vy;
for(int k=0;;++k) {
int X, Y;
int hSpeed, vSpeed; // the horizontal & 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).
scanf("%d%d%d%d%d%d%d", &X, &Y, &hSpeed, &vSpeed, &fuel, &rotate, &power);
if(k==0) {
x = X; y = Y;
vx = hSpeed; vy = vSpeed;
}
int angle, thrust;
// … angle & thrust calculation …
if(angle>rotate+15) angle = rotate+15;
if(angle<rotate-15) angle = rotate-15;
if(thrust>power+1) thrust = power+1;
if(thrust<power-1) thrust = power-1;
x = x+vx-0.5sin(angleM_PI/180.)thrust;
y = y+vy+0.5
(cos(angle*M_PI/180.)thrust-G);
vx = vx-1.sin(angleM_PI/180.)thrust;
vy = vy+1.
(cos(angle
M_PI/180.)*thrust-G);
fprintf(stderr,“x -> %.0Lf ; y = %.0Lf\n”,x,y);
fprintf(stderr,“vx -> %.0Lf ; vy = %.0Lf\n”,vx,vy);
printf("%d %d\n",angle,thrust);
}
return 0;
}[/code]

2 Likes

i already fixed that, it was about rounding - it works without rounding

Actually not.
If we want to make a terraforming to turn Mars into an Earth clone, we have to pollute it. And we humans are EXPERT at polluting Planets. Planet Mars needs Carbon Dioxide which comes from Pollution and that’s because the process would increase the atmospheric density and eliminate the need for pressurised spacesuits making the Red Planet more habitable.

So … yeah … This simulation is against making Mars “better”.

Depends on whether you define “better” as “more habitable” or as “more like natural state”. I suspect that you will get different answers to this if you polled different people. :wink:

  • danBhentschel

:spider_web: NASA has finally put its own solution on GitHub. Honestly, her code a little too bloated for my taste :sweat:.

1 Like

just started working lvl 2, and am I to assume we have to manually strafe left and right to fide the landing site first? as getting the land_x and land_y from the input is only resulting in the endpoint (using python)
Thnx

I’m struggling with the Java portion of lvl 1. A tip in the right direction would be most appreciated.

I wrote a genetic algorithm to optimize the lander path, check it out here: https://www.reddit.com/r/genetic_algorithms/comments/549o5m/example_of_optimizing_a_moon_lander_path_in/

The code is on github: https://github.com/fafl/genetic-lander/

2 Likes

Your solution will not work for the other levels without a ridiculous amount of experimenting!

Another approach is to look at the desired end result (safe landing speed) and correct the craft for any error at every stage of the descent. That way is more scalable to the other problems (not to say they are easy of course).

This exercise is really confusing and unclear in many ways.

  • It is not clear what part are fixed and what are not: the platform is always below, but is it always 100m high?

  • No test case input/output is provided, you have to print yourself the different test case, and retro engineer how the speed and position are computed.

  • The mix variation of integer (speed, position) / double input (gravity) makes it difficult to understand what is expected (rounded values? ceil? floor?)
    Many people want to write logical and good code for this exercice, telling them that a trivial answer would be enough is not an excuse for not rewrite the description.

  • If you try to print the output of a free fall, you realize that the variation of speed (acceleration) is not constant (sometimes -3, sometimes -4), even if the power of engine is always at 0. It makes it very difficult to retro-engineer, and to build test cases for it.

3 Likes

sorry but how do u achieve landing with more than 300 fuel remaining?

By landing as soon as you can, in order to burn the less fuel as possible. I won’t explain in detail here.

To make it 100% clear for people struggling with rounding, just store everything (position, vectors) as double, and ignore the input CG is giving to you, as it’s innacurate integers while they still use the accurate doubles in their engine.
Instead use what you’ve computed from your previous round, and it should all be fine.

As many people already mentionned, not so cool for the players, and makes unit testing complicated since you can’t just use CG input to generate a test case.

2 Likes

You can still compare your own rounded value vs CG input to spot deviation.

It would probably be clearer if the calculation used was given in the description,
however it actually use standard kinetic formula:

The force of gravity, g = 3.711 m/s²
Time to splat: sqrt ( 2 * y / g )
Velocity at splat time: sqrt( 2 * g * y )
time = [ −vi + √(vi² + 2gy) ]/g

1 Like