Improve version of Wuzi chess

xiaoxiao2021-03-05  24

#include "stdafx.h"

// definition point struct point {INT X; int y;};

/ / Define the chess pieces nodes, used to registrate chess struct; // chess pieces of chessboard position int status; // 下子 0 is computer, 1 is chess, 2 is blank int WIN [2] [252]; / / Used to store the number of victory combinations of current nodes};

#define Whitechess 0 // White Chess #define Blackchess 1 // Black #define Blank 2 // White Class Chess {Private:

/ / Define chess and computer's chessboard to store Bool Blackchessboard [11] [11] [252]; BOOL Whitechessboard [11] [11] [252];

// The score of the computer and players in each point is Int Whitechessgrade [11] [11], Blackchessgrade [11] [11];

// Calculate the computer or player in each combination occupies a few pieces // 0 represent black chess, 1 represents white chess Int Win [2] [252];

/ / Define whether it is the first Chess Bool Start;

// Record the number of chess steps of the computer and chess hand int whitechesscount; int blackchescount;

// Used to carry out the current player's conversion (Black "<-> White Chess) BOOL White, Black;

// Used to store the status, position and princes of all chess pieces, used for regrets only use chessnode allchess [122];

// Whether the game ends BOOL GAMEOVER;

// Winner 0 for Bai Chess 1 for Black 2 for the game, not ending - 1 is a flat int winner; / ************ Function *********** **************** /

// Put the chessboard to blank int initboard (); // initialize the score void initialmark (); // Initialmark (); // Record the status of the next chess pieces Void RecordChesstatus (int horizontal, int value, INT Player); // Calculates a number of chess pieces that have been occupied by some victory in the number of win [2] [252], the parameters are horizontal, vertical position, and finally record the falling lace is computer. Or player int compute (int.com); public: // Defines the chessboard int board [11] [11]; // Constructor CHESS (); // Computer By calculating the chess position int WhiteplayChess (int horizontal, int vertical); // players in the chessboard in the chessboard, Int BlackPlayChess (int horizontal, int vertical); // Remotess, can only make a regressment invocirches (int player); // Decision The game ends BOOL GAMEOVER (); // Take the winner 0 for the computer 1 for the player 2 for the chess bureau - 1 is the order Int getwinner ();

/ / Determine the computer's chess position to return the coordinate Point DecidePosition (void); / / The play chess converts Bool Roleswitch (Void);

/ / Get the number of players in the game int getBLACKCHESSCOUNT () {Return Blackchescount;}

// Get the number of steps of the computer falling int GETWHITECHESSCOUNT ()}};

/ ************************************************** **** Function function ************************************************************************************************************ *********** Initialization function *********************** / / initialize the chessboard to blank int CHESS :: Init City () {INT i = 0; // initialize the chessboard to space for FOR (i = 0; i <11; i ) {for (int J = 0; j <11; j ) Board [i] [j] = 2 } // Initialized chess game for (i = 0; i <122; i ) {allchess [i] .point.x = -1; allchess [i] .point.y = -1; allchess [i] .status = Blank;} for (i = 0; i <2; i ) for (int J = 0; J <252; J ) WIN [i] [j] = 0;

For (i = 0; i <11; i ) for (int J = 0; j <11; j ) for (int K = 0; k <252; k ) {blackchessboard [i] [j] [k] = False; Whitechessboard [i] [j] [k] = false;} whitechescount = blackchescount = 0; GameOver = false;

Winner = blank; Return 0;} // Initialmark () {for (int i = 0; i <11; i ) for (int J = 0; j <11; j ) {WhiteChessGrade [i] [j] = 0; BlackCheSSGRADE [i] [j] = 0;}} // Initialized winning combination INT chess :: initwincompages () {INT i = 0, J = 0, K = 0, Num = 0; // Initialization level direction of winning combination portions for (i = 0; i <11; i ) {for (int J = 0; j <7; j ) {for (k = 0; k <5; k ) {BlackchessBoard [i] [j k] [num] = true; Whitechessboard [i] [j k] [Num] = true;} Num ;}}

