#include <iostream> #include <iomanip> #include <cstdlib> #include <cstdio> #include < string.h>using namespace Std; const int X = 21; Checkerboard row number const int Y = 21; Number of checkerboard columns char p[x][y]; //define Checkerboard int m=0;//Define temporary points, save input coordinates int n=0; void display () //output checkerboard { for (int i=0; i<x; i++) COUT<<SETW (3) <<setfill (') <<i; cout<<endl; for (int i=1; i<y; i++) { COUT<<SETW (3) <<setfill (') << ;i; for (int j=1;j<x;j++) COUT<<SETW (3) <&L T;setfill (') <<p[i][j]; cout<<endl; } } void Black () //black square lazi { cout<< "Please black input lazi location: \ n" << "Please enter the number of rows Lazi:"; cin>>m; cout<< "Please enter the number of columns for Lazi:"; cin>>n;  If (m<=0| | m>=x| | n>=y| | n<=0) { cout<< "out of the checkerboard range, please reenter the correct coordinates!" \ n "; Black (); } Else if ((p[m][n]==1) | | p[m][n]==2) { cout<< "The point already has a pawn, please re-select the Lazi point!" \ n "; Black (); } else p[m][n]=1; Black is used to represent system ("CLS"); display ();} void Red () //Red Square lazi { cout<< "Please enter the Lazi location: \ n" << "Please enter the number of rows Lazi:"; cin>>m; cout<< "Please enter the number of columns for Lazi:"; cin>>n; if (m>=x| | m<=0| | n<=0| | n>=y) { cout<< "out of the checkerboard range, please reenter the correct coordinates!" \ n "; Red (); } Else if ((p[m][n]==1) | | p[m][n]==2) { cout<< "The point already has a pawn, please re-select the Lazi point!" \ n "; &NBSp Red (); } else p[m][n]=2; The red side represents the system ("CLS"); display ();} int Evalue () //only need to judge the Lazi point as the center of the nine-point "meter" word is continuous can { int k = 0,r = 0; /* Slash judge */ for ( k=3;k<x-2;k++) //Two, where the p[k][r]!= '-' is excluded from the situation { for (r=3;r<y-2;r++) & nbsp { if (p[k][r]!= '-' &&p[k-2][r-2]==p[k][r]&& P[k-1][r-1]==p[k][r]&&p[k+1][r+1]==p[k][r]&&p[k+2][r+2]==p[k][r]) return 1; ELSE if (p[k][r]!= '-' &&p[k+2][r-2]== P[k][r]&&p[k+1][r-1]==p[k][r]&&p[k-1][r+1]==p[k][r]&&p[k-2][r+2]==p[k][r]) return 1; } } /* Line judging */&NBSP ; for (K=1;K< x;k++) //p[k][r]!= '-' is an exclusion condition for (r=3;r<y-2;r++) & nbsp if (p[k][r]!= '-' &&p[k][r-2]==p[k][r]&&p[k][r-1]==p[k][r]&&p[k][r+1]==p[k][r]&&p K [R+2]==p[k][r] return 1; //Vertical line judging */ for (k= 3;k<x-2;k++) //p[k][r]!= '-' is excluded from the situation for (r=1;r<y;r++) if (p[k][r]!= '-' &&p[k-2][r]==p[k][r]&&p[k-1][r]==p[k][r]&&p[k+1][r]==p[k][r ]&&p[k+2][r]==p[k][r]) return 1; return 0;} int Main () { memset (P, '-', 441); //initialized to '-' cout<< "Welcome to Easy double PvP Gobang game \ n" << "Gobang games are as follows: \ n"; display (); while (1) { &NBS P Red (); if (EVAlue ()) { cout<< "Red side wins!" \ n "; break; } Black ()   ; if (Evalue ()) { cout<< "Black wins!" \ n "; break; } } retur n 0;}
Gobang C + + implementation