is initial game input always sorted from least to greatest by x value?
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.
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.
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).
Could you explain me why you need to substrat (currentAccelleration * 0.5) to the currentPosition ? I don’t understand that. Thanks !
pos = pos_initial + velocitytime + 0.5acceleration*time^2
You will find that formula in physics books or wikipedia.
Fededevi1 added 1acceleration, so he has to subtract 0.5acceleration.
Short answer: This is what it does on their server.
Long answer: When you are calculating integral on some continuous function with discrete steps, like the simulation is doing, (integral of velocity over time) -> distance; instead of using the function value(velocity) at the start of the time step or at the end of the time step you can use the average velocity between the 2 points. This will usually provide a more precise integration.
Since in my code I update velocity before the position, when I update the position currentVelocity is actually the velocity at the end of the step. By subtracting half of the accelleration I basically remove that half velocity delta to have the average velocity between the 2 steps. The code can be confusing to understand like this but basically it is the same as writing:
currentAccelleration = thrust + GRAVITY;
currentVelocity = currentVelocity + currentAccelleration;
halfStepVelocity = currentVelocity + currentAccelleration * 0.5;
currentPosition = currentPosition + halfStepVelocity ;
…I think
Have Fun!
Very clear, thanks !
Thanks, that make sense.
hello i am new in python just a simple question i don’t understand how resolve ‘there is no spoon Episode 1 in python 3’ i tried this : if v_speed < -40:
print (power = 4)
if h_speed > -40:
print (power = 0)
but after this i have any problem can you help me please …
You want to solve There is no spoon or Mars Lander?
Only Level1 using C language, I guess I just don’t get it. I thought something simple would make the program work correctly.
Based on the hint, I used
if (vSpeed <= -40)
{
power = 4;
}
else if (vSpeed > -40)
{
power = 0;
}
But no matter what I did, the simulation just ran the same way. I don’t want the answer but any hint getting me on the right track would be nice. Thanks.
yep buddy i tried the same code… still dont know whats up… its weird
I had my code in the wrong place.
Hi, I’m coding in python and I want to define two variables “thrust” and “rot” as integers and then simply put as output print(“rot thrust”).
However I’m getting the error:
‘Expected two integers but found ‘rot’ and ‘thrust’’
Does anyone know how to solve this?
Try print("{} {}".format(rot, thrust))
or similar.
Or print("%d %d"%(rot,thrust))
.
Hi, Thank you for this nice problem.
Since I am a physicist, I would like to signal an error: “a push force equivalent to X m/s² is generated” is faulse. Force unit is kg.m/s2 or N. So in the case of your puzzle, you can say that :
a push force equivalent to an acceleration of X m/s².
Best regards,
Nicolas
Hi,
I’m trying to learn genetic algorithms and I think that this is a good problem for it.
I’m using a single chromosome that I try to mutate to find a good solution.
My genes are (R,P), where R is a rotation (I’m only using 15° increments, so -90, -75…) and P a power (0 or 4).
My fitness function gives a tuple:
- horizontal distance to the landing site,
- vertical distance to the landing site,
- the max between 38 and the abs of the vertical speed
- the max between 18 and the abs of the horizontal speed
- the last angle
- the fuel used
- (horizontal speed)²+(vertical speed)²
Of course, I’m trying to minimise that.
I’ve got 2 mutations functions. The first one pick a random moment and tries every possibilities with (angle-15,angle,angle+15) and (0 and 4) for the power. I keep track of the moment picked to no do twice the same thing, until I find a best result.
The second mutation function just go through all the genes and change them with a probability of 2/n, where n is the time before landing/crashing.
When my first function pick a moment that has already been tried, it calls the second function.
My problem is that it almost works. I can pass all the tests of mars landers 2, but not each time. Depending on the test, I my have a success rate between 30% and 90%.
The problem is that If I cannot find a good chromosome during the initialisation (since I have more time), I barely manage to get better during the other steps.
I can get around 1000 mutation during the first step and between 50 and 100 for the later steps (of course for the last ones, I can get much better).
I’m using python and I don’t know if I can get faster algorithms.
Do I have to use a small population (like 20 chromosomes) and use a crossing function ?
Should I give more possibilities for the angles and the power ?
And how do you test if you crash ? I have a function that works for Mars Landers 3, but maybe it’s taking too long for this case.
Any help is welcome.
Thanks.
A few thoughts (in no particular order):
Regarding the GA, are you simulating one turn at a time or multiples? The post wasn’t clear on that. I’m assuming you’re looking several turns into the future but if you aren’t, you should be.
A crash in ML2 is easier to detect than in ML3 since there’s no cave component to worry about. You can just look for a negative altitude when you’re not above the landing site, or negative altitude and too high a speed / nonzero angle when you are.
Horizontal and vertical distances are incomplete heuristics for cases like the canyon one… you’re close (horizontally) to the landing site but there’s a mountain in the way, what now?
Finer angle adjustments might help.
Higher speed thresholds might help. I set mine to the highest speed where I could reasonably expect to slow to a safe speed before landing. That way I could make use of some of the high initial starting speeds.
How does your fitness function score a guaranteed crash or landing?
Lastly, a scripted language like Python isn’t well-suited to GAs since they perform best when you can run thousands of generations. Not saying it can’t be done, but it’s easier in a compiled language due to the speed difference.