Toribash Season 7
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, 734 views)
loadBest.lua (3.3 KB, 511 views)
comboGA.lua (9.1 KB, 638 views)
loadBestCombo.lua (3.8 KB, 547 views)
I just wanted to say this mod is a fantastic bit of coding genius.

A little hint if you want to cause the game to run faster, its possible to use /opt blood, trails, uke, tori, hud, and a variety of other parameters in order to remove them from sight and in most cases, increase the framerate.

All though I do not know all of the parameters, you can gain a huge framerate boost if you /opt uke 0 and /opt tori 0, although you will not be able to watch the progress of the fight.

Obviously you will also want to turn off shaders and anti aliasing (I believe they can both be turned off under options) , if you are using them, as they contribute very much to the framerate.

Sorry I could not be more helpful as to all of the /opt parameters, but I hope I at least gave you a few ideas as to increasing game performance, considering I would love to watch this mod develop.
oh yeah
simply amazing! its funny to set it to 100 moves and 100 moveframes... he spazzes out! Its like he is having a seizure! check out the replay! He also tends to rip off both of his own hands... o well. time to set it back to like 10 moves! lol
Attached Files
comboGA spasms.rpl (138.4 KB, 184 views)
[SIGPIC][/SIGPIC]
Mammary Gland Holders of the Humanoid Lifeforms Commonly Known As, Homo Sapiens.
Very cool keep up the work!
You Better Get My Damn Ravioli!!! I'm Gonna Unleash the Beast up in this B***H!
Well
The script works great, but it seems to have problems starting off if the original starting points of uke and your tori are too far apart (instagibfeet)
Is there any way to insert a starter move for the tori to learn off of?
wow, nice script. mine is evolving an arm break now
*edit*
or maybe a suicide
Last edited by SC501; Mar 18, 2010 at 05:54 PM.
[ESSENCE]
What about fitness:
(toribot_score + ukebot_fractures + ukebot_dismembered) - (ukebot_score + toribot_fractures + toribot_dismembered)
I think it would get better in less time. You can do a super score combo, but a combo where you break oponent's members I think is better.