52 lines
1.2 KiB
C++
52 lines
1.2 KiB
C++
#include <cstdio>
|
|
#include <cstdlib>
|
|
|
|
// sans ia et sans gluten
|
|
|
|
const int base_zombies = 3;
|
|
const int base_humans = 10000;
|
|
|
|
const int attack_chance = 80;
|
|
const int infection_chance =
|
|
50; // 50% de chance de se faire infecté si non tué par l'attaque
|
|
const int death_chance = 20; // 20% de chance de mourir de l'attaque
|
|
|
|
void attack(int humans, int zombies, int *new_humans, int *new_zombies) {
|
|
if (rand() % 100 < death_chance) {
|
|
*new_humans = humans - 1;
|
|
*new_zombies = zombies;
|
|
} else if (rand() % 100 < infection_chance) {
|
|
*new_humans = humans - 1;
|
|
*new_zombies = zombies + 1;
|
|
} else {
|
|
*new_humans = humans;
|
|
*new_zombies = zombies;
|
|
}
|
|
}
|
|
|
|
void loop(int hour, int humans, int zombies) {
|
|
|
|
int new_humans;
|
|
int new_zombies;
|
|
|
|
std:printf("hour: %d| zombies: %d| humans: %d \n", hour, zombies, humans);
|
|
|
|
for (int n = 0; n < new_zombies; n++) {
|
|
if (rand() % 100 < attack_chance) {
|
|
attack(humans, zombies, &new_humans, &new_zombies);
|
|
}
|
|
}
|
|
|
|
if (new_humans <= 0 || new_zombies <= 0) {
|
|
std::printf("finito pipo");
|
|
} else {
|
|
loop(hour+1, new_humans, new_zombies);
|
|
}
|
|
}
|
|
|
|
int main() {
|
|
loop(0, base_humans, base_zombies);
|
|
|
|
return 0;
|
|
}
|