pastra98 / NEAT_for_Godot

An implementation of Kenneth O. Stanley's NEAT Algorithm for the Godot game engine, written in gdscript.
MIT License
36 stars 9 forks source link

Successful cars which are then saved are not usable in race mode. #6

Closed DisDoh closed 2 years ago

DisDoh commented 2 years ago

Hi, Very nice Godot Repository! I have tweaked the parameters and have been very successful with your code! But unfortunately while the saved nn cars are doing well in training mode, I can't compete against them because they are acting extremely differently on the same track and getting crashed for all of them. I've tried with and without tweak.

Can you help me?

pastra98 commented 2 years ago

Hi DisDoh, just to make sure I understand your problem:

The network should be saved under your user:// folder, which depends on your OS, in windows its in Roaming\Godot\app_userdata\NEAT_for_Godot\network_configs\. The selectbox in the race cars menu lists all the networks saved in that folder and loads them. I just tested it on my machine and it should be working.

Did you make sure you selected a genome from the latest generation? You could also try to do the saving programmatically, e.g. once the demo reaches a certain fitness threshhold, get the network of the best genome using ga.curr_best.agent.network, and then use network.save_to_json("name") method to save it in the user folder.

DisDoh commented 2 years ago

Hi Pastra98,

Thank you for answering,

What I've done: -Changed the number of initial link to 20. -Changed the numbers of raycast to 20 for the car sense. -Initiating of GeneticAlgorithm with 23 inputs.

I've changed the number of initial link(num_initial_links) parameters into demos/cars/cars_param.cfg and into params.gd to 20. I've changed the number of raycast(num_casts) from 8 to 20 in car.gd and adjusted the number of input when initiating the GenticAlgorithm in car_main.

With those inputs the cars are able very quick to drive in trained mode but unfortunately they crash then when loaded in race mode. Here two jsons files of cars network 16_52__1231.json.txt 16_52__1233.json.txt

Is there any parameters I should adjust for the racing mode?

Thank you!

pastra98 commented 2 years ago

Okay, I loaded your config and had the same experience. I stepped through the code for a while, and didn't notice anything special. But I realized that the car race scene doesn't load your parameter file, as that is usually done by the genetic algorithm and I didn't think of loading it there.

Since I don't have your params.cfg, can you try adding Params.load_config(yourconfigname) somewhere at the start of the cars/race_mode/car_race_main.gd file? Other than that I'm out of ideas for now..

DisDoh commented 2 years ago

Do you have a discord account? If so we could do it via Discord if you have some time?

In the configName I've just changed the initial number of link to 20 that's all. Here it is in case of: car_params.cfg.txt

I've tried to load the Config file in setup_race() at first place but without success.

pastra98 commented 2 years ago

Sure, lets set something up there, send me your handle via email: p.straberger@gmail.com .

pastra98 commented 2 years ago

Thx for your fix @DisDoh ! #7