DarryRing1945184 2015-10-11 02:09
浏览 627

五子棋算法无问题只差输出,求帮忙~~~

#include
#define SIZE 10
#define row 10
#define clow 10
int b[row][clow]={{0}};
void print_board(void){
int i,j,t=0;
//char b[row][clow]={0};
printf(" 0 1 2 3 4 5 6 7 8 9 ");
printf("\n");
printf(" ");
for(i=0;i<2*SIZE+3;i++){
printf("-");
}
printf("\n");
for(i=0;i<SIZE;i++){
printf("%d",t);
t++;
printf("|");
for(j=0;j<SIZE;j++){
//if(*(char )(b)==0)
//printf(" +");
if (
(char*)(b+i*SIZE+j)==1)
printf(" @");
else if (*(char*)(b+i*SIZE+j)==2)
printf(" o");
else printf(" +");
}
printf(" |\n");
}
printf(" ");
for (i=0;i<2*SIZE+3;i++){
printf("-");
}
printf("\n");

}
int test(int x,int y){
if(x=row)
return 0;
if(y=clow)
return 0;
if(b[row][clow]==0)
return 1;
return 0;

}
int putchess(int x,int y,int who){
if(test(x,y)){
b[row][clow]=who;
return 1;
}
else
return 2;
}
int check(int x,int y){
int i,j;
int nx = x, ny = y;
int count = 1;
int dir_x[] = {1,1,1,0};
int dir_y[] = {-1,0,1,1};

int who=b[x][y];
if (who == 0)
    return 0;

for (i = 0; i < 4; i++)
{
    count = 1;
    nx = x;
    ny = y;
    for (j = 0; j < 4; j++)
    {
        nx += dir_x[i];
        ny += dir_y[i];
        if (b[nx][ny] == who)   
            count++;
        else
            break;
    }
    if (count == 5)
        return 1;
}

return 0;

}

int find(void){
int i, j;

for (i = 0; i < row; i++)
{
    for (j = 0; j < clow; j++)
    {
        if (check(i, j))
            return 1;
    }
}

return 0;

}
void clearboard(void)
{
int i, j;

for (i = 0; i < row; i++)
{
    for (j = 0; j < clow; j++)
    {
    b[row][clow]= 0;
    }
}

}

int main(int argc, char *argv[])
{
int x, y;
int step = 0;
int player = 0;
int choice;

//begin:
while (1)
{
print_board();

player = step % 2 + 1;
printf("player %d : ", player);
scanf("%d%d", &x, &y);

    if (putchess(x, y, player))
    {
        if (find())
        {
            printf("<%d> Win!\n", player);
            printf("1.Quit;2.Continue\n");
            scanf("%d", &choice);
            if (choice == 1)
                break;
            else
            {
                clearboard();
                continue;
            }
        }
        print_board();  
        step++;
    }
    else
        printf("<%d %d> is occupied!\n", x, y);
}

return 0;

}

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
    • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
    • ¥15 绘制多分类任务的roc曲线时只画出了一类的roc,其它的auc显示为nan
    • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
    • ¥20 腾讯企业邮箱邮件可以恢复么
    • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
    • ¥15 错误 LNK2001 无法解析的外部符号
    • ¥50 安装pyaudiokits失败
    • ¥15 计组这些题应该咋做呀
    • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?