11.S Corrigés des exercices
197
class Problem {
public:
int color [ MaxSize * MaxSize ];
int nbMoves;
int score;
int length Variation;
Move variation [MaxSize * MaxSize ];
void load (FILE *fp ) {
}
for (int i = O; i < MaxSize; i++)
for (int j = O; j < MaxSize; j++)
if ( fscanf (fp, "o/od",
&color [MaxSize * i + j]) == - 1 )
cerr << "Erreur.... ..,
de.... .., lecture.... ..,
des.... .., problemes"
<< endl;
score = O;
lengthVariation = O;
void buildMove (in t loc , Se en & se en , Move & move ) {
int c = col or [ loc ];
seen. set ( loc );
move. locations (0) = loc;
move. nbLocations = 1;
int stack [MaxSize * MaxSize ];
stack (0) = 1;
stack (1) = loc;
while ( stack (0) > 0) {
int 1 = stack [ stack (0)) , neigh;
stack ( 0)--;
if (1 >= MaxSize) {
neigh = 1 - MaxSize;
}
i f ( c o 1 o r [ ne i g h ] == c )
if (seen. test (neigh )) {
seen . set ( neigh );
move. add ( neigh );
stack [0]++;
stack [ stack [O]) = neigh;
}
if ( 1 < MaxSize * MaxSize - MaxSize ) {
neigh = 1 + MaxSize;
i f ( c o l o r [ n e i g h ] == c )
if (seen .test (neigh )) {
seen. set (neigh );
move. add ( neigh );
197
class Problem {
public:
int color [ MaxSize * MaxSize ];
int nbMoves;
int score;
int length Variation;
Move variation [MaxSize * MaxSize ];
void load (FILE *fp ) {
}
for (int i = O; i < MaxSize; i++)
for (int j = O; j < MaxSize; j++)
if ( fscanf (fp, "o/od",
&color [MaxSize * i + j]) == - 1 )
cerr << "Erreur.... ..,
de.... .., lecture.... ..,
des.... .., problemes"
<< endl;
score = O;
lengthVariation = O;
void buildMove (in t loc , Se en & se en , Move & move ) {
int c = col or [ loc ];
seen. set ( loc );
move. locations (0) = loc;
move. nbLocations = 1;
int stack [MaxSize * MaxSize ];
stack (0) = 1;
stack (1) = loc;
while ( stack (0) > 0) {
int 1 = stack [ stack (0)) , neigh;
stack ( 0)--;
if (1 >= MaxSize) {
neigh = 1 - MaxSize;
}
i f ( c o 1 o r [ ne i g h ] == c )
if (seen. test (neigh )) {
seen . set ( neigh );
move. add ( neigh );
stack [0]++;
stack [ stack [O]) = neigh;
}
if ( 1 < MaxSize * MaxSize - MaxSize ) {
neigh = 1 + MaxSize;
i f ( c o l o r [ n e i g h ] == c )
if (seen .test (neigh )) {
seen. set (neigh );
move. add ( neigh );
