I'm trying to implement genetic algorithms into a game I'm making. I have a problem with the way I'm storing and accessing information in text files.
This is what I'm doing, basically:
- Every enemy has an array of integers as a variable (their chromosome).
- These arrays are stored by writing them as one line each to a text file. So it looks like:
1111111111 (a simple robot)
1123112213 (a slightly more advanced one)
- These are then accessed by being read into an array of strings (each line is one chromosome, which is one element of the array).
And so...my problem is that I now need to rip apart these strings and get them back into arrays of integers. So that after I have stored them and read them back, I can then mutate the values and create new "evolved" enemies.
I've just spent a dreadful couple of hours trying to figure out how I mght be able to accomplish this. The strings in C++ seem a lot less flexible than in Java, that's for sure.
Can anyone offer any guidance?