I think you may want to do some research on PID regulators. Auto pilot is a regulation response. Some regulators even go as far as being able to compensate non linear input to get the desired response. (see [off topic] section for little story*)
PID stands for "Proportional Integral Derivative". In electronics they are implemented with RLC circuits. They are "degree 2" which means they tend to target fast, and if the amortizement is not enough they can oscilate.
Numerically, you could try to make a learning machine, that tries varying ratios of modulated input. Do you know PWM ? Pulse-width modulation of power. It uses "hashing" of a DC source to create an average that can be modulated. Your engine, in a lunar lander, is a On/Off controller, therefore, unodulated it is a DC source. The position of your module is the integral (the
PID) of your engine thrust. You can decide of a pusle frequency (10Hz, 30Hz?). Like a human would do actually, only faster so you have finer modulation grain.
Then your regulator's (black box) input is a float number [0,1] signal that is used to change the width of the pulse. (look it up on wikipedia its going to be immediately clear what I am talking about). Then use a target, your target is a speed curve, the speed is a function of distance to land. Your regulator wants to match this curve. So at the beginning, the speed target is high because you are still far from land. your regulator will not apply thrust until the lander has accelerated near the speed target. then it will approach that target, and the derivative (speed at which the target is being approached), will play a role in the regulator to trigger the decision to apply thrust now, not after the target is overpassed.
Then this is when the actual width of the pulse should be learnt, by some memory (machine learning?) able algorithm. Not much experience with that though. Your regulation is not linear because of gravity, so it makes it slightly unconventional. But it should work more or less even without the learning system. (with some manual tweaking of the magical constants, by empirical testing. physicists could calculate the "charge constant" and be able to determine those factors mathematically, but I am no physicist.)
and this is only unidimensional for now. (vertical)
A simpler goal as a first implementation would be to try to oscilate around the speed target by using ON/OFF regulation (not smooth like PWM-PID) but enough to proof the concept quickly, and familiarize yourself with the reactions of the regulator.
Just apply full thrust when over the speed target, to slow down, and release thrust when under speed target, to let it accelerate down naturally. The speed target still is "distance(lander,ground) * magical constant".
Of course mathematically, if this curve was respected perfectly, it would create the snail curve problem. If a snail divides his speed by two everytime he makes half the distance to its target, it will never reach the target. this is a contra-exponential assymptot. but we are in physics, not math, so some inertia and luck will solve this problem. Unfortunately, the same "luck" and "lag" will also result in crashes at times. But going to smooth PD or PID with PWM with some tweaking will get the landing routine perfectly safe at all times, eventually.
good luck, report progress ! :)
This is actually something that happened as a problem in some industry. Consider this story: One day constructing an helicopter, somebody mounted the throttle mebrane in reverse. Nobody thought it would be possible to do such a thing so no defense existed against that. The membrane is a flexible piece of rubber/textile or fibers, that exists in the gasoline pipes, and is pushed by a piston to regulate gas flow to the engines. The control of the throttle does not go directly from manual lever input, to the piston drivers. It gets through a regulation device that modulates the piston force to get to the exact desired membrane position.
The expected lifetime of the normally mounted membrane was 50k hours, but in reverse much less, because the piston had to apply much more force, however it went unnoticed, and the membrane broke quickly, helicopter crashed, people died. (true story)
intelligent regulators are powerful but could be a risk if this kind of things is not considered :)
in your case, it is just a game, so you're OK though :P hehe