DEV/DEV1.1/TD/TD10.c

98 lines
1.6 KiB
C
Raw Normal View History

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
struct blob{
char faction;
int taille;
};
typedef struct blob blob;
struct arene{
blob combattant[50];
};
typedef struct arene arene;
void printBlob(blob b) {
printf("Faction : %c\nTaille : %d\n",b.faction, b.taille);
}
blob rencontre(blob blob1,blob blob2) {
int tailleOut;
char factionOut;
if (blob1.faction==blob2.faction)
{
tailleOut = blob1.taille + blob2.taille;
factionOut = blob1.faction;
}
if (blob1.faction!=blob2.faction)
{
if (blob1.taille>blob2.taille)
{
tailleOut = blob1.taille-blob2.taille;
factionOut = blob1.faction;
}
if (blob1.taille<blob2.taille)
{
tailleOut = blob2.taille-blob1.taille;
factionOut = blob2.faction;
}
if (blob1.taille==blob2.taille)
{
tailleOut = 1;
factionOut = blob1.faction;
}
}
blob b={factionOut,tailleOut};
return b;
}
void remplirArene(arene* a) {
srand(time(0));
int taille;
char faction;
for (int i = 0; i < 50; ++i)
{
taille = (rand() % 40)+1;
faction = ((rand() % 5)+'a');
blob b={faction, taille};
((*a).combattant[i])=b;
}
}
void afficherArene(arene a) {
for (int i = 0; i < 50; ++i)
{
printf("Participant n°%d \n",i+1);
printBlob(a.combattant[i]);
}
}
int main(int argc, char const *argv[])
{
/*
blob a={'a',5};
blob b={'a',10};
blob c=rencontre(a,b);
printBlob(a);
printBlob(b);
printBlob(c);
*/
arene liguePkmn;
remplirArene(&liguePkmn);
afficherArene(liguePkmn);
blob res=liguePkmn.combattant[0];
int i;
for (int i = 1; i < 50; ++i)
{
res=rencontre(res,liguePkmn.combattant[i]);
printBlob(res);
}
printBlob(res);
return 0;
}