// Initialize the winning combination of the vertical direction for (j = 0; j <11; j ) {for (int i = 0; i <7; i ) {for (k = 0; k <5; k ) {BlackChessBoard [i k] [j] [num] = true; Whitechessboard [i k] [j] [num] = true;} Num ;}} // Initialization Positive diagonal direction Winning combination FOR (i = 0; I <7; i ) {for (j = 0; j <7; j ) {for (k = 0; k <5; k ) {blackchesboard [i k] [j k] [Num] = true; WhitechessBoard [i k] [j k] [Num] = true;} Num ;}} // Initializing the opposition direction Winning combination FOR (i = 0; i <7; i ) for (j = 10; J > = 4; j -) {for (k = 0; k <5; k ) {blackchessboard [i k] [j k] [Num] = true; Whitechessboard [i k] [J K] [Num] = true;} Num ;} NUM = 0; Return 0;}

// Constructor CHESS :: CHESS () {INITBOARD (); INITWINCompages (); initialmark (); start = true; // black chess White = false; black = true;}

/ ************ Function function *********************************************** Status Void Chess :: RecordchesStatus (int horizontal, int value) {// The storage location is the same as the number of steps of the play, that is, from 1 to 121, Allchess [(Blackchesscount WhitechesScount)]. Point.x = Horizontal; Allchesschers [(Blackchescount Whitechescount)]. Point.y = vertical; Allchess [(BlackchessCount Whitechescount)]. status = player; // Record the winning group of the current node for (int i = 0; i <2 ; i ) for (int J = 0; J <252; J ) Allchess [(BlackchescountCount Whitechescount)]. Win [i] [j] = win [i] [j]; return;} // calculate a victory The number of chess pieces already occupied by some square is placed in the array of WIN [2] [252], the parameters are horizontal, vertical position, and finally record the drum is the computer or chess hand int CHESS :: Compute (int Horizontal, int vertical, int player {// If the position of the board is not in the 11 * 11 range, returns an error if ((horizontal> = 11) || (vertical> = 11) || (Horizontal <0) || Vertical <0)) RETURN-1; for (int i = 0; i <252; i ) {// If the fallman is black if (Player == Blackchess) {if (Blackchessboard [horizontal] [Vertical] [i ] && (Win [1] [i]! = -1)) {// Statistics This combination has taken a few children, if it is -1 indicates that there is a combination that has been occupied by the opponent, it is impossible to win. WIN [Blackchess] [i] ;} if (Whitechessboard [horizontal] [vertical] [i]) {// Because the player has dropped next to this combination, the computer is not possible to pass this combination of WHITECHESSBOARD [Horizontal] [Vertical] [I] = false; win [whitechess] [i] = -1;}} // If the fallman is the white flag Else if (Player == Whitechess) {if (Whitechessboard [horizontal] [vertical] [i] && (WIN [0]! = -1)) {// Statistics This combination has taken a few children. If it is -1 indicates that there is a combination that has been occupied by an opponent, it is impossible to win Win [Whitechess ] [i] ;} if (Blackchessboard [horizontal] [vertical] [I]) {// Because the player has dropped next to this combination, the computer is impossible to pass this combination shin Blackchessboard [horizontal] [vertical] [i] =

False; win [blackchess] [i] = -1;}}} Return 1;} // Decide the computer's chess position Return the coordinate of the dropper Point Chess :: DecidePosition (void) {INT i = 0, J = 0, K = 0; // Used to store the highest score of computer and chess hands in the chessboard int whitemax = 0; int Selfx = -1, Selfy = -1, OtherX = -1, Othem = -1; // Used to temporarily store the last determined chess position Point Point; // If the first step for the computer, it is preferentially placed in the central position IF (start) of the chessboard {if (Board [5] [5] == 2) {POINT.X = 5; Point.y = 5;} else {Point.x = 5; point.y = 4;} IF ((BlackChessCount Whitechescount> = 1) start = false; returnire If it is a white flag, first calculate the score of black chess {// first calculate the black chess board to score for (i = 0; i <11; i ) for (j = 0; j <11; j ) {// If the location is a space score IF (Board [i] [j] == 2) {for (int K = 0; k <252; k ) {// determine this location In which winning combination IF (BlackChessboard [i] [j]) {switch (win [1] [k]) {// By calculating the number of sub-numbers of five sons, 1 child five points , 2 children 50, 3 sub-500, 4 sub 5000 case 1: BlackCheSSGRADE [I] [j] = blackchessgrade [i] [j] 5; Break; Case 2: Blackchessgr ADE [i] [j] = blackchessgrade [i] [j] 50; Break; case 3: blackchessgrade [i] [j] = blackchessgrade [i] [j] 500; break; case 4: Blackchessgrade [i] [J] = blackchesSgrade [i] [j] 5000; Break;}}}} // If the current location is greater than the highest split position previously found, the current location information IF (BlackCheSSGRADE [I] [J]> Blackmax) { Blackmax = blackchessgrade [i] [j]; odhen = i; Othem = J;}}

