Hi.
In the game that I am making, I use a genetic algorithm to evolve the enemies.
The way I store the enemies "DNA" is in a text file.
But, when I am reading the text file in and storing all the relevant bits of information something is going wrong and it is causing crashes at various different points in the game cycle.
If I remove this bit of code, the game is fine. So I am sure that this section is the cause of all the crashes.
I suspect that it is the while loop that uses .fail(), but I'm not sure.
Can anyone see why this code isn't working properly?
Any advice/comments/suggestions are much appreciated.
Here is the code, and an example of the content of the text file:
Code:
ifstream file_to_read("DEAD.txt");
while (!file_to_read.fail()) {
char chromo_char_read[12];
char junk_sep_char;
string fitness_string_read;
file_to_read.get(chromo_char_read, 14, '_');
file_to_read.get(junk_sep_char);
getline(file_to_read, fitness_string_read);
chromosome_int_array.push_back(chromo_char_read);
fitness_string_array.push_back(fitness_string_read);
}
file_to_read.close();
And the file it is reading in and using looks like this:
Code:
111111111111_50
111111191111_73
222222222222_20
223222322222_83
222222222222_98
222222221122_18
222222222312_97
222222222222_307
122221222222_102
111111191111_548
I'm really grateful for any help. Cheers.