Mars Lander - Puzzle discussion

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/

3 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

Sure, that’s what I’m doing.
But I’m used to generate JUnits based on the inputs CG is giving for one round, and then writing the asserts based on the inputs of the next turn. This doesn’t work here.

Guys, I need some help. I already solved Mars Lander with an hardcoded strategy based on if/then/else, but I wanted to practice stochastic algorithms, and as Jeff06 pointed out, Mars Lander may be a good candidate for this.

I’m trying Simulated Annealing at the moment, as it looked easier than GA to start with (less parameters to tune, easier to “figure out”). I’ll for sure try GA and MC/MCTS later.

However, I just don’t manage to make it work, and I’m crashing far more shuttles than ESA :slight_smile:
Here’s what I’ve done:

  1. simulate the “game engine”: DONE (took some time due to rounding issues as mentionned above, but always correct now, including crash and landing prediction)
  2. implement SA algorithm, based on wp and this: DONE
  3. tune the SA, deciding on initial temperature, annealing schedule, defining what is a “solution”, generating the first solution, generating a neighbour from a solution, and writing the “energy” fonction (score, fitness, whatever you call it): DONE but most probably wrong in one or several of these
  4. have performant code to have enough simulations done in 100 ms (or 1s for the first turn): ONGOING, at the moment in Java i can “apply” the game engine on a gamestate roughly 500k times in 100 ms. The number of playouts then varies depending on the chosen depth of a solution (for example, 10k with depth 50). I’m not spending time here at the moment, I think that it’s enough and that I should more focus on 3.

And here’s what I get as results: crashes, crashes and crashes :slight_smile: I’m not even trying to optimize the fuel or working on complicated levels.
If I set the depth too high like 150, I’m not even finding one solution in the first second. They all end in crash, so the evaluation of the solution is always the worst possible one.
If I set it too low like 10, then the shuttle goes too fast, not anticipating early enough the coming crash.
Inbetween like 50 does not work any better.

So here are my questions :

  1. Is it correct to try SA on this problem ? I think it is, but if you think otherwise please tell me why.
  2. What depth should a solution have ? If I understood well some comments, some people take only the remaining fuel at landing into account to compute the score of a solution. It then means that solutions should have enough depth to at least allow a landing, so 150 looks like a minimum ?
  3. For the score/fitness, at the moment I’m using a mix of the distance to landing target (middle of the landing zone) and of the speed of the shuttle. When I’m far away from the target, I focus on reducing the distance, when I’m close enough I’m more focusing on controlling the speed, in order to allow for a valid landing. For sure I’m not going to optimize anything like that, but I should easily find solutions. At least this is what I thought, but CG contradicts me :stuck_out_tongue:
  4. Any advice to share on the initial temperature and it’s annealing scheduling ? For now with a depth 50 for instance I start at 100, removing 0.1% at each iteration, so ending close enough to 0 at the end, which is what we want.
  5. Any advice on how to generate the first solution ? For now it’s a completely random chain of actions (within the boundaries of rotation / thrust changes allowed by the game from the previous state)
  6. Any advice on how to generate a neighbour ? For now I’m picking randomly one round, then modifiying it randomly again.
  7. Any advice on the score/fitness function ? Does my distance / speed mix makes sense ?
  8. Did I completely misunderstood SA ? :smiley:

I think that my biggest problem lies in 6, or maybe 5. Feedback would be much appreciated :slight_smile:
I can share replays if it can help to diagnose the issue, or also pseudo-code.

3 Likes

Quick update for those who may be interested: I’m now correctly landing !
What I changed:
A) fixed two bugs in the physic engine related to the end game
B) about 5), from one round to another I’m taking the best solution from the previous turn to initialize the current turn. For the first turn, I’m reusing my good old “ifThenElse” AI to initialize, in order to “drive” the SA in the correct direction. Feels a bit like cheating, but works.
C) about 6), fixed neighbour generation, since changing a round rotation and/or power was sometimes “invalidating” the subsequent moves, because of the rotation and power maximum change restrictions. So I’m now “adapting” the subsequent moves to make them valid.

And that’s it. Submitting on the optimisation puzzle landed me on rank ~270, which is not too bad when my only objective so far was just to land correctly.

1 Like

is initial game input always sorted from least to greatest by x value?

1 Like

PID ControllerDead reckoningTrilateration, all those things are way to hard.

All you gotta do is controll the speed to keep it in the limits, check if you have to move right or left depending on position and calculate the angle you need to keep height (=-+21). When you are above landing area just fall softly.

I tried PID before and it would work but it was way to complicated finetuning it for all the tests.

1 Like

I really liked this puzzle. I thought episode 2 was the most dificult medium puzzle, mostly because I really wanted to optimize fuel. It paid off when I found that there is also an optimization verison of this puzzle.
It helped and was fun to play, between coding sessions, the game that probably inspired this puzzle (http://moonlander.seb.ly/) which is an old arcade game.

2 Likes

It’s trying to get the extra achievement that I think most people are having trouble with (at least that’s what I’m having trouble with).