Toribash
Prev Previous Post   Next Post Next
Original Post
violence evolved version 2: Now with working genetic algorithm and combo maker
hokay! I finally have a version of my GA that i'm proud to put my name to! The last one had several bugs and only kept track of the best move, this one actually works and has loads of cool thing for viewing your best moves. To run it just copy the files to Cgames\toribash\data\scripts and you can start it from the setup -> scripts menu. it will then go about evolving a good move.

I made this script so that you could have an AI opponent for any toribash mod out there. It doesn't matter about the rules different, it should learn them given enough time.

here is how it works:
(0) It starts by generating 10 random moves (aka individuals)
(1) it checks how good each move is (aka fitness value) by executing it
(2) The fitness value is: toribot_score - ukebot_score
(3) once all 10 individuals have had a turn it then takes the top 30% of the population
(4) These are then recombined using crossover(cutting in half, sticking back together) to make the next 10 individuals for the next round
(5) Some of the individuals are mutated just to keep things interesting
(6) goto (1)

Remember a genetic algorithm is probabalistic, meaning it will create a lot of terrible moves before it starts getting good ones (hence the random flailing), it also means that you'll probably get a different solution every time you run the algorithm. I generally left it running overnight to get a decent solution. The population size is set to 10 because I was debugging it, i'd recommend increasing it to 50 if you want to keep things diverse.

If you don't want to start from scratch every time you restart the algorithm there is a flag at the very top of the file called loadPrev, set it to true and it will read from the population file. A word of warning though! first you have to run the algorithm once with loadPrev set to false to create the best and population files (i'm sorry i had to do it this ugly way but the file IO for mods is awful)

I moved the get_fitness function to the top of the file, The fitness function is what drives the algorithm, i have added a very basic one that just tries to maximise the score. you can add what ever you want in there, distance moved, decapitations, disqualifications, dismemberment, etc but remember that if you just check for limbs removed then thats all the algorithm will care about. Even if it scores terribly and chops off all it own limbs in the process its still going to think it did great and get to have lots of kids in the next generation, so be careful what you ask it to do! Also if you do come up with a good fitness function please post it on the forum, I don't actually play the game much and you probably know a lot more about what it should be doing.

There is also a new loadBest application. This will read in all the best moves that you created during your run and replay them for you. You can move between them by pressing n for next and p for previous. As the best file appends new best moves you can actually see how your move evolved over time. Another word of warning! if you have been running the GA mod previously it is best to close toribash and reopen it before running the loadBest mod (again the damn IO is on the blink)

I've also included two other scripts, comboGA and loadBestCombo. They are very similar to openerGA except that you can set the number of moves you want him to make at the top of the file. Its still hard-coded though so he will make an initial move and then the next after (totalMatchFrames/moves) frames. Remember to have the same number of moves in the top of comboGA and loadBestComboGA otherwise it will not show the moves.

I think this is about as far as I can push this as a mod, the file is becoming a bit unweildy and the lack of file IO for mods is a real pain. After this I might re-introduce uke to evolve against but the speed is the primary concern. If I want to evolve REAL AI capable of dealing with counters and chaining combos (and eventually beating humans,mwahahahaha!) then I need to speed it up dramatically. Is there any way of disabling the graphics or running other programs from the mods that anyone knows of

Anyways I hope you enjoy it!

tips for speeding it up:
in the game type "/opt fixedframerate 0" <-this will mean it runs as fast as it can (thanks again deejay!)
in the game settings change the match frames to 250
turn on disqualification
remember the more rounds the better the move!
Attached Files
openerGA.lua (8.4 KB, 791 views)
loadBest.lua (3.3 KB, 560 views)
comboGA.lua (9.1 KB, 695 views)
loadBestCombo.lua (3.8 KB, 593 views)