#ifndefDOTS_AND_BOXES_H_INCLUDED#defineDOTS_AND_BOXES_H_INCLUDED#includeiostream#includeiomanip#includeprocess.husingnamespacestd;classDots{public:Dots(){};voidinit();//Çå¿ÕÍê³ÉboolisFull();//ÅжÏÂúÍê³ÉvoidisWin();//ÊÇ·ñÂúÍê³ÉvoidHcapture();//ºáÏßÕ¼ÁìvoidVcapture();//ÊúÏßÕ¼Áìvoidthink();//µçÄÔ˼¿¼²½×Óvoidplay();//ÏÂÆå//wanchengvoiddisplay();//Íê³ÉvoidsetSide();intshowposition();~Dots(){};private:charboard[11][11];intposition_i;intposition_j;intside;};#endif//DOTS_AND_BOXES_H_INCLUDEDboolDots::isFull(){inti;intj;for(i=1;i=9;i+=2){for(j=1;j=9;j+=2){if(board[i][j]==''){returnfalse;}}}returntrue;}//³õʼ»¯ÆåÅÌÊý×évoidDots::init(){inti,j;for(i=0;i11;i++){for(j=0;j11;j++){board[i][j]='';}}for(i=0;i11;i+=2){for(j=0;j11;j+=2){board[i][j]='*';}}}//Åжϻñʤ·½(Âúʱµ÷ÓÃ)voidDots::isWin(){inti,j;intred=0;intblue=0;for(i=1;i9;i+=2){for(j=1;j9;j+=2){if(board[i][j]=='R'){red++;}else//************************{blue++;}}}if(redblue){coutREDʤÀû!endl;}else{coutBLUEʤÀû!;}}//ÂäÏ߶ùvoidDots::play(){intm,n;intp_i,p_j;if(side==1){coutÇëºì·½ÊäÈëÒªÁ¬ÏßµÄλÖÃ(i,j):;}else{coutÇëÀ¶·½ÊäÈëÒªÁ¬ÏßµÄλÖÃ(i,j):;}cinp_ip_j;position_i=p_j;position_j=p_i;m=(position_i%2);n=(position_j%2);system(cls);coutsetw(40)µã¸ñÆåendlendl;if(board[position_i][position_j]==''){if(m==0&&n!=0){board[position_i][position_j]='-';}//ifelseif(m!=0&&n==0){board[position_i][position_j]='|';}else{display();coutλÖ÷Ƿ¨,ÇëÖØÐÂÊäÈë!endl;play();}}//ifelse{display();coutλÖ÷Ƿ¨,ÇëÖØÐÂÊäÈë!endl;play();}}//¡°¡ª¡±ÏßÕ¼ÁìvoidDots::Hcapture(){if(position_i==0){if(board[position_i+1][position_j-1]!=''&&board[position_i+2][position_j]!=''&&board[position_i+1][position_j+1]!=''){if(side==1){board[position_i+1][position_j]='R';}else{board[position_i+1][position_j]='B';}}else{side*=-1;}}elseif(position_i==10){if(board[position_i-1][position_j-1]!=''&&board[position_i-2][position_j]!=''&&board[position_i-1][position_j+1]!=''){if(side==1){board[position_i-1][position_j]='R';}else{board[position_i-1][position_j]='B';}}else{side*=-1;}}else{if(board[position_i+1][position_j-1]!=''&&board[position_i+2][position_j]!=''&&board[position_i+1][position_j+1]!=''&&board[position_i-1][position_j-1]!=''&&board[position_i-2][position_j]!=''&&board[position_i-1][position_j+1]!=''){if(side==1){board[position_i+1][position_j]='R';board[position_i-1][position_j]='R';}else{board[position_i+1][position_j]='B';board[position_i-1][position_j]='B';}}elseif(board[position_i+1][position_j-1]!=''&&board[position_i+2][position_j]!=''&&board[position_i+1][position_j+1]!=''){if(side==1){board[position_i+1][position_j]='R';}else{board[position_i+1][position_j]='B';}}elseif(board[position_i-1][position_j-1]!=''&&board[position_i-2][position_j]!=''&&board[position_i-1][position_j+1]!=''){if(side==1){board[position_i-1][position_j]='R';}else{board[position_i-1][position_j]='B';}}else{side*=-1;}}}//¡°|¡±ÏßÕ¼ÁìvoidDots::Vcapture(){if(position_j==0){if(board[position_i-1][position_j+1]!=''&&board[position_i][position_j+2]!=''&&board[position_i+1][position_j+1]!=''){if(side==1){board[position_i][position_j+1]='R';}else{board[position_i][position_j+1]='B';}}else{side*=-1;}}elseif(position_j==10){if(board[position_i-1][position_j-1]!=''&&board[position_i][position_j-2]!=''&&board[position_i+1][position_j-1]!=''){if(side==1){board[position_i][position_j-1]='R';}else{board[position_i][position_j-1]='B';}}else{side*=-1;}}else{if(board[position_i+1][position_j+1]!=''&&board[position_i][position_j+2]!=''&&board[position_i-1][position_j]!=''&&board[position_i-1][position_j-1]!=''&&board[position_i][position_j-2]!=''&&board[position_i+1][position_j-1]!=''){if(side==1){board[position_i][position_j+1]='R';board[position_i][position_j-1]='R';}else{board[position_i][position_j+1]='B';board[position_i][position_j-1]='B';}}elseif(board[position_i+1][position_j+1]!=''&&board[position_i][position_j+2]!=''&&board[position_i-1][position_j]!=''){if(side==1){board[position_i][position_j+1]='R';}else{board[position_i][position_j+1]='B';}}elseif(board[position_i-1][position_j-1]!=''&&board[position_i][position_j-2]!=''&&board[position_i+1][position_j-1]!=''){if(side==1){board[position_i][position_j-1]='R';}else{board[position_i][position_j-1]='B';}}else{side*=-1;}}}//ÏÔʾÆåÅÌvoidDots::display(){inti,j;for(i=0;i11;i++){coutsetw(26);for(j=0;j11;j++){coutboard[i][j]setw(2);}cout''i;coutendl;}board[11][0]='0';board[11][1]='1';board[11][2]='2';board[11][3]='3';board[11][4]='4';board[11][5]='5';board[11][6]='6';board[11][7]='7';board[11][8]='8';board[11][9]='9';board[11][10]='1';coutsetw(26)board[11][0]setw(2);coutboard[11][1]setw(2);coutboard[11][2]setw(2);coutboard[11][3]setw(2);coutboard[11][4]setw(2);coutboard[11][5]setw(2);coutboard[11][6]setw(2);coutboard[11][7]setw(2);coutboard[11][8]setw(2);coutboard[11][9]setw(2);coutboard[11][10];cout0;coutendl;}//·µ»ØÌض¨ÖµÒÔÈ·¶¨ÊÇÄÄÖÖÏßintDots::showposition(){if(board[position_i][position_j]=='-'){