F
Furtano
Gast
Hallo,
ich schreibe eine Ameisensimulation. Dabei möchte ich die verschiedenen Entwicklungsstadien der Ameise simulieren.
Egg -> Grub -> Puppet -> Imago
Ich generiere alle 3 Tage neue Eier, die dann altern.
Wenn ein Ei alt genug ist, soll es zur Grub (Larve) werden.
Leider funktioniert mein Code so nicht, er generiert zwar alle 3 Tage Eier, aber wenn es soweit ist dass Larven erzeugt werden sollen werden keine angezeigt.
Hängt das mit der Zeile 49 (zweiter Code) zusammen?
Danke !
ich schreibe eine Ameisensimulation. Dabei möchte ich die verschiedenen Entwicklungsstadien der Ameise simulieren.
Egg -> Grub -> Puppet -> Imago
Ich generiere alle 3 Tage neue Eier, die dann altern.
Wenn ein Ei alt genug ist, soll es zur Grub (Larve) werden.
Leider funktioniert mein Code so nicht, er generiert zwar alle 3 Tage Eier, aber wenn es soweit ist dass Larven erzeugt werden sollen werden keine angezeigt.
Hängt das mit der Zeile 49 (zweiter Code) zusammen?
Danke !
PHP:
std::vector <Breed*> breed;
std::vector <Breed*> tempBreed;
void antQueen(){
do {
tempdays = timeSimulationRuned.getElapsedTime().asSeconds();
tempdays = (float)((int)(tempdays*100))/100;
// 1 new day:
if (fmod(tempdays, 1) == 0 ){
// !first round
if (oldTempDays != tempdays){
std::cout << "\n\n\n\n\n MODODODO" << breed.size() << "\n\n\n";
// A new Ant Spawns in The Game ;)
init.lifeStadium[livingAnts] = 1;
livingAnts++;
// Queen spawns an Egg
if (days % 3 == 0 && days != 0){
std::cout << "\n 1EGGGGGGGGGGGGGGGGGGGG";
Egg egg;
egg.days = 0;
egg.lifeStatus = true;
breed.push_back(&egg);
std::cout << "EGGTIME\n";
}
// For Stats
checkBreed();
// 1 Day is Over
days++;
for (Breed * ant : breed){
ant->days++;
}
}
// For Twice-Failure Checking
oldTempDays = tempdays;
}
}
while (true);
}
PHP:
void checkBreed(){
eggs = 0;
grubs = 0;
puppets = 0;
for (Breed* ant : breed){
if(ant->status == status_EGG){
// Egg is developed ready
// endDate == 14
if (ant->days == ant->endDate){
eggs--;
Grub grub;
grub.days = 15;
grub.lifeStatus = true;
grub.status = status_GRUB;
tempBreed.push_back(&grub);
}
else {
eggs++;
}
}
else if (ant->status == status_GRUB){
std::cout << "\n\nGRUBBB";
grubs++;
}
else if (ant->status == status_PUPPET){
puppets++;
}
// Is an Ant !!!
else {
}
}
for (Breed * tempAnt : tempBreed){
std::cout << "\n\nHAHAHHA GRUBBBBY";
breed.push_back(tempAnt);
grubs++;
}
if (days % 30 == 0 && days != 0){
days = 0;
months++;
}
if (months % 12 == 0 && months != 0){
months = 0;
years++;
}
}
PHP:
class Breed {
public:
Breed();
statusOfAnt status;
int days;
int endDate;
int food;
// 0 == Dead, 1 == Alive
bool lifeStatus;
int aviableFood;
void feed(int food);
void dayIsOver();
};
class Egg : public Breed {
public:
Egg (){
status = status_EGG;
days = 0;
endDate = 5;
food = 10;
lifeStatus = 0;
}
//this.status = status_PUPPET;
void Egg::dayIsOver(){
// Egg doesnt need food
this->food -= 0;
}
};
class Grub : public Breed {
public:
Grub (){
status = status_GRUB;
days = 0;
endDate = 24;
food = 2;
lifeStatus = 0;
}
void Grub::dayIsOver(){
this->food -= 3;
}
//this.status = status_PUPPET;
};
Zuletzt bearbeitet von einem Moderator: