DSJ2 playing AI

General discussion about the PC version of DSJ2.
Post Reply
Posts: 3
Joined: 11 Jan 2020, 23:48

DSJ2 playing AI

Post by grzywa »

For the last two years I've been developing a DSJ2 playing AI.
Here are some of the results:

AUS 305.03m https://www.youtube.com/watch?v=T2-VnDzhN8Q
HUN 238.51 https://www.youtube.com/watch?v=ET50-LNzcL0
SVK 135.53 https://www.youtube.com/watch?v=omNfTHvwrno

Jumps from all hills are available on my channel.
Here's a playlist: https://www.youtube.com/watch?v=T2-VnDz ... KKjW20uxTz
Replays: https://drive.google.com/drive/folders/ ... Oaalwhzn9K

For those who are interested in technical details below is a brief description.

Before getting any results I had tried many different approaches.
The one closest to success was image processing using python + different libraries implementing neural networks.
It's biggest disadvantage is the fact that it is quite slow - as slow as a human player jumping.

Then I started playing with reverse engineering in order to get the game's state without using image processing.
As time went by I was able to retrieve more and more info from each frame e.g. jumper's position, wind speed or slope angle.

I also extended Dosbox's debugger to:
- control the game using breakpoints and embedded python scripting
- profile the game to find the most CPU consuming operations (that's frame drawing)
- enhance logging
- and much more.

Thanks to the profiler I was able to disable frame drawing enteriely but still be able to control the jumper.
As a result each jump now takes only 0.2-0.3s instead 10 to 20 seconds.

At some point, when I lost interest in the project for a while, one of the world records was beaten by more than 3 meters.
That was the moment when I realized that there's still room for improvements on many hills and my focus shifted from machine learning/neural networks to more or less "how far one could jump on each hill, all's fair".

Many players know that in order to jump further you need the so called "hurricane" - low wind on the inrun becoming huge wind during the flight phase.
To find such winds I recreated the entire wind algorithm and wrote a program looking for the best wind conditions using basically brute force.
The amount of possible solutions is so huge that it's not possible to check all of them, but I went through billions in a few hours for each hill which was enough to find conditions never seen before:)

In short there are different parts of the solution:
- reading gibbons from the best replays and then modifying them,
- finding the best wind conditions,
- finding the suboptimal angle of attack in flight on each hill,
- finding the best frame to start landing,
- reading/saving replays on demand outside of dsj
and a few more.

The progress of results is mainly produced thanks to genetic algorithms where each jumper is a genome, and each genome is a list of mouse actions taken in each frame.
All this was coded mainly in C++ (Dosbox Staging) and embedded Python 3 for genetic algorithms.
In far future instead of the genetic algorithms I will try to use reinforcement learning or NEAT neural networks too.
Last edited by grzywa on 31 Aug 2021, 23:08, edited 1 time in total.
Posts: 43
Joined: 17 Feb 2020, 12:56

Re: DSJ2 playing AI

Post by sneze2r »

Wow. I have couple of questions.

1. How did training process looked like? Have you used external servers with good GPU or is something like this possible on good desktop? And how long did it take for the model to learn?
2. All of the actions are performed by AI? Because I think takeoff could be handled by simpler script than AI.
3. Have you trained one model per hill? Or on all hills & conditions cumulativly?
3. Will you share this somewhere on git? :)
Posts: 3
Joined: 11 Jan 2020, 23:48

Re: DSJ2 playing AI

Post by grzywa »

Hi, thanks.

1. The first step is finding the best wind conditions and the best takeoff frame.
Sometimes when a wind during the inrun phase is really low, a jumper's speed is higher so it is sometimes better to takeoff a bit sooner. All this is automated.
Then I try to find a few promising attack angles at a given hill.
Given such starting conditions I put them as an input to the genetic algorithm combined in different random ways: different angles, different gibbons, different landing moments and try to choose the best jumpers from each population.

Usually it takes a few hours to produce really good results and it can easily be run on a laptop.
I've been thinking about using GPU to find more promising wind candidates, but I'm fine with what I have now.

2. So yeah, that is true, some parts are much simpler. I described some of the takeoff details in the 1st point. There is another problem related to details of calling a random number generator in each frame. Basically in order to achieve the same wind conditions each jumper has to end the takeoff at the same frame. There's no way around it. So once I find good takeoff it is reused in every jump. No AI needed.
I tried to train some takeoff model when I was playing with the image processing and it is a very hard problem in my opinion.

3. One per hill. Each hill is different.

4. No, I don't think so:/ Every mechanism I've implemented contains game's internals, so I think Jussi wouldn't be pleased if I published so many important memory offsets.
Posts: 147
Joined: 23 Jan 2007, 15:38

Re: DSJ2 playing AI

Post by Domin »

Thats impressive. Good job Grzywa 👌
Dominik Domin Machowiak
Post Reply