This repository has been archived on 2022-05-02. You can view files and clone it, but cannot push or open issues or pull requests.
Ecosysteme/main.cpp

63 lines
1.5 KiB
C++

#include "univers.hpp"
void lancerSimulation(Univers ** univers, int m, int n, int nb_moutons, int nb_loups) {
*univers = new Univers(m, n);
std::vector<Animal*> animaux;
while(nb_moutons > 0) {
animaux.push_back(new Mouton());
nb_moutons--;
}
while(nb_loups > 0) {
animaux.push_back(new Loup());
nb_loups--;
}
(*univers)->ajoutAnimaux(animaux);
for(Animal *const &animal: animaux)
delete animal;
}
void arreterSimulation(Univers * univers) {
delete univers;
univers = nullptr;
}
/* m x n = taille de l'univers
* nb_moutons = nombre de moutons
* nb_loups = nombre de loups */
int main(int argc, char const *argv[]) {
if(argc > 1 && argc != 5) {
std::cerr << "Arguments non renseignés." << std::endl;
std::cout << "Usage : " << argv[0] << " m n nb_moutons nb_loups" << std::endl;
exit(1);
}
int m, n, nb_moutons, nb_loups;
if(argc == 5) { // renseigné par l'utilisateur
m = std::stoi(argv[1]);
n = std::stoi(argv[2]);
nb_moutons = std::stoi(argv[3]);
nb_loups = std::stoi(argv[4]);
} else { // valeurs par défaut
m = 5;
n = 5;
nb_moutons = 7;
nb_loups = 2;
}
Univers * univers = nullptr;
try {
lancerSimulation(&univers, m, n, nb_moutons, nb_loups);
univers->affichage();
arreterSimulation(univers);
} catch(const std::exception& e) {
std::cerr << e.what() << std::endl;
return 1;
}
return 0;
}