Good vs. Evil

  • The FTB Forum is now read-only, and is here as an archive. To participate in our community discussions, please join our Discord! https://ftb.team/discord

lenscas

Over-Achiever
Jul 31, 2013
2,015
1,801
248
22 assuming the code works at first try I think I have the most important parts for the genetic AI.
I have a system in place to generate 100 lists (also called Genomes) with 4 to 8 genes.
I have a system in place that allows the rest of the program to grab a genome and let it make decisions.
When the game needs a new genome the old one gets its fitness score calculated.
I have a way to sort genomes based on their fitness.
I have a way to "breed" genomes and a way to remove the bad ones to make room for the new children.
I also have a way to mutate all genomes in the current population.

Currently I do see 1 major problem though, when a genome mutates to get a new gene it will most likely become much worse as the every gene after the new one stops lining up correctly. So, I may need to insert more genes at once or put a system in place that reduces the chance of genomes that recently mutated to gain an extra gene from being culled right away.

Maybe I can make the gene count important for the fitness score? Because, lets be honest the more genes a genome has the more actions it can prepare before it will be forced to loop.
 

duckfan77

Popular Member
Mar 18, 2013
80
683
118
20 I think I have the main logic for the Simulation Program I'm working on for school done. It should simulate everything accurately, I just need to put in statistics gathering systems so the data it generates is useful.
 

lenscas

Over-Achiever
Jul 31, 2013
2,015
1,801
248
21 so... by pure luck one of the AI's managed to survive 30000001 frames.
If I did my math right and assuming there is no lag you would need to play 5.78703723 days to get that many frames.

I'm going to assume that either there is a bug as the AI's aren't implemented properly yet and their environment isn't fixed yet, so each round is different.
 

lenscas

Over-Achiever
Jul 31, 2013
2,015
1,801
248
21 currently doing a lot of cleanup.
I tore out the parts that update the game state.
The function to get key presses needs to be supplied to this new part, as well as the function to render the game.
It also doesn't deal with looping the game any longer, its now just a function. As a result, it now also doesn't depend on the sleep function any longer.
 

duckfan77

Popular Member
Mar 18, 2013
80
683
118
20 Currently I'm working on adding statistics gathering to the simulation, so the results it produces are actually usable.
 

lenscas

Over-Achiever
Jul 31, 2013
2,015
1,801
248
21 so....even gen 1 survives too long for my liking, assuming my code is correct.
Kind of hard to really check right now as not everything is in place yet.....
 

duckfan77

Popular Member
Mar 18, 2013
80
683
118
20 Always an interesting place to be. I think it works, but it isn't finished so I can't really check yet.
 

lenscas

Over-Achiever
Jul 31, 2013
2,015
1,801
248
21 so.... After increasing the difficulty of the game a good bit (astroids are now spawned more often and you can use your laser less often) and some more work done on working with the various lists I now have something that manages to somewhat improve itself. It is still far from great (the current best survivied time is 2699 frames. Meanwhile, my basic bot survives 12289 frames
 

lenscas

Over-Achiever
Jul 31, 2013
2,015
1,801
248
19 and.. it gets stagnant long before that.
Its best score was 2700. The genes where
0111001000111111101
Our program reads 6 numbers (genes) at each frame, continuing from where it left off. So, before we go further lets make it more easily readable by splitting the genes up in the same way they get read. The genes can't totaly be divided this way, don't worry about that for now.
011100 ->frame 1
100011 ->frame 2
111110 ->frame 3
1

Having done this, we grab our handy action table, count the amount of one's in each frame and use this to get the action of the AI
Code:
frame 1-> 3
frame 2->3
frame 3->4
Code:
//possible actions
0 = "" (do nothing)
1 = ""
2 = "w" (go up)
3= "d" (go right)
4 = "s" (go down)
5 = "a" (go left)
6 = " " (shoot laser)
Now, lets talk about that lonely 1 at the end. If our program reaches the end it simply loops back. So, at frame 4 it first reads the single 1 left before starting at the beginning again.
As a result, it now only reads the first 5 instead of 6 as it already knew one. This causes all actions to change and be left with 2, which become 3,4,5 and eventually a full 6. After this, it will repeat.
The total actions "programmed" are thus
Code:
011100 ->d
100011->d
111110->a
101110->s
010001->w
111111->laser
010111->s
001000->nothing
111111->laser
101011->s
100100->w
011111->a
110101->s
110010->d
001111->s
111010->s
111001->s
000111->d
111101->a
This pattern gets repeated until it gets killed.
 

lenscas

Over-Achiever
Jul 31, 2013
2,015
1,801
248
19 the fact that both 0 and 1 where nothing was actually a slight oversight caused by me being stupid and not counting 0 as a possible action when I wrote that code.
Also, I discovered a potential bug where involving how I display the frames survived, the current genomes and the best genomes. As a result, the above mentioned genome may not be the one that scored 2700.

After fixing both of these problems I got a genome that managed to get a nice 73176, its genes are 010100001111111110. Note that it gets split every 5 instead of 6 and all actions are shifted by 1 (so the laser which was 6 is now 5, going up which was 2 is now 1, etc)

However, though I lack the tools to accurately measure this I believe the survival time eventually wend down, so I had to stop the program. Maybe making it so you can actually score points by killing stuff and have that be used together (or alone) to calculate a genomes fitness would improve things.