用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - c代码库

五子棋

2017-06-20 作者: 赶蚊子举报

[c]代码库

#include"global.h"
#include"game.h"
#include"modal.h"
int AnChessStatus[15][15];
void initStatus()
{
int i;
int j;
for(i=0;i<15;i++)
{
for(j=0;j<15;j++)
{
	 AnChessStatus[i][j]=STATUS_BLANK;
}
}
}
int getStatus(const Point spPoint)
{
	return  AnChessStatus[spPoint.row][spPoint.col];
}

void setStatus(const Point spPoint)
{
AnChessStatus[spPoint.row][spPoint.col]=spPoint.status;
}

int judge(Point spPoint)
{
int count=0;
spPoint.status=AnChessStatus[spPoint.row][spPoint.col];
//横向
count=judgeHorizontal(spPoint);
if(count>=5)
{
	return JUDGE_WIN;
}
//竖向
count=judgeVertical(spPoint);
if(count>=5)
{
return JUDGE_WIN;
}
//向上对角线
count=judgeHyperphoria(spPoint);
if(count>=5)
{
return JUDGE_WIN;
}
//向下对角线
count=judgeHypophoria(spPoint);
if(count>=5)
{
return JUDGE_WIN;
}
if(judgeDraw()==TRUE)
{
return JUDGE_DRAW;
}
return JUDGE_PLAY;
}

//横向
int judgeHorizontal(const Point spPoint)
{
	int i;
	int j;
	int counter=1;
int standard=spPoint.status;
j=spPoint.col-1;
i=spPoint.row;
while(j>=0)
{
if(AnChessStatus[i][j--]==standard)
{
counter++;
}
else
{
break;
}
}
j=spPoint.col+1;
while(j<=14)
{
if(AnChessStatus[i][j++]==standard)
{
counter++;
}
else
{
break;
}
}
return counter;
}
 
//竖向
int judgeVertical(const Point spPoint)
{
int i;
int j;
int counter=1;
int standard=spPoint.status;
j=spPoint.col;
i=spPoint.row-1;
while(i>=0)
{
if(AnChessStatus[i--][j]==standard)
{
counter++;
}
else
{
break;
}
}
i=spPoint.row+1;
while(i<=14)
{
if(AnChessStatus[i++][j]==standard)
{
counter++;
}
else
{
break;
}
}
return counter;
}

//向上对角线
int judgeHyperphoria(const Point spPoint)
{
int i;
int j;
int counter=1;
int standard=spPoint.status;
j=spPoint.col-1;
i=spPoint.row+1;
while(i>=0&&j>=0)
{
if(AnChessStatus[i++][j--]==standard)
{
counter++;
}
else
{
break;
}
}
i=spPoint.row-1;
j=spPoint.col+1;
while(i<=14&&j<=14)
{
if(AnChessStatus[i--][j++]==standard)
{
counter++;
}
else
{
break;
}
}
return counter;
}

//向下对角线
int judgeHypophoria(const Point spPoint)
{
int i;
int j;
int counter=1;
int standard=spPoint.status;
j=spPoint.col-1;
i=spPoint.row-1;
while(i>=0&&j>=0)
{
if(AnChessStatus[i--][j--]==standard)
{
counter++;
}
else
{
break;
}
}
i=spPoint.row+1;
j=spPoint.col+1;
while(i<=14&&j<=14)
{
if(AnChessStatus[i++][j++]==standard)
{
counter++;
}
else
{
break;
}
}
return counter;
}

int judgeDraw()
{
int i;
int j;
for(i=0;i<15;i++)
{
for(j=0;j<15;j++)
{
if(AnChessStatus[i][j]==STATUS_BLANK)
{
return FALSE;
}
}
}
return TRUE;
}

[源代码打包下载]




网友评论    (发表评论)

共6 条评论 1/1页

发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...