Robot::Robot()
fitness = 5; totalBattery = 5; int randNum; int i = 0; bool valid = true; srand(time(NULL)); //get robot's position on board and check to see if it is not starting on the wall while (valid) { position = (rand()+i++) % 196; if (position >= 0 && position <= 14) { } else if ((position % 14) == 0 || (position % 14) == 13) { } else if (position >= 183 && position <= 195) { } else { valid = false; cout << endl << "MY POSITION IS : " << position << endl << endl; } } //randomize Robot Genetics for (int j = 0; j < genes; j++) { for (int k = 0; k < chromosomes; k++) { //first 4; set N S E W(what the robot looks for in that direction) //0 = empty; 1 = battery; 2 = don't care; 3 = wall if (k < 4) { randNum = ((rand()+i++) % 4); switch(randNum) { //Empty Space case 0: DNA[j][k] = " * "; break; //Battery case 1: DNA[j][k] = " B "; break; //Don't Care case 2: DNA[j][k] = " D "; break; //Wall case 3: DNA[j][k] = " W "; break; default: cout << "YOUR CODE SCREWED UP IF YOU ARE IN HERE!! " << endl; } } //direction facing; N S E W else if (k < 5) { randNum = ((rand()+i++) % 4); switch(randNum) { case 0: DNA[j][k] = "N"; break; case 1: DNA[j][k] = "S"; break; case 2: DNA[j][k] = "E"; break; case 3: DNA[j][k] = "W"; break; default: cout << "YOUR CODE SCREWED UP IF YOU ARE IN HERE!! " << endl; break; } } //step counter in that direction else if (k < 6) { DNA[j][k] = "0"; } //Rotate Right(R); Rotate Left(L); Move in facing Direction(M); Do Nothing (X) else { randNum = ((rand()+i++) % 4); switch(randNum) { case 0: DNA[j][k] = "X"; break; case 1: DNA[j][k] = "L"; break; case 2: DNA[j][k] = "R"; break; case 3: DNA[j][k] = "M"; break; default: cout << "YOUR CODE SCREWED UP IF YOU ARE IN HERE!! " << endl; break; } } } }
}
I am trying to construct objects of a class, and I need 200 of them. I am using a vector and iterating through a while loop and each time i construct a new instance of the class, the objects come out with the exact same data. How are you supposed to properly use the randomizer function to get different data into variables while constructing objects of a class? I tried doing research, but it just got me to this point, and I'm unsure why this isn't working. Thank You in advanced.