Using a genetic algorithm to power “infinite” elytra flight (client mod inside) via /r/Minecraft


Using a genetic algorithm to power “infinite” elytra flight (client mod inside)

I recently acquired my first elytra wings in survival, and after enchanting them with mending and unbreaking III, I really wanted to use them as my main method of long distance transportation.

Google gave me this video, that shows you can actually achieve "infinite" flight (you are still limited by the elytra durability, but you can now gain altitude over time) :
https://www.youtube.com/watch?v=l-zHXNd8mnI

This is very promising, but the method provided in this video is incomplete : you know you should aim for the -40 angle when going up, and for a 40 angle when coming down, but there are other variable that impact how much altitude you gain.

For example, how do you know when you have accumulated enough speed to start going up again, and how do you know when you have depleted all your momentum, and you should start to dive again.

There is another factor, which is the speed at which you move your mouse when you change orientation : go too fast, and the abrupt angle will make you loose all your momentum. Too slow, and you will loose too much altitude.

In total, when doing a "parabolic flight", there are 6 variable that can be fined tuned to get the best results :
* pullUpAngle
* pullDownAngle
* pullUpMinVelocity
* pullDownMaxVelocity
* pullUpSpeed
* pullDownSpeed

Simulation and genetic algorithm :

I browsed the minecraft source code to find the part controlling elytra flight, and reproduced it in a test application. Plugging in the values from the video above (-40; 40 angles, and velocity and speed that "felt right"), I get the following flight profile, starting at a height of 250 blocks : GRAPH

This graph is over the course of 5 minutes, or 6000 client ticks. We gain 0.0177 vertical blocks of altitude for every horizontal block traveled, which is not too bad, but I had a feeling the values of the parabolic flight could be tweaked to produce even better results.

The algorithm that controls the elytra flight is complex, and it cannot be easily reduced to mathematics equations that we could integrate to find the optimal values. I decided to use another method to find if I could gain more altitude using the elytra, a genetic algorithm.

I you are unfamiliar with how genetic algorithms work, you can read a primer about them here

In short, we generate a bunch of random solutions to the problem, and make the best solutions "reproduce" over and over, hoping that after enough generations, a good solution will emerge.

Here is a new graph showing the flight profile of my original solution in blue, compared to the solution that was found by the genetic algorithm in green :
GRAPH

The genetic algorithm gains 0. 0495 vertical blocks for each horizontal block traveled, which is almost thrice as good as our original solution! However, the new flight pattern covered approximately 10% less ground over the 6000 client ticks of the experiment.

Here are the variables found by the genetic algorithm :
* pullUpAngle : -49.44969
* pullDownAngle : 37.7458839
* pullUpMinVelocity : 1.76282883
* pullDownMaxVelocity : 2.1081
* pullUpSpeed : 2.08719635
* pullDownSpeed : 0.224041611

The Mod : I created a mod (mods, one for forge and one for liteloader) that use these values to automatically fly the elytra to gain altitude. The mod looks at your current angle and velocity, and modifies the pitch of the player accordingly.

Using this mod, with my original solution, the player gains 5 blocks each "cycle" (going down then up), and 12 blocks each cycle using the solution found by the genetic algorithm.

To try the mods, simply start using your elytra, and a line should appear containing your flight information (altitude, velocity, …). Press "U" to start the "auto flight" mode, where the mod will adjust your camera automatically. Feel free to try out the mods and let me know what you think! Please bear in mind that I know close to nothing in minecraft mod development, so these may be very sloppily written. If you want to improve on this mod I'll be more than happy to share my code 🙂

Forge Mod
Liteloader Mod

Future work : For now the flight control is very simple, there are only two phases : going up, and going down. Using a more sophisticated flight pattern could result in even better results. Artificial Neural Networks could be used for this. The inputs of the network could be the current angle, and the current vertical velocity, and it's output would be the new pitch to apply to the camera.

Furthermore, my selection function for the genetic algorithm was partial to only altitude gained. You could use the genetic algorithm to design other flight patterns that would emphasize other desirable aspects, such as a smaller amplitude (you could then take off from a lower altitude), or horizontal speed (so that you would get to where you want to be faster)

Submitted December 14, 2016 at 12:32PM by louislourson
via reddit http://ift.tt/2hFZzwg