It is said that there is an undefeated algorithm. I will write another version of PVC tomorrow.
The topic is that today I am bored with writing a game of well-known chess. By the way, I gradually get used to good code styles and learn from them.
Jzq2.cpp
/* For the PVP version of the N-character chess game, the DOS version board can be expanded, you only need to adjust the detection conditions, other interfaces do not need to change. Non-man-machine combat type, PVP type; @ author: unparalleled in the world @ date: 2014-5-25 @ version: 1.0 */# include
# Include
# Define INVALIDINDEX-1 # define FULL-2 # define OK 0 # define WIN 1 # define ISIN-3 using namespace std; struct box {// use box to represent the int chess of each lattice on the Board; // use a color to represent the pawns, black and whiteint status; // 0 to indicate that the lattice has no pawns, 1 indicates that a pawn has been obtained}; enum COLOR {black, white}; class chessBoard {private: static const int MAXROW = 10; static const int MAXCOLUMN = 10; int row; int column; int blackBox; // The number of remaining checkerboard grids. You can click box arr [MAXROW] [MAXCOLUMN]; void setRow (int r) {row = r ;}; void setCol (int c) {column = c ;}; int GetRow () const {return row ;}; int GetCol () const {return column ;}; public: chessBoard (int r, int col) {if (r> MAXROW | col> MAXCOLUMN) {cerr <"The board size exceeds the range" <
= R | j> = col) return INVALIDINDEX; // if (c! = Black & c! = White) // return INVALIDINDEX; if (arr [I] [j]. status = 0) {// drop the pawn into the checker arr [I] [j]. chess = c; arr [I] [j]. status = 1; // identify the flush (); // refresh blackBox --; if (isGameOver () return WIN; if (isFull () return FULL; return OK;} return ISIN;} protected: void creat () {// initialize the checkboard int r = chessBoard: GetRow (); int col = chessBoard: GetCol (); for (int I = 0; I
= 0 & j
Main. cpp
# Include
# Include "jzq2.cpp" using namespace std; int main () {// 3 indicates that the chessboard is 3*3, and the three rows are the same as the victory, 5, 5 represents 5-character chess, but the size of the Board is also 5*5 // The expansion board will be launched in the next version chessBoard cb (); int status; COLOR c = black; // record who is going to take the next step int x, y; bool falg = false; // used to record whether the game is successful. bool isExit = false; // used to record whether the game is over while (! IsExit) {cout <"\ n \" 0 \ "represents white, \" * \ "represents black" <
> X> y;/* if (falg) c = black? White: black; // enter */status = cb. insertChess (x, y, c); switch (status) {// out of the range. If INVALIDINDEX-1 is returned, the system returns WIN 1. // if the Board is full, return FULL-2 // if the player is playing normally, OK 0 case 0: falg = true; c = black? White: black; // if the game is successfully played, change to break. case-1: cout <"\ n the input coordinate is incorrect. It is out of range" <
If you have tested 3*3 without a BUG, you must enter a number. If you enter a letter, it will crash!
Put it in PVP for fun, hahaha.
Today, I ran to the duoyi network to test the problem. On the way back, I thought of the last question and wrote less judgment. I was depressed.
I thought about it on the way back.
Depressing ing ......
Okay, you're asleep. Good night.