Recurns: Take Russian Equation with Russia

zhaozj2021-02-16  53

First introduce Russian hockers, the interface is as follows:

Walking method: 32 pieces of the disk open, the middle is empty; walk when walking, and the sick is eaten. Who can go into the last child's situation, that is, win.

I know Russian hocker from a friend. Al can't win, and finally I can help it on the computer. You can comfort yourself, the surrounding people don't have one to win by yourself. Not thinking, huh, huh.

It is obvious that this problem is similar to the eight queen problems, and it is more concaiscriminated with the credibility. The primary part of the solution program is the Russia () function, and next () is used as a function that looks for the next step. The solution procedure is as follows:

// Russian checkers

#include #include int CHESSBOARD [7] [7] = {- 10, -10, 1, 1, 1, -10, -10, -10, -10 ,1, 1, 1, -10, -10, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -10, -10, 1, 1, 1, -10, -10, -10, -10, 1, 1, 1, -10, -10}; // is 1 chessboard

Int Step [4] [31]; // Record each step: x y delta (x) delta (Y)

INT Delta [2]; // Temporary array record Delta (x) delta (Y) has four directions INT NEXT (INT X, INT Y); // Next

INT Russia (int X, int y, int count) // main loop

{

INT I, J;

Int results = 0;

IF (count == 31)

Return 1;

Else IF (next (x, y) == 1)

{

Step [0] = x;

Step [1] [count] = Y;

Step [2] [count] = DELTA [0];

Step [3] [count] = DELTA [1];

Chessboard [x] [y] = 0;

Chessboard [x delta [0] / 2] [Y DELTA [1] / 2] = 0;

Chessboard [x delta [0]] [Y DELTA [1]] = 1;

For (i = 0; i <7; i )

For (j = 0; j <7; j )

{

IF (Chessboard [i] [j] == 1) Result = Russia (i, j, count 1);

IF (Result> 0) Break;

}

IF (Result> 0)

{

Printf ("% d", count);

Return 1;

}

Else

{

IF ((x! = step [0] [count]) && y! = step [1] [count]) exit (1);

Chessboard [x] [y] = 1;

Chessboard [x step [2] [count] / 2] [y step [3] [count] / 2] = 1;

Chessboard [x step [2] [count]] [y step [3] [count] = 0;

Step [0] = 0;

Step [1] [count] = 0; Step [2] [count] = 0;

Step [3] [count] = 0;

Return 0;

}

}

Else

Return 0;

}

INT NEXT (INT X, INT Y) // Next {IF (((x 2) <7) && Chessboard [x 2] [Y] == 0 && Chessboard [x 1] [y] == 1) { Delta [0] = 2; Delta [1] = 0; RETURN 1;} IF ((Y-2)> 0) && chessboard [x] [Y-2] == 0 && chessboard [x] [Y-1] = = 1) {DELTA [0] = 0; Delta [1] = - 2; RETURN 1;} IF ((x-2)> 0) && chessboard [x-2] [y] == 0 && chessboard [x-1 ] [y] == 1) {DELTA [0] = - 2; Delta [1] = 0; RETURN 1;} IF ((Y 2) <7) && chessboard [x] [y 2] == 0 && chessboard [x] [y 1] == 1) {DELTA [0] = 0; Delta [1] = 2; Return 1;} return 0;}

Void main () {INT I, J;

For (j = 0; j <31; j ) for (i = 0; i <4; i ) Step [i] [j] = 0; RUSSIA (3, 5, 0); for (j = 0; J <31; J ) {for (i = 0; i <4; i ) {printf ("% D,", step [i] [j]);} printf ("/ n");}}

Need procedures and source code, you can download it online:

Http://turbulence.myshow.cn "Network Hard Drive" - ​​"/ My Works / The most difficult game in history /"

I hope to help you understand the recursive help.

转载请注明原文地址:https://www.9cbs.com/read-23166.html

New Post(0)