TP8: Robot
This commit is contained in:
BIN
TP8/ROBOT/Côté_Robot_24.pdf
Normal file
BIN
TP8/ROBOT/Côté_Robot_24.pdf
Normal file
Binary file not shown.
31
TP8/ROBOT/ROBOT.sln
Normal file
31
TP8/ROBOT/ROBOT.sln
Normal file
@@ -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
|
||||
139
TP8/ROBOT/ROBOT.vcxproj
Normal file
139
TP8/ROBOT/ROBOT.vcxproj
Normal file
@@ -0,0 +1,139 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Text Include="Robot1.txt" />
|
||||
<Text Include="Robot2.txt" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>17.0</VCProjectVersion>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<ProjectGuid>{d8576f8d-202e-43d4-b649-16f43537fec7}</ProjectGuid>
|
||||
<RootNamespace>ROBOT</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
30
TP8/ROBOT/ROBOT.vcxproj.filters
Normal file
30
TP8/ROBOT/ROBOT.vcxproj.filters
Normal file
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Fichiers sources">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Fichiers d%27en-tête">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Fichiers de ressources">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Text Include="Robot1.txt">
|
||||
<Filter>Fichiers de ressources</Filter>
|
||||
</Text>
|
||||
<Text Include="Robot2.txt">
|
||||
<Filter>Fichiers de ressources</Filter>
|
||||
</Text>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp">
|
||||
<Filter>Fichiers sources</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
4
TP8/ROBOT/ROBOT.vcxproj.user
Normal file
4
TP8/ROBOT/ROBOT.vcxproj.user
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup />
|
||||
</Project>
|
||||
7
TP8/ROBOT/Robot1.txt
Normal file
7
TP8/ROBOT/Robot1.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
6
|
||||
R;7;
|
||||
R;3;
|
||||
N;8;
|
||||
B;1;
|
||||
N;8;
|
||||
R;9;
|
||||
6
TP8/ROBOT/Robot2.txt
Normal file
6
TP8/ROBOT/Robot2.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
5
|
||||
B;3;
|
||||
B;4;
|
||||
N;8;
|
||||
R;4;
|
||||
B;2;
|
||||
264
TP8/ROBOT/main.cpp
Normal file
264
TP8/ROBOT/main.cpp
Normal file
@@ -0,0 +1,264 @@
|
||||
#include <iostream>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
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 <class C>
|
||||
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 <class C>
|
||||
void affichage(C cont) {
|
||||
for (auto a : cont) {
|
||||
a.affichage(); cout << endl;
|
||||
}
|
||||
}
|
||||
|
||||
template <class C>
|
||||
void affichage(multimap<string, C> cont) {
|
||||
|
||||
for (auto a : cont) {
|
||||
a.second.affichage(); cout << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <class C>
|
||||
int penalite(C cont, char c) {
|
||||
int i = 0;
|
||||
for (auto a : cont) {
|
||||
if (a.getCouleur() != c) {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
template <class C>
|
||||
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 <class A, class B>
|
||||
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 <class C>
|
||||
void fill(multiset<Boule> &set, C c) {
|
||||
for (Boule b : c) {
|
||||
set.insert(b);
|
||||
}
|
||||
}
|
||||
|
||||
template <class C>
|
||||
void fill(multimap<string,Boule> &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 <class C>
|
||||
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<Boule> L1;
|
||||
vector<Boule> 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<string, Boule> MMap;
|
||||
multiset<Boule> 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"<<winner << endl;
|
||||
break;
|
||||
default:
|
||||
cout << "Pas de gagnant!" << endl;
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 5:
|
||||
winner = getWinner(L1, 'R', V1, 'B');
|
||||
switch (winner) {
|
||||
case 1:
|
||||
fill(MSet, V1);
|
||||
fill(MMap, V1);
|
||||
break;
|
||||
case 2:
|
||||
fill(MSet, L1);
|
||||
fill(MMap, V1);
|
||||
break;
|
||||
default:
|
||||
cout << "Pas de gagnant!" << endl;
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
case 6:
|
||||
cout << "L1 : " << endl;
|
||||
affichage(L1);
|
||||
cout << "V1 : " << endl;
|
||||
affichage(V1);
|
||||
cout << "MMap : " << endl;
|
||||
affichage(MMap);
|
||||
|
||||
break;
|
||||
case 7:
|
||||
del_half(L1);
|
||||
del_half(V1);
|
||||
del_half(MMap);
|
||||
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user