| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1069 人关注过本帖
标题:求教:一个判断五子棋胜负的算法
只看楼主 加入收藏
越毛越毛飞
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2008-1-2
收藏
 问题点数:0 回复次数:0 
求教:一个判断五子棋胜负的算法
不明白该算法怎样算的出是五子  1 2 3 4 5 6 7 8 都代表什么
//判断棋盘胜负
/*
             5 4 6
              \|/
            1 - - 3
              /|\
            7  2  8

*/
int checkChessWin(Site checkSize)
{
    int i, j ;
    int flagDirect[4] = {0,0,0,0}, flagDirectTure[4] = {0,0,0,0} ;
   
    for(i = 1;i < 5;i++)
    {
         // 1
         if( flagDirectTure[0] != -1)
         {
            if(checkSize.x+i < CB_LEN
            && chessMan[checkSize.x+i][checkSize.y] == chessKey+1)
            {
                flagDirect[0] ++ ;
            }
            else
            {
                flagDirectTure[0] = -1 ;
            }
         }
         // 2
         if(flagDirectTure[1] != -1)
         {
            if(checkSize.y+i < CB_LEN
            && chessMan[checkSize.x][checkSize.y+i] == chessKey+1)
            {
                flagDirect[1] ++ ;
            }
            else
            {
                flagDirectTure[1] = -1 ;
            }
         }
         // 5
         if( flagDirectTure[2] != -1)
         {
            if(checkSize.x-i >= 0 && checkSize.y-i >= 0
            && chessMan[checkSize.x-i][checkSize.y-i] == chessKey+1)
            {
                flagDirect[2] ++ ;
            }
            else
            {
                flagDirectTure[2] = -1 ;
            }
         }
         // 6
         if(flagDirectTure[3] != -1)
         {
            if(checkSize.x+i < CB_LEN && checkSize.y-i >= 0
            && chessMan[checkSize.x+i][checkSize.y-i] == chessKey+1)
            {
                flagDirect[3] ++ ;
            }
            else
            {
                flagDirectTure[3] = -1 ;
            }
         }
    }
   
    flagDirectTure[0] = 0 ;
    flagDirectTure[1] = 0 ;
    flagDirectTure[2] = 0 ;
    flagDirectTure[3] = 0 ;
   
    for(i = 1;i < 5;i++)
    {
         // 3
         if(flagDirectTure[0] != -1)
         {
            if(checkSize.x-i >= 0
            && chessMan[checkSize.x-i][checkSize.y] == chessKey+1)
            {
                flagDirect[0] ++ ;
            }
            else
            {
                flagDirectTure[0] = -1 ;
            }
         }
         if(flagDirect[0] >= 4)
          return 1;
         
         // 4
         if( flagDirectTure[1] != -1)
         {
            if(checkSize.y-i >= 0
            && chessMan[checkSize.x][checkSize.y-i] == chessKey+1)
            {
                flagDirect[1] ++ ;
            }
            else
            {
                flagDirectTure[1] = -1 ;
            }
         }
         if(flagDirect[1] >= 4)
          return 2;
         
         // 7
         if( flagDirectTure[3] != -1)
         {
            if(checkSize.x-i >= 0 && checkSize.y+i < CB_LEN
            && chessMan[checkSize.x-i][checkSize.y+i] == chessKey+1)
            {
                flagDirect[3] ++ ;
            }
            else
            {
                flagDirectTure[3] = -1 ;
            }
         }
         if(flagDirect[3] >= 4)
          return 4;
         
         // 8
         if( flagDirectTure[2] != -1)
         {
            if(checkSize.x+i < CB_LEN && checkSize.y+i < CB_LEN
            && chessMan[checkSize.x+i][checkSize.y+i] == chessKey+1)
            {
                flagDirect[2] ++ ;
            }
            else
            {
                flagDirectTure[2] = -1 ;
            }
         }
         if(flagDirect[2] >= 4)
          return 3;
     }

     return 0;
}
搜索更多相关主题的帖子: 五子棋 算法 胜负 判断 
2008-01-02 17:43
快速回复:求教:一个判断五子棋胜负的算法
数据加载中...
 
   



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

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