Mars Lander - Puzzle discussion

Why wont my Second while loop run?

 while (X < 5600)
    Console.WriteLine("-20 4");
       while ( Y < 590)
              Console.WriteLine("0 4");

Basicly once the space ship reaches a section of the mars it will start to counter
the gravity and stuff but once all that works the while loop inside the while loop that supposed to initiate once the spaceship is near the ground to land wont run why?

Also yes I am a noob :> I did not finish the second one but i just wanted to see what the 3rd episode looked like

The variables X and Y won’t update themselves. If you need updated values of the position, you have to read the inputs again and update those variables after your Console.WriteLine.

After 1 month trial, I finally pass Level3 with reinforcement learning approach!
my steps:

  • write a simulator, modified base on “gymnasium” LunarLander env
    mainly learn Box2d to simulate physical movement and detect collision
    design action space: since the space is large, I reduce the action to 3x2 (+15/0/-15 for rotate with clip of ±45degree, +1/-1 for power with clip of 0-4)

  • train a policy with help of “stable baseline3” PPO model
    tried DQN first, then switch to PPO
    need to carefully design the input and the reward function
    input: in final version, I give a 13 dimension vector as input [distance in 6 directions, h/v speed, rotate, power, relative h/v distance to the middle of landing zone, whether the lander can see the LandingZone]. normalize with modified sigmoid function to get all input in range [-1,1].
    reward: lots of pains in reward function design, +++ for success landing, + for approaching (i use the angle leftOfLandingZone-rocket-rightOfLandingZone as a indicator), — for collision, - for too high speed, - for high power, – for wrong direction
    training: since the space is very large, I train gradually (at beginning, the rocket start very near to the LandingZone, to get a good Q-value/Policy for that area, then gradually move the start far away and eventually the actual start point). I use random map between the 2 tests and random starting point (with randomness on position(with in the chosen area)/speed/rotation…) in “make_vec_env” to train.
    network arch: first I used a 4x200 nodes policy network and a same form of vf network, but then find out the parameters are too big for the 100k code limit.
    in final version is 2x100 nodes policy network and 4x200 vf network.

  • transfer the parameters (tensor or numpy array to base64 string) and use in codingame.
    thanks to the help from @ jacek1 and @ FrancoisB about this part :))) (the Unicode method is genius, but since I reduce my network, I won’t need that magic this time)
    manually calculate the “prediction” part to get output from neural network

And that’s it, enjoy the game!


Hello everyone,
When I did this puzzle, I wrote a program that allowed me to run my solution locally and draw on the visualization. This allowed me to see the trajectories I was simulating and it helped me a lot.
So I wanted to share my program with you, in case it might help you too.

Have a nice day !

1 Like

What is difference bewtween First and second episode? i complete second used first code soultion :slight_smile:

How did you even manage to make the code for it? besides i thought i had to do a entire if factor to do all of these conditions, which is driving my brain insane.

I also tried a physics approach (computing the distance necessary to brake and comparing with the current one) and it failed as well. I looked at the logs carefully and I found something weird (even in the episode 1):
as long as I don’t switch on my thruster the (vertical) speed increases as expected (well decreases as it is negative)
Then when I switch on the thruster at full capacity (4) I was expecting the speed to stabilize right away (and even reduce a bit, by 4-3.711=0.289 to be precise) but it still increases significantly for 2 rounds (more than 2m/s2). It doesn’t make sense to me…

Got it: the thrust cannot go from 0 to 4 in one second, it will increment second after second…
if you were at 0 and ask for 4 you will get 1 then 2 then 3 then 4

This puzzle sems broken. The default code reads in an x and y that when output with cerr do not match the Game Information.

### Game information:
Landing phase starting X=2500m, Y=2500m, HSpeed=0m/s VSpeed=0m/s Fuel=500l, Angle=0°, Power=0 (0.0m/s2)

### Standard Error Stream:
landing left (1500,100) landing right (3000,100)
x = 5000
y = 5000

### Standard Output Stream:
0 1

### Game information:
Landing in progress... X=2500m, Y=2499m, HSpeed=0m/s VSpeed=-3m/s Fuel=499l, Angle=0°, Power=1 (1.0m/s2)

### Standard Error Stream:
x = 0
y = 0

Would you please send me your code in private message and I’ll take a look?

All I did was take the default code and output x and y.

I don’t see what you posted before. The following is shown in the console:

### Game information:

Landing phase starting X=2500m, Y=2500m, HSpeed=0m/s VSpeed=0m/s Fuel=500l, Angle=0°, Power=0 (0.0m/s2)

00 36

### Standard Error Stream:

x = 2500

y = 2500

### Standard Output Stream:

0 0

### Game information:

Landing in progress... X=2500m, Y=2498m, HSpeed=0m/s VSpeed=-4m/s Fuel=500l, Angle=0°, Power=0 (0.0m/s2)

01 36

### Standard Error Stream:

x = 2500

y = 2498

### Standard Output Stream:

0 0

### Game information:

Landing in progress... X=2500m, Y=2493m, HSpeed=0m/s VSpeed=-7m/s Fuel=500l, Angle=0°, Power=0 (0.0m/s2)

not for me, the x and y retrieved from cin, do not match the Game information. Not sure what’s going on, I’ll just try a different puzzle.

I have created a series of code solving videos for Mars Lander Episode 1. The videos walkthrough demonstrates how to approach the problem in a way new programmers can follow. You can watch them in order and follow along to solve the puzzle with me, or you can pick and choose the videos that work best for you. The whole playlist can be found here:

The constraints on the puzzle say

0 ≤ fuel ≤ 2000

but that doesn’t seem to be the case in practice. I get values as high as 9000. Is that a typo?

Is it Mars Lander Episode 1, 2 or 3, and which test case? Can you copy and paste here the game information from the console?

Edit: I am sorry for the confusion. The l for liters looks almost like a 1 in the console output. It is all correct.

I’m using Ruby and am just learning and can’t figure out why this won’t work.

[Mod Edit: Avoid posting code on the forum]

please help :smiling_face_with_tear:

There are at least 2 issues:

  • All the lines you’ve added have syntax errors. Please look for the proper syntax.
  • You cannot increase or decrease power indefinitely as there’s a lower limit (0) and an upper limit (4).

Also, please avoid posting codes on the forum. If you need further help, you may send a private message to me. Thanks.

what are the syntax errors and/or is there a tool to help me understand the error codes?