| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 428 人关注过本帖
标题:请问还有更好的五子棋判断方法吗
取消只看楼主 加入收藏
伍初
Rank: 2
等 级:论坛游民
帖 子:16
专家分:22
注 册:2011-5-15
结帖率:0
收藏
 问题点数:0 回复次数:0 
请问还有更好的五子棋判断方法吗
int CMywuziqi1::Judgment()
{
  UINT count1=0,count2=0;
  for (int i=0;i<15;i++)
  {   if(count1>=5||count2>=5)
      break;
      for (int j=0;j<15;j++)
  {
       if(Board[i][j]==1)
       { count1++;count2=0;}
       if(Board[i][j]==2)
        { count2++;count1=0;}
       if(count1>=5||count2>=5)
         break;
       if(Board[i][j]==0)
       {count2=0;count1=0;}}
}
/////////////////////////

if(count1<5&&count2<5)
{     count1=0;count2=0;
       for (int j=0;j<15;j++)
      {    if(count1>=5||count2>=5)break;
           for (int i=0;i<15;i++)
          {
            if(Board[i][j]==1)
            {
            count1++;count2=0;
            }
            if(Board[i][j]==2)
            {
             count2++;count1=0;
            }
           if(count1>=5||count2>=5)
            break;
           if(Board[i][j]==0)
           {
            count2=0;count1=0;
}}}}
////////////////////////////////

if(count1<5&&count2<5)
{count1=0;count2=0;
      for(int i=4;i<15;i++)
      {if(count1>=5||count2>=5)break;
           for(int j=0,k=i;k>=0,j<=i;j++,k--)
           {
           if(Board[j][k]==1)
           {
             count1++;
              count2=0;
            }
            if(Board[j][k]==2)
            {
             count2++;
             count1=0;
             }
            if(count1>=5||count2>=5)
            break;
            if(Board[j][k]==0)
            {
             count2=0;
             count1=0;
}}}}
///////////////////////////////

if(count1<5&&count2<5)
{count1=0;count2=0;
             for(int i=0;i<15;i++)
            {if(count1>=5||count2>=5) break;
                 for(int j=i,k=14;j<15;j++,k--)
                {
                        if(Board[j][k]==1)
                        { count1++;count2=0;}
                        if(Board[j][k]==2)
                        { count2++;count1=0;}
                        if(count1>=5||count2>=5)
                             break;
                        if(Board[j][k]==0)
                         {count2=0;count1=0;
}}}}
///////////////////////////////
if(count1<5&&count2<5)
{count1=0;count2=0;
                      for(int i=10;i>=0;i--)
                      {if(count1>=5||count2>=5)
                         break;
                              for(int j=0,k=i;j<15,k<15;j++,k++)
                             {
                                     if(Board[k][j]==1)
                                       {
                                           count1++;count2=0;
                                        }
                                      if(Board[k][j]==2)
                                      {
                                           count2++;count1=0;
                                        }
                                       if(count1>=5||count2>=5)
                                          break;
                                       if(Board[k][j]==0)
                                       {
                                         count2=0;count1=0;
}}}}
//////////////////////////
if(count1<5&&count2<5)
{count1=0;count2=0;
            for(int i=0;i<15;i++)
           {if(count1>=5||count2>=5)
                 break;
                     for(int k=0,j=i;j<15;j++,k++)
                    {
                      if(Board[k][j]==1)
                       {
                       count1++;count2=0;
                        }
                       if(Board[k][j]==2)
                        {
                        count2++;count1=0;
                         }
                         if(count1>=5||count2>=5)
                              break;
                        if(Board[k][j]==0)
                         {
                         count2=0;count1=0;
}}}}
if(count1>=5)
return 1;
if(count2>=5)
return 2;
if(count1<5&&count2<5)
return 0;
}
搜索更多相关主题的帖子: 五子棋 
2011-09-05 17:58
快速回复:请问还有更好的五子棋判断方法吗
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016924 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved