求教:一个判断五子棋胜负的算法
不明白该算法怎样算的出是五子 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;
}