/ / Calculate the white flag's checkerboard score for (i = 0; i <11; i ) for (j = 0; j <11; j ) {// If this location is a space to score if (Board [i ] [j] == 2) {for (int K = 0; k <252; K ) {// What is the winning combination of this position in the combination of IF (WhiteChesboard [i] [j] [k]) { Switch (Win [0] [K]) {// By calculating the number of children with a combination of five sub-individuals, 1 child, 2 sub-50, 3 sub 500, 4 sub 5000 // Let the computer under the same conditions More points, make it more important than attack, if you focus on defense, you can get it 1: Whitechessgrade [i] [j] = Whitechessgrade [i] [j] 6; break; casse 2: Whitechessgrade [i] [J] = Whitechessgrade [i] [j] 51; break; case 3: Whitechessgrade [i] [j] = Whitechessgrade [i] [j] 501; break; case 4: Whitechessgrade [i] [j] = Whitechessgrade [i] [j] 5001; break;}}}} // If the current location is greater than the highest split position previously found, save the current location information if (WhiteCheSSGRADE [I] [J]> WhiteMax) {WhiteMax = WhiteChessgrade [ I] [j]; selfX = i; Selfy = J;}}

IF (WhiteMax> = Blackmax) {Point.x = Selfx; Point.y = Selfy;} else {Point.x = OtherX; Point.y = Othem}} // If black chess else if (black) {/ / First calculate the white chess board to score for (i = 0; i <11; i ) for (j = 0; j <11; j ) {// If this location scores IF for the space ( Board [i] [j] == 2) {for (int K = 0; k <252; k ) {// determines which win in this position in which IF (WhiteChesboard [i] [j] [k ]) {Switch (Win [1] [K]) {// By calculating the number of children with a calculation combination, 1 child is 5,000, 2 sub-50, 3 sub 500, 4 sub 5000 case 1: WhiteChessgrade [ I] [J] = Whitechessgrade [i] [j] 5; break; case 2: Whitechessgrade [i] [j] = whitechechessgrade [i] [j] 50; break; case 3: Whitechessgrade [i] [j ] = Whitechessgrade [i] [j] 500; Break; Case 4: Whitechessgrade [i] [j] = Whitechessgrade [i] [j] 5000; Break;}}}} // If the current location is greater than before Maximum location, save the current location information if (WhiteCheSSGRADE [i] [j]> whitemax) {whitemax = whitechessgrade [i] [j]; odherx = i Othem = J;}}

// Calculate the chess board to score for (i = 0; i <11; i ) for (j = 0; j <11; j ) {// If this location scores IF (Board [ I] [j] == 2) {for (int K = 0; k <252; k ) {// determines which win in this position in the combination of IF (BlackChessboard [i] [j] [k]) {Switch (Win [0] [K]) {// By calculating the number of sub-number score, 1 child, 2 sub-50, 3 sub-500, 4 sub-5000 // allows the computer in the same conditions Under the one point, make it more important than attack, if you focus on defense, you can get Case 1: Blackchessgrade [i] [j] = blackchessgrade [i] [j] 6; break; casse 2: Blackchessgrade [i ] [j] [j] 51; Break; Case 3: Blackchessgrade [i] [j] = blackchessgrade [i] [j] 501; break; case 4: blackchessgrade [i] [j] = BlackCheSSGRADE [I] [J] 5001; Break;}}}} // If the current location is greater than the highest split position previously found, the current location information IF (BlackCheSSGRAX [I] [J]> Blackmax) {Blackmax = Blackchessgrade [i] [j]; selfX = i; Selfy = J;}} f (blackmax> = whitemax) {Point.x = Selfx; Poi Nt.y = Selfy;} else {Point.x = OtherX; point.y = otHERY;}} // If the highest score of the computer is larger than the player's highest score, the computer attacked initialmark (); returnire

