注册 登录
编程论坛 C++教室

五子棋游戏的判断输赢不知道哪里有问题

btn 发布于 2021-03-04 16:23, 1239 次点击
[code]#include<iostream>
#include<cstring>
using namespace std;


int main(){
    cout<<"---Game of Chess---"<<endl;
    cout<<"H against the C"<<endl;
   
    char a[7][7];
    for(int i=0;i<7;i++){
        for(int j=0;j<7;j++)
            a[i][j]='*';
    }
        for(int i=0;i<7;i++){
            for(int j=0;j<7;j++)
               cout<<a[i][j]<<' ';
            cout<<endl;
        }
   
    cout<<"Enter X,Y coordinates for moving:";
   
    int times=1;
    bool win(int x,int y,char a[7][7]);
   
   int m,n;
    do{
      cin>>m>>n;
   
      if(times%2!=0)
      a[m-1][n-1]='H';
      else
      a[m-1][n-1]='C';
   
       for(int i=0;i<7;i++){
            for(int j=0;j<7;j++){
               cout<<a[i][j]<<' ';
           }
            cout<<endl;
        }
    cout<<"Enter X,Y coordinates for moving:";
    times++;
    }while(win);
   
   
    if(times%2==0)
    cout<<"C won!";
    else
    cout<<"H won!";
   
    return 0;
}
bool win(int x,int y,char a[7][7]){
   
    for(int i=0;i<7;i++){
        int count=0;
            for(int j=0;j<6;j++){
                if(a[i][j]=a[i][j+1])
                count++;
            }
            if(count=4)
            return false;
            else
            return true;
    }
        for(int i=0;i<6;i++){
           int count=0;
           for(int j=0;j<7;j++){
               
                if(a[i][j]=a[i+1][j])
                count++;
            }
            if(count=4)
            return false;
            else
            return true;
        }
        for(int i=0;i<6;i++){
           int count=0;
           for(int j=0;j<6;j++){
               
                if(a[i][j]=a[i+1][j+1])
                count++;
            }
            if(count=4)
            return false;
            else
            return true;
       }
           for(int i=0;2<i&&i<7;i++){
             int count=0;
             for(int j=0;2<i&&i<7;j++){
               
                if(a[i][j]=a[i-1][j-1])
                count++;
            }
            if(count=4)
            return false;
            else
            return true;
           }
}



判断输赢不知道哪里出了问题
1 回复
#2
rjsp2021-03-08 10:52
你的判断逻辑没说,那我不知道。
我仅仅编译了一下你的代码,有很多错误

    bool win(int x,int y,char a[7][7]);

    do{
        ……
    }while(win);


有四处 if(count=4)
1