Three-dimensional coat player programming
Lin Qing
Game Rules: There are some three-dimensional circle gaming products on the market, the most common, 4-storey transparent plastic version, with 4 * 4-form caves. When two people played, the colorful chess pieces were placed in the empty hole, and the four colored chess pieces were first wins. There are many ways to connect, which can be horizontal, vertical, or angled. Analysis: 4 pieces have a total of 76 possible straight lines. Each layer, there are 8 lines with parallel lines, plus 2 diagonal, so there are 10 lines of each layer, and there are 40 4th floor. There are 16 vertical lines, 4 long diagonal, and in 8 vertical faces, 2 diagons on each surface. Design plan: According to the score of this chess piece: (Take Black Chess) (1): Add black chess in a blank straight line 1 point in the straight line of only one white chess 2 points Only a black chess line with black chess 3 points in the straight line with two black chess, black chess 4 points in line with two white chess, black chess 5 points in the straight line of three black chess Additional black chess must be executed. Return to successfully add black chess with three white chess (2): Then, the total number of straight lines affecting the number of straight lines, if the biggest is the biggest.
Give code:
// This version does not consider the display of graphics in many properties Nothing record: #include
// pmatixline [i] [7] Recorded this picture of the chess pieces and 76 straight lines related to int pmatixline [64] [7] = {{1, 5, 9, 41, 57, 61, 69} {1, 6, 42, 63, 0, 0, 0}, {1, 7, 43, 65, 0, 0, 0}, {1, 8, 10, 44, 58, 67, 70}, { 2, 5, 45, 71, 0, 0, 0}, {2, 6, 9, 46, 0, 0, 0}, {2, 7, 10, 47, 0, 0}, {2, 8, 48, 72, 0, 0}, {3, 5, 49, 73, 0, 0, 0}, {3, 6, 10, 50, 0, 0, 0}, {3, 7, 9, 51, 0, 0}, {3, 8, 52, 74, 0, 0, 0}, {4, 5, 10, 53, 59, 62, 75}, {4, 6, 54, 64, 0, 0, 0}, {4, 7, 55, 66, 0, 0}, {4, 8, 9, 56, 60, 68, 76}, {11, 15, 19, 41, 0,0,0}, {11, 16, 42, 69, 0, 0, 0}, {11, 17, 43, 70, 0, 0, 0}, {11, 18, 20, 44, 0, 0,0}, {12,15,45,61,0,0,0}, {12, 16, 19, 46, 57, 63, 71}, {12, 17, 20, 47, 58, 65, 72}, {12,18,48,67,0,0,0}, {13, 15, 49, 62, 0, 0, 0}, {13, 16, 20, 50, 59, 64, 73} {13, 17, 19, 51, 60, 66, 74}, {13, 18, 52, 68, 0, 0, 0}, {14, 15, 20, 53, 0, 0, 0}, { 14, 16, 54, 75, 0, 0}, {14, 17, 55, 76, 0, 0, 0}, {14, 18, 19, 56, 0, 0, 0}, {21, 25, 29, 41, 0, 0}, {21, 26, 42, 70, 0, 0, 0}, {21, 27, 43, 69, 0, 0, 0}, {21, 28, 30, 44, 0, 0, 0}, {22, 25, 45, 62, 0, 0, 0}, {22, 26, 29, 46, 60, 64, 72}, {22, 27, 30, 47, 59, 66, 71}, {22, 28, 48, 68}, {23, 25, 49, 61, 0, 0, 0}, {23, 26, 30, 50, 58, 63, 74} {23, 27, 29, 51, 57, 65, 73}, {23, 28, 52, 67, 0, 0, 0}, {24, 25, 30, 53, 0, 0, 0}, { 24, 26, 54, 76, 0, 0, 0}, {24, 27, 55, 75, 0, 0, 0}, {2 4, 28, 29, 26, 0, 0}, {31, 35, 39, 41, 60, 62, 70}, {31, 36, 42, 64, 0, 0, 0}, {31, 37, 43, 66, 0, 0}, {31, 38, 40, 44, 59, 68, 69}, {32, 35, 45, 72, 0, 0, 0}, {32, 36, 39, 46, 0, 0, 0}, {32, 37, 40, 47, 0, 0, 0}, {32, 38, 48, 71, 0, 0, 0}, {33, 35, 49, 74, 0, 0, 0}, {33, 36, 40, 50, 0, 0}, {33, 37, 39, 51, 0, 0, 0}, {33, 38, 52, 73, 0,0,0}, {34, 35, 40, 53, 58, 61, 76}, {34, 36, 54, 63, 0, 0, 0}, {34, 37, 55, 65, 0, 0,0}, {34,38,39,56,57,67,75}}; typedef enum LineStyle {empty, oneblack, towblack, threeblack, onewhite, towwhite, threewhite, mix, succeed} MyLineStyle; typedef enum ChessmanStyle { WITHOUT, CHESSBLACK, CHESSWHIUT} mychessmanstyle; // typef enjoy} mychescessmanstyle; typedef enum currentches {black, white} mycurrentche;
// Implement the input of the CHESS to change the line status affected by the AlLnestyle and the status of allChess chess pieces to facilitate the filtering of this selection // Return 1 Success Int ChangeState (int ifblack, mylinestyle allLinesTyle ", int Chess, mychescessmanstyle Allchess [64] ); // Calculate If the score of the lower position // becomes a unique one of its own 1 //, there are two 3 // become three 4 // become four max 1 // Destroy the other three max // destroy the other side 2 // destroy the two 5 // From the original use of useless 0 // Return -1 is successful Int SingleCount (int ifblack, int cables, mylinestyle allLinestyle [76]); // Implement the option to choose the most ideal return sub-position below // Return -1 Picple Sub-cash with Int ProjectSelect (int ifblack, mylinestyle allLinesTyle 76], MychesmanStyle Allchess [64]); // White Chess User Input Status INT INPUTCHESS (INT IFBLACK, MychesmanStyle Allchesess [64]); // Print Checasbon Int Chessboard (MychesmanStyle Allchess "; // Print Menu Char Menu (); //man - machine game int mantocomputer (); // stand-alone version of the game INT mantoman (); // Game rule int tentime (); int ChangeState (int ifblack, mylinestyle allLinesTyle [76], int Chess, MychesSmanStyle Allchesess [64]) {INT I; INT CURLINE; IF (Allchess [Chess]) {Printf ("DID Not Chance Input"); Return 0;} // Allchess [Chess] = Have; ifblack // White under white {Allchess [chess] = chesswhite; for (i = 0; i <7 && pmatixline [chess] [i]! = 0; i ) {curline = PM atixLine [chess] [i] -1; switch (AllLineStyle [curline]) {case empty: AllLineStyle [curline] = onewhite; break; case oneblack: case towblack: case threeblack: AllLineStyle [curline] = mix; break; case onewhite : AllLineStyle [curline] = towwhite; break; case towwhite: AllLineStyle [curline] = threewhite; break; case threewhite: AllLineStyle [curline] = succeed; return 1; case mix: break;}}} else // {the Black Allchess [chess] = chessblack; for (i = 0; i <7 && pmatixline [chess] [i]! = 0; i ) {curline = pmatixline [chess] [i] -1;
switch (AllLineStyle [curline]) {case empty: AllLineStyle [curline] = oneblack; break; case oneblack: AllLineStyle [curline] = towblack; break; case towblack: AllLineStyle [curline] = threeblack; break; case threeblack: AllLineStyle [curline ] = succeed; ruln 1; Case OneWhite: Case ThreeWhite: AllLinesTyle [curline] = Mix; Case Mix: Break;}}} Return 0;
// Calculation If the score of this position is // becomes a unique one of its own 1 //, there are two 3 // become three 4 // become four max 1 // Destroy the other three max // destroy the other side 2 // destroy the other side 5 // From the original use of useless 0 // Return -1 is success, must Select int singlecount (int ifblack, int chess, mylinestyle allentyle [76]) {INT i; int curline; int sum = 0; if (ifblack) // White {for (i = 0; i <7 && pmatixline [chess] [i]! = 0; i ) {curline = pmatixline [chess] [i] -1; switch (allLinestyle: sum = SUM 1; Break; Case OneBlack: Sum = SUM 2; Break; Case Towblack: Break; Case Threeblack: Return Max; Case OneWhite: Sum = SUM 3; Break; Case TowWhite: Sum = SUM 4; Break; Case ThreeWhite: Return -1; Case Mix : Break;}}} else // Black chess {for (i = 0; i <7 && pmatixline [chess] [i]! = 0; i ) {curline = pmatixline [chess] [i] -1; switch (allLinesTyle [CURLINE]) {Case Empty: Sum = SUM 1; Break; Case OneBlack: Sum = SUM 3; Break; Case Towblack: Sum = SUM 4; Break; Case ThreeBlack: Return -1; Case OneWhite: Sum = SUM 2; Break; Case TowWhite: Sum = SUM 5; Break; Case ThreeWhite: Sum = max; break; case: break;}}} Return SUM;} // Implement the option of the most ideal back to the chess position // Return -1 colorless INT ProjectSelect (int ifblack, mylinester allLines "[64]) {int downloadMARK = 0; int currentmark = 0; For (int i = 0; i <64; i ) { IF (Allchess "; currentmark = singlecount (ifb, i, alllinestyle; if (currentmark == - 1) Return i; if (currentmark> maxmark) {downchess = i; maxmark = currentmark;
}}}}}} // Bai Chess User Input Status INT INPUTCHESS (INT IFBLACK, Mychescessmanstyle Allchesess [64]) {Int Z, X, Y; Int Chess; Do {CHESSBOARD (AllChess); if (ifblack == Black ) PRINTF ("Black Check Cap (Layer, Row, List):", Else Printf ("White Vernic% C (Layer, Layer, Column):", SCANF ("% D, % D,% D ", & Z, & Y, & X); chess = (z-1) * 16 y * 4 x;} while (z> 4 || z <1 || y> 3 || y < 0 || x> 3 || x <0 || Allchess [Chess]! = Without); Return Chess;} // Print Chess Dish Int Chessboard (MyChessmanStyle Allchess [64]) {INT I, J, M, CURRENT = 0 System ("CLS"); Printf ("3D Circle Clip Opera / N"); Printf ("| | (3) | | (4) | / N"); Printf "| 0123 | | 0123 | 0123 | | 0123 | / n"); for (i = 0; i <4; i ) {for (j = 0; j <4; j ) {printf ("% D" , i); for (m = 0; m ) {switch (allchess [current ]) {CASE without: Printf (""); break; case cupblack: printf ("% c", 1); BREAK Case Casswhite: Printf ("% C", 2); Break;}} printf ("|"); current = current 12;} printf ("/ n"); current = (i 1) * 4; } Return 1;} // Print menu char MENU () {char ch; do {system ("CLS"); Printf ("(J) Human Mode / N"); Printf ("(M) People - People Mode / N "); Printf (" " (R) Rules / N "); Printf (" (f) Return / N "); Printf (" Please select the operation you want (J, M, R, F): "); scanf ("% C " , CH = Toupper (CH);} while (ch! = 'j' && ch! = 'm' && ch! = 'r' && ch! = 'r'); return ch;} //man - machine game Int mantocomputer () {mycurrentches, currentchess = black; mylinestyle line [76]; mychescessmanstyle chess [64]; int getChess = -1; int 1; for (i = 0; i <76; i ) line [i] = Empty; For (i = 0; i <84;
i ) Chess [i] = without; // chessboard (chess); do {ife ((getches = INPUTCHESS, CHESS) == - 1) {Printf ("Input Error or Exit / N"); Break; } IF (CHANGESTATE (CURRENTCHESS, LINE, GETCHESS, CHESS) {CHESSBOARD (CHESS); Printf ("Black Win / N"); Break;} Currentches = White; IF (CURRENTCHESS, LINE, CHESS) ) == - 1) {Printf ("A Draw In Chess / N"); Break;} IF (CHANGESTATE (CURRENTCHESS, LINE, GETCHESS, CHESS) {CHESSBOARD (CHESS); Printf ("White Win / N") Break;} currentches = black; chess;} while (1); return 1;} // stand-alone version of the game Int mantoman () {return 1;} // game rule int} () {Return 1;} int main () {char CH; do {CH = MENU (); switch (ch) {case 'j': mantocomputer (); break; case 'm: mantoman (); break; case' r ' : Readme (); Break; Case 'f': Break;}} while (ch == 'f'); Printf ("/ n welcomes / n"); system ("pause"); return 1;} / / Note: For the first time, please forgive me.