8
Fonctions d'évaluation
1.6.2 Joueur parfait pour Nim
#include
using namespa ce s td ;
int tas [4] = {7 , 5, 3, 1 } ;
int mai n () {
int t, nombre;
while ( tr ue) {
cout << tas [O] << ".... ., " << tas [1] << " .... .. " <<
tas [2] << ".... ., " << tas [3] << endl;
if (tas [O] + tas [1] + tas [2] + tas [3] == 0) {
cout << "J' ai._.gag ne._.!" << endl;
}
break ;
}
do {
cout << "Don nez .... .. le._.tas .... .. ( entre._.0._.et._. 3):._.";
ci n >> t;
cout << "Don nez .... .. le._. nombre._.: .... .. ";
ci n >> nombre;
} wh ile (( t < 0) Il (t > 3)
Il
(tas [t]
}
tas [t] -= nombre;
cout << tas [O] << " .... .. "
tas [2] << " .... .. "
for ( int i = O; i < 4;
for ( i n t j = 1 ; j <=
tas [ i] -= j ;
}
if (( tas [O]
A
tas
t = i ;
nombre = j;
}
tas [ i] += j ;
<< tas [ 1 ] <<
<< tas [3] <<
i ++)
tas [ i ] ; j ++)
[ 1 ]
A
tas [2]
cout << "Je._.pre nd._." << nombre <<
"._. dans._.l e._.tas._." << t << endl;
tas [ t] -= nombre;
return 0;
Il
Il
<<
endl;
{
A
tas [ 3]) -- 0) {
Fonctions d'évaluation
1.6.2 Joueur parfait pour Nim
#include
using namespa ce s td ;
int tas [4] = {7 , 5, 3, 1 } ;
int mai n () {
int t, nombre;
while ( tr ue) {
cout << tas [O] << ".... ., " << tas [1] << " .... .. " <<
tas [2] << ".... ., " << tas [3] << endl;
if (tas [O] + tas [1] + tas [2] + tas [3] == 0) {
cout << "J' ai._.gag ne._.!" << endl;
}
break ;
}
do {
cout << "Don nez .... .. le._.tas .... .. ( entre._.0._.et._. 3):._.";
ci n >> t;
cout << "Don nez .... .. le._. nombre._.: .... .. ";
ci n >> nombre;
} wh ile (( t < 0) Il (t > 3)
Il
(tas [t]
tas [t] -= nombre;
cout << tas [O] << " .... .. "
tas [2] << " .... .. "
for ( int i = O; i < 4;
for ( i n t j = 1 ; j <=
tas [ i] -= j ;
}
if (( tas [O]
A
tas
t = i ;
nombre = j;
}
tas [ i] += j ;
<< tas [ 1 ] <<
<< tas [3] <<
i ++)
tas [ i ] ; j ++)
[ 1 ]
A
tas [2]
cout << "Je._.pre nd._." << nombre <<
"._. dans._.l e._.tas._." << t << endl;
tas [ t] -= nombre;
return 0;
Il
Il
<<
endl;
{
A
tas [ 3]) -- 0) {
