This commit is contained in:
Awen Lelu
2026-01-06 16:35:32 +01:00
parent 3e28ea4d9f
commit 5041f3c541
13 changed files with 110 additions and 4834 deletions

52
main.cpp Normal file
View File

@@ -0,0 +1,52 @@
#include <cstdio>
#include <cstdlib>
// sans ia et sans gluten
const int base_zombies = 3;
const int base_humans = 1000;
const float attack_chance = 0.8;
const float infection_chance =
0.5; // 50% de chance de se faire infecté si non tué par l'attaque
const float death_chance = 0.2; // 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;
} 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: %ld| zombies: %ld| humans: %ld \n", hour, zombies, humans);
for (int n = 0; n < new_zombies; n++) {
if (rand() % 100 < attack_chance) {
attack(humans, zombies, &new_humans, &new_zombies);
}
}
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;
}