1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
| program mastermind;
var
i, faux, bienplace, malplace, reponse1, reponse2, reponse3: integer;
{faux etant le nombre de fois que l'utilisateur se trompe}
solution, f, g, h: array[1..3] of integer;
choix: char;
begin
writeln;
writeln(' *************MASTERMIND**************');
writeln(' ** Bienvenue dans Mastermind **');
writeln(' ** pour concours infirmier **');
writeln(' ** developpe par Loupsio **');
writeln(' ** Avril 2011 **');
writeln(' *************MASTERMIND**************');
i := 1;
repeat
writeln('choisissez');
writeln('j: jouer');
writeln('r: lire les regles');
writeln('q: quitter');
readln(choix);
choix := lowercase(choix);
writeln;
writeln;
case choix of
'j':
begin
randomize;
begin
for i := 1 to 3 do
begin
solution[i] := random(5) + 1;
if solution[i] = solution[i - 1] then
solution[i] := solution[i] + 1;
if solution[i] = solution[i - 2] then
solution[i] := solution[i] + 1;
if solution[i] = solution[i - 1] then
solution[i] := solution[i] + 1;
end;
for i := 1 to 3 do
begin
f[i] := random(5) + 1;
if f[i] = f[i - 1] then
f[i] := f[i] + 1;
if f[i] = f[i - 2] then
f[i] := f[i] + 1;
if f[i] = f[i - 1] then
f[i] := f[i] + 1;
end;
for i := 1 to 3 do
begin
g[i] := random(5) + 1;
if g[i] = g[i - 1] then
g[i] := g[i] + 1;
if g[i] = g[i - 2] then
g[i] := g[i] + 1;
if g[i] = g[i - 1] then
g[i] := g[i] + 1;
end;
for i := 1 to 3 do
begin
h[i] := random(5) + 1;
if h[i] = h[i - 1] then
h[i] := h[i] + 1;
if h[i] = h[i - 2] then
h[i] := h[i] + 1;
if h[i] = h[i - 1] then
h[i] := h[i] + 1;
end;
end;
begin
bienplace := 0;
malplace := 0;
{PREMIERE LIGNE}
if solution[1] = f[1] then
bienplace := bienplace + 1;
if solution[2] = f[2] then
bienplace := bienplace + 1;
if solution[3] = f[3] then
bienplace := bienplace + 1;
writeln('les possibilites sont:');
writeln;
for i := 1 to 3 do
begin
Write(f[i]);
end;
if bienplace <> 0 then
Write(' ', bienplace, ' bien places ;');
if solution[1] = f[2] then
malplace := malplace + 1;
if solution[1] = f[3] then
malplace := malplace + 1;
if solution[2] = f[1] then
malplace := malplace + 1;
if solution[2] = f[3] then
malplace := malplace + 1;
if solution[3] = f[1] then
malplace := malplace + 1;
if solution[3] = f[2] then
malplace := malplace + 1;
if malplace <> 0 then
writeln(' ', malplace, ' mal places')
else
writeln;
{DEUXIEME LIGNE}
bienplace := 0;
malplace := 0;
if solution[1] = g[1] then
bienplace := bienplace + 1;
if solution[2] = g[2] then
bienplace := bienplace + 1;
if solution[3] = g[3] then
bienplace := bienplace + 1;
for i := 1 to 3 do
begin
Write(g[i]);
end;
if bienplace <> 0 then
Write(' ', bienplace, ' bien places ;');
if solution[1] = g[2] then
malplace := malplace + 1;
if solution[1] = g[3] then
malplace := malplace + 1;
if solution[2] = g[1] then
malplace := malplace + 1;
if solution[2] = g[3] then
malplace := malplace + 1;
if solution[3] = g[1] then
malplace := malplace + 1;
if solution[3] = g[2] then
malplace := malplace + 1;
if malplace <> 0 then
writeln(' ', malplace, ' mal places')
else
writeln;
{TROSIEME LIGNE}
bienplace := 0;
malplace := 0;
if solution[1] = h[1] then
bienplace := bienplace + 1;
if solution[2] = h[2] then
bienplace := bienplace + 1;
if solution[3] = h[3] then
bienplace := bienplace + 1;
i := 1;
for i := 1 to 3 do
begin
Write(h[i]);
end;
if bienplace <> 0 then
Write(' ', bienplace, ' bien places ;');
if solution[1] = h[2] then
malplace := malplace + 1;
if solution[1] = h[3] then
malplace := malplace + 1;
if solution[2] = h[1] then
malplace := malplace + 1;
if solution[2] = h[3] then
malplace := malplace + 1;
if solution[3] = h[1] then
malplace := malplace + 1;
if solution[3] = h[2] then
malplace := malplace + 1;
if malplace <> 0 then
writeln(' ', malplace, ' mal places')
else
writeln;
end;
faux := 0;
writeln('entre ta solution (chaques chiffres separes par des espaces)');
repeat
if faux <= 2 then {2 autorise 3 erreur avant don de solution}
begin
readln(reponse1, reponse2, reponse3);
if (reponse1 = solution[1]) and (reponse2 = solution[2]) and
(reponse3 = solution[3]) then
begin
writeln('CORRECT');
writeln;
writeln;
end
else
begin
writeln('FAUX');
faux := faux + 1;
end;
end
else
begin
faux := 5; {5 est impossible donc c est qu il a rate son dernier coup et affiche la reponse}
reponse1 := solution[1];
reponse2 := solution[2];
reponse3 := solution[3];
end;
until (reponse1 = solution[1]) and (reponse2 = solution[2]) and (reponse3 = solution[3]);
if faux = 5 then
writeln('la solution est: ', solution[1], solution[2], solution[3]);
writeln;
writeln;
end;
'r':
begin
writeln('************************************************************');
writeln('************************************************************');
writeln('**', '**': 58);
writeln('** pour jouer tu dois trouver les 3 chiffre de la reponse **');
writeln('** les indices en bout de lignes t indiquent si ces **');
writeln('** chiffres sont presents dans la reponse **');
writeln('** EXEMPLE **');
writeln('** 342 2 mal places 1 bien place **');
writeln('** signifie que le 2 le 3 et le 4 sont presents **');
writeln('** mais que un seul est a la bonne place **');
writeln('** aides toi des trois lignes pour trouver la solution **');
writeln('** BONNE CHANCE **');
writeln('**', '**': 58);
writeln('************************************************************');
writeln('************************************************************');
end;
'q':
writeln
else
writeln('tu dois choisir entre j,r et q, tu as appuye sur ', choix);
end;
until choix = 'q';
end. |
Partager