I finally fixed this a couple of days ago.
I gave up on storing the information in a text file and used some vectors instead. Then I made a function which copies the vectors to an (otherwise...
Type: Posts; User: Onions
I finally fixed this a couple of days ago.
I gave up on storing the information in a text file and used some vectors instead. Then I made a function which copies the vectors to an (otherwise...
I've changed it to this:
while (file_to_read) {
file_to_read >> chromosome_int_read;
file_to_read >> fitness_string_read;
...
So, if I then opened the DEAD file to look at what had happened would it look like
111111111111 223 222222222222 342 111111111111 112
Or would it still be
Well, it compiles and runs, yes. But after it has made a few enemies the game crashes for random reasons again.
I've tried your loop, Bench. It still crashes, unfortunately.
Crashed. Even if it tries to read just one chromosome and fitness from that DEAD file it crashes.
(Sigh)
I commented out the loop which reads in the chromosomes and fitness integers, and just shoved this there:
string chromosome = "222222222222";
for (int i = 0; i < 215; i++) {...
Yeah, I can do it in a new program. With a vector too.
[I'm talking about what 7stud described]
I just don't get this at all.
When an enemy is destroyed, it's chromosome and fitness is...
Hmm...it crashes the moment it tries to use that loop.
Why exactly is it a problem if you use getline() twice?
Well, the code now looks like this...
ifstream file_to_read("DEAD.txt");
string chromosome_string_read;
chromosome_string_read = "";
string fitness_string_read;
They are both strings.
I have tried reading in a different file using the same sort of method, and that crashes the game as well. I can't seem to read in anything from a text file without it...
I've changed it to this, and it STILL crashes.
while (getline(file_to_read, chromosome_int_read, '_') && getline(file_to_read, fitness_string_read)) {
God, this is annoying. If I remove...
Ah, OK.
Mate, sorry I'm being such a dumbass here...but I don't understand what you mean by that.
Can you explain what you mean exactly?
So, how do I stop it from reading in a blank chromosome and a blank fitness? It can't be good having them in the string vectors.
Right, OK...I've switched it to strings. And it still crashes after a short while.
Looking at what happens, it seems it is reading in a blank line from the text file.
If there are 6 lines of...
If I change it to...
file_to_read.get(chromo_char_read, 13, '_');
The game freezes when it tries to create a new enemy.
Yes, I wanted to treat it as a string...so get() is the correct function to use, eh?
Oh, OK...sorry, just read your other bit.
"chromosome_int_array" is a vector of strings. I've been meaning to change the name, it's confusing and stupid.
I'll just add that 2nd parameter of...
OK. So, I changed it to...
file_to_read.get(chromo_char_read, 13, '_');
But it still crashes. Am I being really stupid here?
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...
class EnemySprite : public Sprite
{
protected:
int m_iChromosome;
int m_iFitness;
...
Hi,
I have an EnemySprite object that has an int member variable called Chromosome. The value of it is "1".
I'm trying to write that value to a text file, but instead of getting "1" I am...
Ohhh, I see. I had no idea you could do that with strings.
You'll have to forgive me - I'm in England, and it's been a long day.
But if the string is "1123211132", how do I actually access the characters within?
In Java, I'd just do stringName.getChar(index)...is there a C++ way of doing that?