cpp
This commit is contained in:
52
main.cpp
Normal file
52
main.cpp
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user