// 下 白 旗 r r r ({ix) {ion {ix ((horizontal == -1)) {GameOver = True; Winner = false; return -1;} // If the position of the chess is not in the range of 11 * 11, it returns an error if ((horizontal> = 11) || (vertical> = 11) || (Horizontal <0) || (Vertical <0)) Return -1; if (Board [horizontal]! = 2) Return -1; Board [horizontal] [Vertical] = Whitechess; WhiteChessCount ; // Record the status of the next piece Recordchesstatus Horizontal, Vertical, WHITECHESS;

// Calculate the chess player on the chessboard in a combination of chess pieces in a combination of chess pieces if (! Compute erroral in white "<< whitechescount," COUT << "Compute Error In White << WhiteChessCount;

If (BlackchescountCount == 60) // There is no vacant situation on the board {GameOver = true; winner = -1;} // play chess to convert Roleswitch ();

Return 1;}} // Black Falls Int Chess :: BlackPlayChes (int horizontal, int value) {if (gameover) return -1; if (black) {ix ((horizontal == -1) && (Vertical == -1)) {GameOver = true; Winner = false; return -1;} // If the position of the chess pieces are not in the 11 * 11 range, returning an error if ((horizontal> = 11) || (Vertical > = 11) || (Vertical <0)) Return -1; if (Board [Horizontal]! = 2) Return -1; Board [Horizontal] [Vertal] = Blackchess; Blackchescount ;

// Record the status of the chess pieces RecordchessStatus (Horizontal, Vertical, Blackche;

// Check the chess hand on the chessboard in a combination of chessia in a combination of chess pieces in a combination of chessboards (! "Compute error in black") cout << "compute erroor in black"

If (BlackchescountCount == 60) // Survival on the board {GameOver = true; winner = -1;} // Purchaser converts Roleswitch (); returnit 1;} else return -1;} // Remelling, It can only be used to repent thessians INT Chess :: ContritionChess (Int Player) {// for use to store the current step Int Step; Point Point;

Step = WhitechessCount; if (step> 1) {if (player == whitechess) {// If the previous step is to undo two steps IF (Allchess [Step] .status == Blackchess) && (Allchess [ Step] .point.x! = -1)) {Point = allchess [step] .point; board [Point.x] [Point.y] = 2; Allchess [Step] .status = 2; Allchess [STEP]. Point.x = -1; allchess [step] .point.y = -1; // Restore STEP-1 combined winning number for (int i = 0; i <2; i ) for (int J = 0; J <252; j ) WIN [I] [j] = allchess [step] .win [i] [j]; blackcherscount--; step--;} // If white chess regularss IF ((allchess [step] .status == Whitechess) && (allchess [step] .point.x! = -1)) {Point = Allchess [step] .point; board [Point.x] [Point.y] = 2; Allchess [Step] .status = 2; Allchess [step] .point.x = -1; allchess [step] .point.y = -1; // Restore STEP-1 combined winning number for (int i = 0; i <2; i ) For (int J = 0; J <252; J ) WIN [I] [J] = Allchess [(BlackchessCount Whitechescount)]. Win [i] [j]; whitechesc Ount -; step -;}}}} else if (player == blackchess) {// If the previous step is to undo two-step IF (Allchess [Step] .status == Whitechess) && (Allchess [Step] .point.x! = -1))) {// Canceling White Point = Allchess [Step] .point; Board [Point.x] [Point.y] = 2; Allchess [Step] .status = 2; Allchess [ Step] .point.x = -1; allchess [step] .point.y = -1; // Restore STEP-1 combined winning number for (int i = 0; i <2; i ) for (int J = 0; J <252; J ) WIN [I] [J] = Allchess [Step] .win [i] [j];

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

New Post(0)