diff --git a/TP8/ROBOT/Côté_Robot_24.pdf b/TP8/ROBOT/Côté_Robot_24.pdf new file mode 100644 index 0000000..8bc6640 Binary files /dev/null and b/TP8/ROBOT/Côté_Robot_24.pdf differ diff --git a/TP8/ROBOT/ROBOT.sln b/TP8/ROBOT/ROBOT.sln new file mode 100644 index 0000000..756a5b1 --- /dev/null +++ b/TP8/ROBOT/ROBOT.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.7.34221.43 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ROBOT", "ROBOT.vcxproj", "{D8576F8D-202E-43D4-B649-16F43537FEC7}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D8576F8D-202E-43D4-B649-16F43537FEC7}.Debug|x64.ActiveCfg = Debug|x64 + {D8576F8D-202E-43D4-B649-16F43537FEC7}.Debug|x64.Build.0 = Debug|x64 + {D8576F8D-202E-43D4-B649-16F43537FEC7}.Debug|x86.ActiveCfg = Debug|Win32 + {D8576F8D-202E-43D4-B649-16F43537FEC7}.Debug|x86.Build.0 = Debug|Win32 + {D8576F8D-202E-43D4-B649-16F43537FEC7}.Release|x64.ActiveCfg = Release|x64 + {D8576F8D-202E-43D4-B649-16F43537FEC7}.Release|x64.Build.0 = Release|x64 + {D8576F8D-202E-43D4-B649-16F43537FEC7}.Release|x86.ActiveCfg = Release|Win32 + {D8576F8D-202E-43D4-B649-16F43537FEC7}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {5AFDF616-7FA6-4C58-98EB-A32F1A90369E} + EndGlobalSection +EndGlobal diff --git a/TP8/ROBOT/ROBOT.vcxproj b/TP8/ROBOT/ROBOT.vcxproj new file mode 100644 index 0000000..95f332e --- /dev/null +++ b/TP8/ROBOT/ROBOT.vcxproj @@ -0,0 +1,139 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + + + + + + + + 17.0 + Win32Proj + {d8576f8d-202e-43d4-b649-16f43537fec7} + ROBOT + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + \ No newline at end of file diff --git a/TP8/ROBOT/ROBOT.vcxproj.filters b/TP8/ROBOT/ROBOT.vcxproj.filters new file mode 100644 index 0000000..c913357 --- /dev/null +++ b/TP8/ROBOT/ROBOT.vcxproj.filters @@ -0,0 +1,30 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Fichiers de ressources + + + Fichiers de ressources + + + + + Fichiers sources + + + \ No newline at end of file diff --git a/TP8/ROBOT/ROBOT.vcxproj.user b/TP8/ROBOT/ROBOT.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/TP8/ROBOT/ROBOT.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/TP8/ROBOT/Robot1.txt b/TP8/ROBOT/Robot1.txt new file mode 100644 index 0000000..69c314b --- /dev/null +++ b/TP8/ROBOT/Robot1.txt @@ -0,0 +1,7 @@ +6 +R;7; +R;3; +N;8; +B;1; +N;8; +R;9; \ No newline at end of file diff --git a/TP8/ROBOT/Robot2.txt b/TP8/ROBOT/Robot2.txt new file mode 100644 index 0000000..f5573a4 --- /dev/null +++ b/TP8/ROBOT/Robot2.txt @@ -0,0 +1,6 @@ +5 +B;3; +B;4; +N;8; +R;4; +B;2; \ No newline at end of file diff --git a/TP8/ROBOT/main.cpp b/TP8/ROBOT/main.cpp new file mode 100644 index 0000000..0926a11 --- /dev/null +++ b/TP8/ROBOT/main.cpp @@ -0,0 +1,264 @@ +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +class Boule { + char couleur; + int points; +public: + + void saisie(ifstream& f); + void affichage(); + + char getCouleur(); + int getPoints(); + + bool operator==(Boule b); + bool operator<(Boule b) const; +}; + +char Boule::getCouleur() { return couleur; } +int Boule::getPoints() { return points; } + +void Boule::saisie(ifstream& f) { + f >> couleur; f.ignore(); + f >> points; f.ignore(); +} + +void Boule::affichage() { + cout << couleur << " : " << points; +} + +bool Boule::operator==(Boule b) { + return couleur == b.couleur && points == b.points; +} + +bool Boule::operator<(Boule b) const { + return (couleur == b.couleur) ? points < b.points : couleur < b.couleur; +} + +template +void lec_boules(C& cont, const string fname) { + ifstream f(fname); + + if (!f.is_open()) { + cout << "Erreur lors de la lecture du fichier" << endl; + exit(1); + } + + cout << "Lecture du fichier " << fname << endl; + + int N; + + f >> N; f.ignore(); + + while ((N--) > 0) { + Boule b; + + b.saisie(f); f.ignore(); + cont.push_back(b); + } +} + +template +void affichage(C cont) { + for (auto a : cont) { + a.affichage(); cout << endl; + } +} + +template +void affichage(multimap cont) { + + for (auto a : cont) { + a.second.affichage(); cout << endl; + } +} + + +template +int penalite(C cont, char c) { + int i = 0; + for (auto a : cont) { + if (a.getCouleur() != c) { + i++; + } + } + return i; +} + +template +int Som(C cont, char c) { + int score = 0; + + for (auto a : cont) { + if (a.getCouleur() == c) { + score += a.getPoints(); + } + else { + score -= a.getPoints(); + } + } + + return score; +} + +// Robot1 = 1, Robot2 = 2, égalité = 0 +template +int getWinner(A a, char ac, B b, char bc) { + int SL = Som(a, ac); + int SV = Som(b, bc); + + /*cout << "Score Robot1 : " << SL << endl; + cout << "Score Robot2 : " << SV << endl; + cout << endl;*/ + + if (SL > SV) { + return 1; + } + else if (SL < SV) { + return 2; + } + else { + return 0; + } +} + +template +void fill(multiset &set, C c) { + for (Boule b : c) { + set.insert(b); + } +} + +template +void fill(multimap &m, C& c) { + affichage(m); + for (auto it = c.begin(); it != c.end(); ) { + cout << endl; + string k = it->getCouleur() + to_string(it->getPoints()); + cout << "MMap : " << endl; + m.insert(make_pair(k, *it)); + it = c.erase(it); + affichage(m); + cout << "Boules perdant : " << endl; + affichage(c); + } +} + +template +void del_half(C& c) { + for (auto it = c.begin(); it != c.end();) { + if (it != c.end()) it++; + else break; + + if (it != c.end()) + it = c.erase(it); + } +} + + +int menu() { + int c; + + cout << "1- LectureSaisieL et Affichage " << endl + << "2- LectureSaisieV et Affichage" << endl + << "3- Compter le nombre de boules pénalisantes dans L et V" << endl + << "4- Qui est le gagnant? " << endl + << "5- Déposer les boules du Robot perdant dans une MMap" << endl + << "6- Afficher L, V et MMap " << endl + << "7- Supprimer un élément sur deux de L, V et MMap" << endl; + cout << "Choix : "; + cin >> c; cin.ignore(); + return c; +} + +int main() { + setlocale(LC_ALL, ""); + + list L1; + vector V1; + + int winner; + + // Je ne comprend absolument pas pourquoi il faut utiliser une multimap + // Au lieu d'un multiset + // Ils veulent que la clé soit couleur + score concat??! + // C'est plus malin avec juste un set un opérateur de tri bien choisis (voir Boule::operator< ) + // Dcp je vais faire en version set et version multimap + multimap MMap; + multiset MSet; + + while (true) { + switch (menu()) { + case 1: + lec_boules(L1, "Robot1.txt"); + affichage(L1); + break; + case 2: + lec_boules(V1, "Robot2.txt"); + affichage(V1); + break; + case 3: + cout << "L : nombre de boules pénalisantes = " << penalite(L1, 'R') << endl; + cout << "V : nombre de boules pénalisantes = " << penalite(V1, 'B') << endl; + + break; + case 4: + winner = getWinner(L1, 'R', V1, 'B'); + + switch (winner) { + case 1: + case 2: + cout << "Le gagnant est : Robot"<