回 帖 发 新 帖 刷新版面

主题:我很早以前编的五子棋,供大家参考!

需要一些我自己定义的*.h文件,有兴趣的话我可以贴上来
#include "stdio.h"
#include "conio.h"
#include "stdlib.h"
#include "string.h"
#include "graphics.h"
#include "bioskey.h"
#include "mousea.h"

int oldi,oldj,f=1;
again()
{
    int x,y;
    setlinestyle(0,0,3);
    setfillstyle(1,7);
    bar(100,150,400,300);
    setcolor(15);
    line(100,150,400,150);
    line(100,150,100,300);
    setcolor(4);
    line(100,300,400,300);
    line(400,150,400,300);
    settextstyle(1,0,2);
    outtextxy(170,170,"Play again?");
    outtextxy(170,230,"OK");
    outtextxy(300,230,"NO");
    initmouse();
    showmouse();
    while(1)
    {
        getmousexy(&x,&y);
        if(x>120&&x<240&&y>210&&y<270)
        {
            setcolor(15);
            line(130,210,230,210);
            line(130,210,130,270);
            setcolor(0);
            line(130,270,230,270);
            line(230,210,230,270);
            if(getpressinfo(0)==1)
            {
                    hidemouse();
                    main();
            }
            continue;
        }
        if(x>260&&x<380&&y>210&&y<270)
        {
            setcolor(15);
            line(270,210,370,210);
            line(270,210,270,270);
            setcolor(0);
            line(270,270,370,270);
            line(370,210,370,270);
            if(getpressinfo(0)==1)
            {
                hidemouse();
                closegraph();
            }
            continue;
        }
        if(!(x>120&&x<240&&y>210&&y<270&&x>260&&x<380&&y>210&&y<270))
        {
            setcolor(7);
            line(130,210,230,210);
            line(130,210,130,270);
            line(130,270,230,270);
            line(230,210,230,270);
            line(270,210,370,210);
            line(270,210,270,270);
            line(270,270,370,270);
            line(370,210,370,270);
            if(getpressinfo(0)==1);
            continue;
        }
    }
}
win1(int i)
{
    setcolor(3);
    settextstyle(1,0,4);
    outtextxy(100,10,"Press any key!");
    settextstyle(1,0,6);
    randomize();
    if(i==1)
    {
        while(!bioskey(1))
        {
            setcolor(random(15)+1);
            outtextxy(100,400,"PLAY_1 IS WINNER");
            delay(50);
        }
        again();
    }
    if(i==2)
    {
        while(!bioskey(1))
        {
            setcolor(random(15)+1);
            outtextxy(100,400,"PLAY_2 IS WINNER");
            delay(50);
        }
        again();
    }
}

panduan(int a[16][16],int x,int y,int iflag)
{
    if(a[x][y]==iflag)
        if( (a[x+1][y]==iflag&&a[x+2][y]==iflag&&a[x+3][y]==iflag&&a[x+4][y]==iflag)
          ||(a[x-1][y]==iflag&&a[x+1][y]==iflag&&a[x+2][y]==iflag&&a[x+3][y]==iflag)
          ||(a[x-2][y]==iflag&&a[x-1][y]==iflag&&a[x+1][y]==iflag&&a[x+2][y]==iflag)
          ||(a[x-3][y]==iflag&&a[x-2][y]==iflag&&a[x-1][y]==iflag&&a[x+1][y]==iflag)
          ||(a[x-4][y]==iflag&&a[x-3][y]==iflag&&a[x-2][y]==iflag&&a[x-1][y]==iflag))
            win1(iflag);
        if( (a[x+1][y+1]==iflag&&a[x+2][y+2]==iflag&&a[x+3][y+3]==iflag&&a[x+4][y+4]==iflag)
          ||(a[x-1][y-1]==iflag&&a[x+1][y+1]==iflag&&a[x+2][y+2]==iflag&&a[x+3][y+3]==iflag)
          ||(a[x-2][y-2]==iflag&&a[x-1][y-1]==iflag&&a[x+1][y+1]==iflag&&a[x+2][y+2]==iflag)
          ||(a[x-3][y-3]==iflag&&a[x-2][y-2]==iflag&&a[x-1][y-1]==iflag&&a[x+1][y+1]==iflag)
          ||(a[x-4][y-4]==iflag&&a[x-3][y-3]==iflag&&a[x-2][y-2]==iflag&&a[x-1][y-1]==iflag))
            win1(iflag);
        if( (a[x][y+1]==iflag&&a[x][y+2]==iflag&&a[x][y+3]==iflag&&a[x][y+4]==iflag)
          ||(a[x][y-1]==iflag&&a[x][y+1]==iflag&&a[x][y+2]==iflag&&a[x][y+3]==iflag)
          ||(a[x][y-2]==iflag&&a[x][y-1]==iflag&&a[x][y+1]==iflag&&a[x][y+2]==iflag)
          ||(a[x][y-3]==iflag&&a[x][y-2]==iflag&&a[x][y-1]==iflag&&a[x][y+1]==iflag)
          ||(a[x][y-4]==iflag&&a[x][y-3]==iflag&&a[x][y-2]==iflag&&a[x][y-1]==iflag))
            win1(iflag);
        if( (a[x+1][y-1]==iflag&&a[x+2][y-2]==iflag&&a[x+3][y-3]==iflag&&a[x+4][y-4]==iflag)
          ||(a[x-1][y+1]==iflag&&a[x+1][y-1]==iflag&&a[x+2][y-2]==iflag&&a[x+3][y-3]==iflag)
          ||(a[x-2][y+2]==iflag&&a[x-1][y+1]==iflag&&a[x+1][y-1]==iflag&&a[x+2][y-2]==iflag)
          ||(a[x-3][y+3]==iflag&&a[x-2][y+2]==iflag&&a[x-1][y+1]==iflag&&a[x+1][y-1]==iflag)
          ||(a[x-4][y+4]==iflag&&a[x-3][y+3]==iflag&&a[x-2][y+2]==iflag&&a[x-1][y+1]==iflag))
            win1(iflag);
}

putchess(int a[16][16])
{
    int k,l,x=0,y=0;
    f++;
    for(k=0;k<16;k++)
        for(l=0;l<16;l++)
        {
            if(a[k][l]==1)
            {
                x=k*20;
                y=l*20;
                setlinestyle(0,0,1);
                setcolor(14);
                qizi(x+50,y+50,14);
//                a[k][l]==1;
                oldi=k;
                oldj=l;
//                printf("%d %d",&k,&l);
                panduan(a,k,l,1);
            }
            if(a[k][l]==4)
            {
                x=k*20;
                y=l*20;
                setlinestyle(0,0,1);
                setcolor(4);
                qizi(x+50,y+50,4);
                a[k][l]=2;
                panduan(a,k,l,2);
            }
        }
}

qizi(int x,int y,int i)
{
    circle(x,y,6);
    setfillstyle(1,i-1);
    floodfill(x,y,i);
}

judg4_1(int a[16][16],int newi,int newj,int num1,int num2)
{
            if(a[newi][newj]==num2&&a[newi-1][newj]==num2&&a[newi-2][newj]==num2&&a[newi-3][newj]==num2)
            {
                if(a[newi+1][newj]==0)
                {
                    a[newi+1][newj]=num1;
                    putchess(a);
                    return 5;
                }
                if(a[newi-4][newj]==0)
                {
                    a[newi-4][newj]=num1;
                    putchess(a);
                    return 5;
                }
            }
            if(a[newi][newj]==num2 && a[newi-1][newj]==num2 && a[newi-2][newj]==num2 && a[newi+1][newj]==num2)
            {
                if(a[newi-3][newj]==0)
                {
                    a[newi-3][newj]=num1;
                    putchess(a);
                    return 5;
                }
                if(a[newi+2][newj]==0)
                {
                    a[newi+2][newj]=num1;
                    putchess(a);
                    return 5;
                }
            }
            if(a[newi][newj]==num2 && a[newi-1][newj]==num2 && a[newi+1][newj]==num2 && a[newi+2][newj]==num2)
            {
                if(a[newi-2][newj]==0)
                {
                    a[newi-2][newj]=num1;
                    putchess(a);
                    return 5;
                }
                if(a[newi+3][newj]==0)
                {
                    a[newi+3][newj]=num1;
                    putchess(a);
                    return 5;
                }
            }
            if(a[newi][newj]==num2 && a[newi+1][newj]==num2 && a[newi+2][newj]==num2 && a[newi+3][newj]==num2)
            {
                if(a[newi-1][newj]==0)
                {
                    a[newi-1][newj]=num1;
                    putchess(a);
                    return 5;
                }
                if(a[newi+4][newj]==0)
                {
                    a[newi+4][newj]=num1;
                    putchess(a);
                    return 5;
                }
            }


            if(a[newi-4][newj]==num2&&a[newi-3][newj]==num2&&a[newi-1][newj]==num2&&a[newi][newj]==num2)
            {
                if(a[newi-2][newj]==0)
                {
                    a[newi-2][newj]=num1;
                    putchess(a);
                    return 5;
                }
            }
            if(a[newi-3][newj]==num2&&a[newi-2][newj]==num2&&a[newi+1][newj]==num2&&a[newi][newj]==num2)
            {
                if(a[newi-1][newj]==0)
                {
                    a[newi-1][newj]=num1;
                    putchess(a);
                    return 5;
                }
            }
            if(a[newi-1][newj]==num2&&a[newi][newj]==num2&&a[newi+2][newj]==num2&&a[newi+3][newj]==num2)
            {
                if(a[newi+1][newj]==0)
                {
                    a[newi+1][newj]=num1;
                    putchess(a);
                    return 5;
                }
            }
            if(a[newi][newj]==num2&&a[newi+1][newj]==num2&&a[newi+3][newj]==num2&&a[newi+4][newj]==num2) //8
            {
                if(a[newi+2][newj]==0)
                {
                    a[newi+2][newj]=num1;
                    putchess(a);
                    return 5;
                }
            }
            if(a[newi][newj]==num2&&a[newi-2][newj]==num2&&a[newi-3][newj]==num2&&a[newi-4][newj]==num2)
            {
                if(a[newi-1][newj]==0)
                {
                    a[newi-1][newj]=num1;
                    putchess(a);
                    return 5;
                }
            }
            if(a[newi][newj]==num2&&a[newi-2][newj]==num2&&a[newi+1][newj]==num2&&a[newi+2][newj]==num2)
            {
                if(a[newi-1][newj]==0)
                {
                    a[newi-1][newj]=num1;
                    putchess(a);
                    return 5;
                }
            }
            if(a[newi][newj]==num2&&a[newi+2][newj]==num2&&a[newi+3][newj]==num2&&a[newi+4][newj]==num2)
            {
                if(a[newi+1][newj]==0)
                {
                    a[newi+1][newj]=num1;
                    putchess(a);
                    return 5;
                }
            }
            if(a[newi][newj]==num2&&a[newi-1][newj]==num2&&a[newi-2][newj]==num2&&a[newi+2][newj]==num2)
            {
                if(a[newi+1][newj]==0)
                {
                    a[newi+1][newj]=num1;
                    putchess(a);
                    return 5;
                }
            }

           //heng lian 4

            if(a[newi][newj]==num2 && a[newi-1][newj-1]==num2 && a[newi-2][newj-2]==num2 && a[newi-3][newj-3]==num2)
            {
                if(a[newi+1][newj+1]==0)
                {
                    a[newi+1][newj+1]=num1;
                    putchess(a);
                    return 5;
                }
                if(a[newi-4][newj-4]==0)
                {
                    a[newi-4][newj-4]=num1;
                    putchess(a);
                    return 5;
                }
            }
            if(a[newi][newj]==num2 && a[newi-1][newj-1]==num2 && a[newi-2][newj-2]==num2 && a[newi+1][newj+1]==num2)
            {
                if(a[newi-3][newj-3]==0)
                {
                    a[newi-3][newj-3]=num1;
                    putchess(a);
                    return 5;
                }
                if(a[newi+2][newj+2]==0)
                {
                    a[newi+2][newj+2]=num1;
                    putchess(a);
                    return 5;
                }
            }
            if(a[newi][newj]==num2 && a[newi-1][newj-1]==num2 && a[newi+1][newj+1]==num2 && a[newi+2][newj+2]==num2)
            {
                if(a[newi-2][newj-2]==0)
                {
                    a[newi-2][newj-2]=num1;
                    putchess(a);
                    return 5;
                }
                if(a[newi+3][newj+3]==0)
                {
                    a[newi+3][newj+3]=num1;
                    putchess(a);
                    return 5;
                }
            }
            if(a[newi][newj]==num2 && a[newi+1][newj+1]==num2 && a[newi+2][newj+1]==num2 && a[newi+3][newj+3]==num2)
            {
                if(a[newi-1][newj-1]==0)
                {
                    a[newi-1][newj-1]=num1;
                    putchess(a);
                    return 5;
                }
                if(a[newi+4][newj+4]==0)
                {
                    a[newi+4][newj+4]=num1;
                    putchess(a);
                    return 5;
                }
            }


            if(a[newi-4][newj-4]==num2&&a[newi-3][newj-3]==num2&&a[newi-1][newj-1]==num2&&a[newi][newj]==num2)
            {
                if(a[newi-2][newj-2]==0)
                {
                    a[newi-2][newj-2]=num1;
                    putchess(a);
                    return 5;
                }
            }
            if(a[newi-3][newj-3]==num2&&a[newi-2][newj-2]==num2&&a[newi+1][newj+1]==num2&&a[newi][newj]==num2)
            {
                if(a[newi-1][newj-1]==0)
                {
                    a[newi-1][newj-1]=num1;
                    putchess(a);
                    return 5;
                }
            }
            if(a[newi-1][newj-1]==num2&&a[newi][newj]==num2&&a[newi+2][newj+2]==num2&&a[newi+3][newj+3]==num2)
            {
                if(a[newi+1][newj+1]==0)
                {
                    a[newi+1][newj+1]=num1;
                    putchess(a);
                    return 5;
                }
            }
            if(a[newi][newj]==num2&&a[newi+1][newj+1]==num2&&a[newi+3][newj+3]==num2&&a[newi+4][newj+4]==num2)
            {
                if(a[newi+2][newj+2]==0)
                {
                    a[newi+2][newj+2]=num1;
                    putchess(a);
                    return 5;
                }
            }
            if(a[newi][newj]==num2&&a[newi-2][newj-2]==num2&&a[newi-3][newj-3]==num2&&a[newi-4][newj-4]==num2)
            {
                if(a[newi-1][newj-1]==0)
                {
                    a[newi-1][newj-1]=num1;
                    putchess(a);
                    return 5;
                }
            }
            if(a[newi][newj]==num2&&a[newi-2][newj-2]==num2&&a[newi+1][newj+1]==num2&&a[newi+2][newj+2]==num2)
            {
                if(a[newi-1][newj-1]==0)
                {
                    a[newi-1][newj-1]=num1;
                    putchess(a);
                    return 5;
                }
            }
            if(a[newi][newj]==num2&&a[newi+2][newj+2]==num2&&a[newi+3][newj+3]==num2&&a[newi+4][newj+4]==num2)
            {
                if(a[newi+1][newj+1]==0)
                {
                    a[newi+1][newj+1]=num1;
                    putchess(a);
                    return 5;
                }
            }
            if(a[newi][newj]==num2&&a[newi-1][newj-1]==num2&&a[newi-2][newj-2]==num2&&a[newi+2][newj+2]==num2)
            {
                if(a[newi+1][newj+1]==0)
                {
                    a[newi+1][newj+1]=num1;
                    putchess(a);
                    return 5;
                }
            }

            //you xie lian 4

            if(a[newi][newj]==num2 && a[newi][newj-1]==num2 && a[newi][newj-2]==num2 && a[newi][newj-3]==num2)
            {
                if(a[newi][newj+1]==0)
                {
                    a[newi][newj+1]=num1;
                    putchess(a);
                    return 5;
                }
                if(a[newi][newj-4]==0)
                {
                    a[newi][newj-4]=num1;
                    putchess(a);
                    return 5;
                }
            }
            if(a[newi][newj]==num2 && a[newi][newj-1]==num2 && a[newi][newj-2]==num2 && a[newi][newj+1]==num2)
            {
                if(a[newi][newj-3]==0)
                {
                    a[newi][newj-3]=num1;
                    putchess(a);
                    return 5;
                }
                if(a[newi][newj+2]==0)
                {
                    a[newi][newj+2]=num1;
                    putchess(a);
                    return 5;
                }
            }
            if(a[newi][newj]==num2 && a[newi][newj-1]==num2 && a[newi][newj+1]==num2 && a[newi][newj+2]==num2)
            {
                if(a[newi][newj-2]==0)
                {
                    a[newi][newj-2]=num1;
                    putchess(a);
                    return 5;
                }
                if(a[newi][newj+3]==0)
                {
                    a[newi][newj+3]=num1;
                    putchess(a);
                    return 5;
                }
            }
            if(a[newi][newj]==num2 && a[newi][newj+1]==num2 && a[newi][newj+2]==num2 && a[newi][newj+3]==num2)
            {
                if(a[newi][newj-1]==0)
                {
                    a[newi][newj-1]=num1;
                    putchess(a);
                    return 5;
                }
                if(a[newi][newj+4]==0)
                {
                    a[newi][newj+4]=num1;
                    putchess(a);
                    return 5;
                }
            }


            if(a[newi][newj-4]==num2&&a[newi][newj-3]==num2&&a[newi][newj-1]==num2&&a[newi][newj]==num2)
            {
                if(a[newi][newj-2]==0)
                {
                    a[newi][newj-2]=num1;
                    putchess(a);
                    return 5;
                }
            }
            if(a[newi][newj-3]==num2&&a[newi][newj-2]==num2&&a[newi][newj+1]==num2&&a[newi][newj]==num2)
            {
                if(a[newi][newj-1]==0)
                {
                    a[newi][newj-1]=num1;
                    putchess(a);
                    return 5;
                }
            }
            if(a[newi][newj-1]==num2&&a[newi][newj]==num2&&a[newi][newj+2]==num2&&a[newi][newj+3]==num2)
            {
                if(a[newi][newj+1]==0)
                {
                    a[newi][newj+1]=num1;
                    putchess(a);
                    return 5;
                }
            }
            if(a[newi][newj]==num2&&a[newi][newj+1]==num2&&a[newi][newj+3]==num2&&a[newi][newj+4]==num2)
            {
                if(a[newi][newj+2]==0)
                {
                    a[newi][newj+2]=num1;
                    putchess(a);
                    return 5;
                }
            }
            if(a[newi][newj]==num2&&a[newi][newj-2]==num2&&a[newi][newj-3]==num2&&a[newi][newj-4]==num2)
            {
                if(a[newi][newj-1]==0)
                {
                    a[newi][newj-1]=num1;
                    putchess(a);
                    return 5;
                }
            }
            if(a[newi][newj]==num2&&a[newi][newj-2]==num2&&a[newi][newj+1]==num2&&a[newi][newj+2]==num2)
            {
                if(a[newi][newj-1]==0)
                {
                    a[newi][newj-1]=num1;
                    putchess(a);
                    return 5;
                }
            }
            if(a[newi][newj]==num2&&a[newi][newj+2]==num2&&a[newi][newj+3]==num2&&a[newi][newj+4]==num2)
            {
                if(a[newi][newj+1]==0)
                {
                    a[newi][newj+1]=num1;
                    putchess(a);
                    return 5;
                }
            }
            if(a[newi][newj]==num2&&a[newi][newj-1]==num2&&a[newi][newj-2]==num2&&a[newi][newj+2]==num2)
            {
                if(a[newi][newj+1]==0)
                {
                    a[newi][newj+1]=num1;
                    putchess(a);
                    return 5;
                }
            }

            //shu lian 4


            if(a[newi][newj]==num2 && a[newi-1][newj+1]==num2 && a[newi-2][newj+2]==num2 && a[newi-3][newj+3]==num2)//1
            {
                if(a[newi+1][newj-1]==0)
                {
                    a[newi+1][newj-1]=num1;
                    putchess(a);
                    return 5;
                }
                if(a[newi-4][newj+4]==0)
                {
                    a[newi-4][newj+4]=num1;
                    putchess(a);
                    return 5;
                }
            }
            if(a[newi][newj]==num2 && a[newi-1][newj+1]==num2 && a[newi-2][newj+2]==num2 && a[newi+1][newj-1]==num2)//2
            {
                if(a[newi-3][newj+3]==0)
                {
                    a[newi-3][newj-3]=num1;
                    putchess(a);
                    return 5;
                }
                if(a[newi+2][newj-2]==0)
                {
                    a[newi+2][newj-2]=num1;
                    putchess(a);
                    return 5;
                }
            }
            if(a[newi][newj]==num2 && a[newi-1][newj+1]==num2 && a[newi+1][newj-1]==num2 && a[newi+2][newj-2]==num2)//3
            {
                if(a[newi-2][newj+2]==0)
                {
                    a[newi-2][newj+2]=num1;
                    putchess(a);
                    return 5;
                }
                if(a[newi+3][newj-3]==0)
                {
                    a[newi+3][newj-3]=num1;
                    putchess(a);
                    return 5;
                }
            }
            if(a[newi][newj]==num2 && a[newi+1][newj-1]==num2 && a[newi+2][newj-1]==num2 && a[newi+3][newj-3]==num2)//4
            {
                if(a[newi-1][newj+1]==0)
                {
                    a[newi-1][newj+1]=num1;
                    putchess(a);
                    return 5;
                }
                if(a[newi+4][newj-4]==0)
                {
                    a[newi+4][newj-4]=num1;
                    putchess(a);
                    return 5;
                }
            }


            if(a[newi-4][newj+4]==num2&&a[newi-3][newj+3]==num2&&a[newi-1][newj+1]==num2&&a[newi][newj]==num2)   //5
            {
                if(a[newi-2][newj+2]==0)
                {
                    a[newi-2][newj+2]=num1;
                    putchess(a);
                    return 5;
                }
            }
            if(a[newi-3][newj+3]==num2&&a[newi-2][newj+2]==num2&&a[newi+1][newj-1]==num2&&a[newi][newj]==num2)   //6
            {
                if(a[newi-1][newj+1]==0)
                {
                    a[newi-1][newj+1]=num1;
                    putchess(a);
                    return 5;
                }
            }
            if(a[newi-1][newj+1]==num2&&a[newi][newj]==num2&&a[newi+2][newj-2]==num2&&a[newi+3][newj-3]==num2)//7
            {
                if(a[newi+1][newj-1]==0)
                {
                    a[newi+1][newj-1]=num1;
                    putchess(a);
                    return 5;
                }
            }
            if(a[newi][newj]==num2&&a[newi+1][newj-1]==num2&&a[newi+3][newj-3]==num2&&a[newi+4][newj-4]==num2)//8
            {
                if(a[newi+2][newj-2]==0)
                {
                    a[newi+2][newj-2]=num1;
                    putchess(a);
                    return 5;
                }
            }

            if(a[newi][newj]==num2&&a[newi+2][newj-2]==num2&&a[newi+3][newj-3]==num2&&a[newi+4][newj-4]==num2) //9
            {
                if(a[newi+1][newj-1]==0)
                {
                    a[newi+1][newj-1]=num1;
                    putchess(a);
                    return 5;
                }
            }
            if(a[newi][newj]==num2&&a[newi+2][newj-2]==num2&&a[newi-1][newj+1]==num2&&a[newi-2][newj+2]==num2)  //10
            {
                if(a[newi+1][newj-1]==0)
                {
                    a[newi+1][newj-1]=num1;
                    putchess(a);
                    return 5;
                }
            }
            if(a[newi][newj]==num2&&a[newi-2][newj+2]==num2&&a[newi-3][newj+3]==num2&&a[newi-4][newj+4]==2)   //11
            {
                if(a[newi-1][newj+1]==0)
                {
                    a[newi-1][newj+1]=num1;
                    putchess(a);
                    return 5;
                }
            }
            if(a[newi][newj]==num2&&a[newi+1][newj-1]==num2&&a[newi+2][newj-2]==num2&&a[newi-2][newj+2]==num2) //12
            {
                if(a[newi-1][newj+1]==0)
                {
                    a[newi-1][newj+1]=num1;
                    putchess(a);
                    return 5;
                }
            }
          //zuo xie lian 4


// Yi Shang Lian 4

}
judg3_1(int a[16][16],int newi,int newj,int num1,int num2)
{
    if(a[newi][newj]==num2&&a[newi-2][newj]==num2&&a[newi-3][newj]==num2 && a[newi-4][newj]==0&&a[newi-1][newj]==0&&a[newi+1][newj]==0)
    {
        a[newi-1][newj]=num1;
        putchess(a);
        return 5;
    }
    if(a[newi][newj]==num2&&a[newi-1][newj]==num2&&a[newi-3][newj]==num2 && a[newi-4][newj]==0&&a[newi-2][newj]==0&&a[newi+1][newj]==0)
    {
        a[newi-2][newj]=num1;
        putchess(a);
        return 5;
    }
    if(a[newi][newj]==num2&&a[newi-1][newj]==num2&&a[newi-2][newj]==num2 && a[newi-3][newj]==0&&a[newi+1][newj]==0)
    {
        a[newi-3][newj]=num1;
        putchess(a);
        return 5;
    }
    if(a[newi][newj]==num2 && a[newi-2][newj]==num2 && a[newi+1][newj]==num2 && a[newi-3][newj]==0&&a[newi-1][newj]==0&&a[newi+2][newj]==0)
    {
        a[newi-1][newj]=num1;
        putchess(a);
        return 5;
    }
    if(a[newi][newj]==num2&&a[newi-1][newj]==num2&&a[newi+1][newj]==num2 && a[newi-2][newj]==0&&a[newi+2][newj]==0)
    {
        a[newi-2][newj]=num1;
        putchess(a);
        return 5;
    }
    if(a[newi][newj]==num2&&a[newi-1][newj]==num2&&a[newi+2][newj]==num2 && a[newi-2][newj]==0&&a[newi+1][newj]==0&&a[newi+3][newj]==0)
    {
        a[newi+1][newj]=num1;
        putchess(a);
        return 5;
    }
    if(a[newi][newj]==num2&&a[newi+1][newj]==num2&&a[newi+2][newj]==num2 && a[newi-1][newj]==0&&a[newi+3][newj]==0)
    {
        a[newi-1][newj]=num1;
        putchess(a);
        return 5;
    }
    if(a[newi][newj]==num2&&a[newi+1][newj]==num2&&a[newi+3][newj]==num2 && a[newi-1][newj]==0&&a[newi+2][newj]==0&&a[newi+4][newj]==0)
    {
        a[newi+2][newj]=num1;
        putchess(a);
        return 5;
    }
    if(a[newi][newj]==num2&&a[newi+2][newj]==num2&&a[newi+3][newj]==num2&& a[newi-1][newj]==0&&a[newi+1][newj]==0&&a[newi+4][newj]==0)
    {
        a[newi+1][newj]=num1;
        putchess(a);
        return 5;
    }

            //heng lian 3
    if(a[newi][newj]==num2&&a[newi-2][newj-2]==num2&&a[newi-3][newj-3]==num2 && a[newi-4][newj-4]==0&&a[newi-1][newj-1]==0&&a[newi+1][newj+1]==0)
    {
        a[newi-1][newj-1]=num1;
        putchess(a);
        return 5;
    }
    if(a[newi][newj]==num2&&a[newi-1][newj-1]==num2&&a[newi-3][newj-3]==num2 && a[newi-4][newj-4]==0&&a[newi-2][newj-2]==0&&a[newi+1][newj+1]==0)
    {
        a[newi-2][newj-2]=num1;
        putchess(a);
        return 5;
    }
    if(a[newi][newj]==num2&&a[newi-1][newj-1]==num2&&a[newi-2][newj-2]==num2 && a[newi-3][newj-3]==0&&a[newi+1][newj+1]==0)
    {
        a[newi-3][newj-3]=num1;
        putchess(a);
        return 5;
    }
    if(a[newi][newj]==num2 && a[newi-2][newj-2]==num2 && a[newi+1][newj+1]==num2 && a[newi-3][newj-3]==0&&a[newi-1][newj-1]==0&&a[newi+2][newj+2]==0)
    {
        a[newi-1][newj-1]=num1;
        putchess(a);
        return 5;
    }
    if(a[newi][newj]==num2&&a[newi-1][newj-1]==num2&&a[newi+1][newj+1]==num2 && a[newi-2][newj-2]==0&&a[newi+2][newj+2]==0)
    {
        a[newi-2][newj-2]=num1;
        putchess(a);
        return 5;
    }
    if(a[newi][newj]==num2&&a[newi-1][newj-1]==num2&&a[newi+2][newj+2]==num2 && a[newi-2][newj-2]==0&&a[newi+1][newj+1]==0&&a[newi+3][newj+3]==0)
    {
        a[newi+1][newj+1]=num1;
        putchess(a);
        return 5;
    }
    if(a[newi][newj]==num2&&a[newi+1][newj+1]==num2&&a[newi+2][newj+2]==num2 && a[newi-1][newj-1]==0&&a[newi+3][newj+3]==0)
    {
        a[newi-1][newj-1]=num1;
        putchess(a);
        return 5;
    }
    if(a[newi][newj]==num2&&a[newi+1][newj+1]==num2&&a[newi+3][newj+3]==num2 && a[newi-1][newj-1]==0&&a[newi+2][newj+2]==0&&a[newi+4][newj+4]==0)
    {
        a[newi+2][newj+2]=num1;
        putchess(a);
        return 5;
    }
    if(a[newi][newj]==num2&&a[newi+2][newj+2]==num2&&a[newi+3][newj+3]==num2&& a[newi-1][newj-1]==0&&a[newi+1][newj+1]==0&&a[newi+4][newj+4]==0)
    {
        a[newi+1][newj+1]=num1;
        putchess(a);
        return 5;
    }

            //you xie lian 3
    if(a[newi][newj]==num2&&a[newi][newj-2]==num2&&a[newi][newj-3]==num2 && a[newi][newj-4]==0&&a[newi][newj-1]==0&&a[newi][newj+1]==0)
    {
        a[newi][newj-1]=num1;
        putchess(a);
        return 5;
    }
    if(a[newi][newj]==num2&&a[newi][newj-1]==num2&&a[newi][newj-3]==num2 && a[newi][newj-4]==0&&a[newi][newj-2]==0&&a[newi][newj+1]==0)
    {
        a[newi][newj-2]=num1;
        putchess(a);
        return 5;
    }
    if(a[newi][newj]==num2&&a[newi][newj-1]==num2&&a[newi][newj-2]==num2 && a[newi][newj-3]==0&&a[newi][newj+1]==0)
    {
        a[newi][newj-3]=num1;
        putchess(a);
        return 5;
    }
    if(a[newi][newj]==num2 && a[newi][newj-2]==num2 && a[newi][newj+1]==num2 && a[newi][newj-3]==0&&a[newi][newj-1]==0&&a[newi][newj+2]==0)
    {
        a[newi][newj-1]=num1;
        putchess(a);
        return 5;
    }
    if(a[newi][newj]==num2&&a[newi][newj-1]==num2&&a[newi][newj+1]==num2 && a[newi][newj-2]==0&&a[newi][newj+2]==0)
    {
        a[newi][newj-2]=num1;
        putchess(a);
        return 5;
    }
    if(a[newi][newj]==num2&&a[newi][newj-1]==num2&&a[newi][newj+2]==num2 && a[newi][newj-2]==0&&a[newi][newj+1]==0&&a[newi][newj+3]==0)
    {
        a[newi][newj+1]=num1;
        putchess(a);
        return 5;
    }
    if(a[newi][newj]==num2&&a[newi][newj+1]==num2&&a[newi][newj+2]==num2 && a[newi][newj-1]==0&&a[newi][newj+3]==0)
    {
        a[newi][newj-1]=num1;
        putchess(a);
        return 5;
    }
    if(a[newi][newj]==num2&&a[newi][newj+1]==num2&&a[newi][newj+3]==num2 && a[newi][newj-1]==0&&a[newi][newj+2]==0&&a[newi][newj+4]==0)
    {
        a[newi][newj+2]=num1;
        putchess(a);
        return 5;
    }
    if(a[newi][newj]==num2&&a[newi][newj+2]==num2&&a[newi][newj+3]==num2&& a[newi][newj-1]==0&&a[newi][newj+1]==0&&a[newi][newj+4]==0)
    {
        a[newi][newj+1]=num1;
        putchess(a);
        return 5;
    }

            //shu lian 3
    if(a[newi][newj]==num2&&a[newi+2][newj-2]==num2&&a[newi+3][newj-3]==num2 && a[newi+4][newj-4]==0&&a[newi+1][newj-1]==0&&a[newi-1][newj+1]==0)
    {
        a[newi+1][newj-1]=num1;
        putchess(a);
        return 5;
    }
    if(a[newi][newj]==num2&&a[newi+1][newj-1]==num2&&a[newi+3][newj-3]==num2 && a[newi+4][newj-4]==0&&a[newi+2][newj-2]==0&&a[newi-1][newj+1]==0)
    {
        a[newi+2][newj-2]=num1;
        putchess(a);
        return 5;
    }
    if(a[newi][newj]==num2&&a[newi+1][newj-1]==num2&&a[newi+2][newj-2]==num2 && a[newi+3][newj-3]==0&&a[newi-1][newj+1]==0)
    {
        a[newi+3][newj-3]=num1;
        putchess(a);
        return 5;
    }
    if(a[newi][newj]==num2 && a[newi+2][newj-2]==num2 && a[newi-1][newj+1]==num2 && a[newi+3][newj-3]==0&&a[newi+1][newj-1]==0&&a[newi-2][newj+2]==0)
    {
        a[newi+1][newj-1]=num1;
        putchess(a);
        return 5;
    }
    if(a[newi][newj]==num2&&a[newi+1][newj-1]==num2&&a[newi-1][newj+1]==num2 && a[newi+2][newj-2]==0&&a[newi-2][newj+2]==0)
    {
        a[newi+2][newj-2]=num1;
        putchess(a);
        return 5;
    }
    if(a[newi][newj]==num2&&a[newi+1][newj-1]==num2&&a[newi-2][newj+2]==num2 && a[newi+2][newj-2]==0&&a[newi-1][newj+1]==0&&a[newi-3][newj+3]==0)
    {
        a[newi-1][newj+1]=num1;
        putchess(a);
        return 5;
    }
    if(a[newi][newj]==num2&&a[newi-1][newj+1]==num2&&a[newi-2][newj+2]==num2 && a[newi+1][newj-1]==0&&a[newi-3][newj+3]==0)
    {
        a[newi+1][newj-1]=num1;
        putchess(a);
        return 5;
    }
    if(a[newi][newj]==num2&&a[newi-1][newj+1]==num2&&a[newi-3][newj+3]==num2 && a[newi+1][newj-1]==0&&a[newi-2][newj+2]==0&&a[newi-4][newj+4]==0)
    {
        a[newi-2][newj+2]=num1;
        putchess(a);
        return 5;
    }
    if(a[newi][newj]==num2&&a[newi-2][newj+2]==num2&&a[newi-3][newj+3]==num2&& a[newi+1][newj-1]==0&&a[newi-1][newj+1]==0&&a[newi-4][newj+4]==0)
    {
        a[newi-1][newj+1]=num1;
        putchess(a);
        return 5;
    }
//zuo xie lian 3
// Yi Shang Lian 3 Bidu
}

judg3_2(int a[16][16],int newi,int newj,int num1,int num2)
{
    if(a[newi][newj]==num2&&a[newi-2][newj]==num2&&a[newi-3][newj]==num2 &&a[newi-1][newj]==0)
    {
        if(a[newi-4][newj]==num1&&a[newi+1][newj]==0)
        {
            a[newi+1][newj]=num1;
            putchess(a);
            return 5;
        }
        if(a[newi+1][newj]==num1&&a[newi-4][newj]==0)
        {
            a[newi-4][newj]=num1;
            putchess(a);
            return 5;
        }
    }
    if(a[newi][newj]==num2&&a[newi-1][newj]==num2&&a[newi-3][newj]==num2 &&a[newi-2][newj]==0)
    {
        if(a[newi-4][newj]==num1&&a[newi+1][newj]==0)
        {
            a[newi+1][newj]=num1;
            putchess(a);
            return 5;
        }
        if(a[newi+1][newj]==num1&&a[newi-4][newj]==0)
        {
            a[newi-4][newj]=num1;
            putchess(a);
            return 5;
        }
    }
    if(a[newi][newj]==num2&&a[newi-1][newj]==num2&&a[newi-2][newj]==num2)
    {
        if(a[newi-3][newj]==num1&&a[newi+1][newj]==0)
        {
            a[newi+1][newj]=num1;
            putchess(a);
            return 5;
        }
        if(a[newi+1][newj]==num1&&a[newi-3][newj]==0)
        {
            a[newi-3][newj]=num1;
            putchess(a);
            return 5;
        }
    }
    if(a[newi][newj]==num2 && a[newi-2][newj]==num2 && a[newi+1][newj]==num2 &&a[newi-1][newj] == 0)
    {
        if(a[newi-3][newj]==num1&&a[newi+2][newj]==0)
        {
            a[newi+2][newj]=num1;
            putchess(a);
            return 5;
        }
        if(a[newi+2][newj]==num1&&a[newi-3][newj]==0)
        {
            a[newi-3][newj]=num1;
            putchess(a);
            return 5;
        }
    }
    if(a[newi][newj]==num2&&a[newi-1][newj]==num2&&a[newi+1][newj]==num2)
    {
        if(a[newi-2][newj]==num1&&a[newi+2][newj]==0)
        {
            a[newi+2][newj]=num1;
            putchess(a);
            return 5;
        }
        if(a[newi+2][newj]==num1&&a[newi-2][newj]==0)
        {
            a[newi-2][newj]=num1;
            putchess(a);
            return 5;
        }
    }
    if(a[newi][newj]==num2&&a[newi-1][newj]==num2&&a[newi+2][newj]==num2 &&a[newi+1][newj] == 0)
    {
        if(a[newi-2][newj]==num1&&a[newi+3][newj]==0)
        {
            a[newi+3][newj]=num1;
            putchess(a);
            return 5;
        }
        if(a[newi+3][newj]==num1&&a[newi-2][newj]==0)
        {
            a[newi-2][newj]=num1;
            putchess(a);
            return 5;
        }
    }
    if(a[newi][newj]==num2&&a[newi+1][newj]==num2&&a[newi+2][newj]==num2)
    {
        if(a[newi-1][newj]==num1&&a[newi+3][newj]==0)
        {
            a[newi+3][newj]=num1;
            putchess(a);
            return 5;
        }
        if(a[newi+3][newj]==num1&&a[newi-1][newj]==0)
        {
            a[newi-1][newj]=num1;
            putchess(a);
            return 5;
        }
    }
    if(a[newi][newj]==num2&&a[newi+1][newj]==num2&&a[newi+3][newj]==num2 &&a[newi+2][newj]==0)
    {
        if(a[newi-1][newj]==num1&&a[newi+4][newj]==0)
        {
            a[newi+4][newj]=num1;
            putchess(a);
            return 5;
        }
        if(a[newi+4][newj]==num1&&a[newi-1][newj]==0)
        {
            a[newi-1][newj]=num1;
            putchess(a);
            return 5;
        }
    }
    if(a[newi][newj]==num2&&a[newi+2][newj]==num2&&a[newi+3][newj]==num2 &&a[newi+1][newj]==0)
    {
        if(a[newi-1][newj]==num1&&a[newi+4][newj]==0)
        {
            a[newi+4][newj]=num1;
            putchess(a);
            return 5;
        }
        if(a[newi+4][newj]==num1&&a[newi-1][newj]==0)
        {
            a[newi-1][newj]=num1;
            putchess(a);
            return 5;
        }
    }
//heng lian 3
    if(a[newi][newj]==num2&&a[newi-3][newj-3]==num2&&a[newi-2][newj-2]==num2 &&a[newi-1][newj-1]==0)
    {
        if(a[newi-4][newj-4]==num1&&a[newi+1][newj+1]==0)
        {
            a[newi+1][newj+1]=num1;
            putchess(a);
            return 5;
        }
        if(a[newi+1][newj+1]==num1&&a[newi-4][newj-4]==0)
        {
            a[newi-4][newj-4]=num1;
            putchess(a);
            return 5;
        }
    }
    if(a[newi][newj]==num2&&a[newi-1][newj-1]==num2&&a[newi-3][newj-3]==num2 &&a[newi-2][newj-2]==0)
    {
        if(a[newi-4][newj-4]==num1&&a[newi+1][newj+1]==0)
        {
            a[newi+1][newj+1]=num1;
            putchess(a);
            return 5;
        }
        if(a[newi+1][newj+1]==num1&&a[newi-4][newj-4]==0)
        {
            a[newi-4][newj-4]=num1;
            putchess(a);
            return 5;
        }
    }
    if(a[newi][newj]==num2&&a[newi-1][newj-1]==num2&&a[newi-2][newj-2]==num2)
    {
        if(a[newi-3][newj-3]==num1&&a[newi+1][newj+1]==0)
        {
            a[newi+1][newj+1]=num1;
            putchess(a);
            return 5;
        }
        if(a[newi+1][newj+1]==num1&&a[newi-3][newj-3]==0)
        {
            a[newi-3][newj-3]=num1;
            putchess(a);
            return 5;
        }
    }
    if(a[newi][newj]==num2 && a[newi-2][newj-2]==num2 && a[newi+1][newj+1]==num2&&a[newi-1][newj-1] == 0)
    {
        if(a[newi-3][newj-3]==num1&&a[newi+2][newj+2]==0)
        {
            a[newi+2][newj+2]=num1;
            putchess(a);
            return 5;
        }
        if(a[newi+2][newj+2]==num1&&a[newi-3][newj-3]==0)
        {
            a[newi-3][newj-3]=num1;
            putchess(a);
            return 5;
        }
    }
    if(a[newi][newj]==num2&&a[newi-1][newj-1]==num2&&a[newi+1][newj+1]==num2)
    {
        if(a[newi-2][newj-2]==num1&&a[newi+2][newj+2]==0)
        {
            a[newi+2][newj+2]=num1;
            putchess(a);
            return 5;
        }
        if(a[newi+2][newj+2]==num1&&a[newi-2][newj-2]==0)
        {
            a[newi-2][newj-2]=num1;
            putchess(a);
            return 5;
        }
    }
    if(a[newi][newj]==num2&&a[newi-1][newj-1]==num2&&a[newi+2][newj+2]==num2&&a[newi+1][newj+1]==0)
    {
        if(a[newi-2][newj-2]==num1&&a[newi+3][newj+3]==0)
        {
            a[newi+3][newj+3]=num1;
            putchess(a);
            return 5;
        }
        if(a[newi+3][newj+3]==num1&&a[newi-2][newj-2]==0)
        {
            a[newi-2][newj-2]=num1;
            putchess(a);
            return 5;
        }
    }
    if(a[newi][newj]==num2&&a[newi+1][newj+1]==num2&&a[newi+2][newj+2]==num2)
    {
        if(a[newi-1][newj-1]==num1&&a[newi+3][newj+3]==0)
        {
            a[newi+3][newj+3]=num1;
            putchess(a);
            return 5;
        }
        if(a[newi+3][newj+3]==num1&&a[newi-1][newj-1]==0)
        {
            a[newi-1][newj-1]=num1;
            putchess(a);
            return 5;
        }
    }
    if(a[newi][newj]==num2&&a[newi+1][newj+1]==num2&&a[newi+3][newj+3]==num2&&a[newi+2][newj+2]==0)
    {
        if(a[newi-1][newj-1]==num1&&a[newi+4][newj+4]==0)
        {
            a[newi+4][newj+4]=num1;
            putchess(a);
            return 5;
        }
        if(a[newi+4][newj+4]==num1&&a[newi-1][newj-1]==0)
        {
            a[newi-1][newj-1]=num1;
            putchess(a);
            return 5;
        }
    }
    if(a[newi][newj]==num2&&a[newi+2][newj+2]==num2&&a[newi+3][newj+3]==num2&&a[newi+1][newj+1]==0)
    {
        if(a[newi-1][newj-1]==num1&&a[newi+4][newj+4]==0)
        {
            a[newi+4][newj+4]=num1;
            putchess(a);
            return 5;
        }
        if(a[newi+4][newj+4]==num1&&a[newi-1][newj-1]==0)
        {
            a[newi-1][newj-1]=num1;
            putchess(a);
            return 5;
        }
    }
    //you xie lian 3
    if(a[newi][newj]==num2&&a[newi][newj-3]==num2&&a[newi][newj-2]==num2&&a[newi][newj-1]==0)
    {
        if(a[newi][newj-4]==num1&&a[newi][newj+1]==0)
        {
            a[newi][newj+1]=num1;
            putchess(a);
            return 5;
        }
        if(a[newi][newj+1]==num1&&a[newi][newj-4]==0)
        {
            a[newi][newj-4]=num1;
            putchess(a);
            return 5;
        }
    }
    if(a[newi][newj]==num2&&a[newi][newj-1]==num2&&a[newi][newj-3]==num2&&a[newi][newj-2]==0)
    {
        if(a[newi][newj-4]==num1&&a[newi][newj+1]==0)
        {
            a[newi][newj+1]=num1;
            putchess(a);
            return 5;
        }
        if(a[newi][newj+1]==num1&&a[newi][newj-4]==0)
        {
            a[newi][newj-4]=num1;
            putchess(a);
            return 5;
        }
    }
    if(a[newi][newj]==num2&&a[newi][newj-1]==num2&&a[newi][newj-2]==num2)
    {
        if(a[newi][newj-3]==num1&&a[newi][newj+1]==0)
        {
            a[newi][newj+1]=num1;
            putchess(a);
            return 5;
        }
        if(a[newi][newj+1]==num1&&a[newi][newj-3]==0)
        {
            a[newi][newj-3]=num1;
            putchess(a);
            return 5;
        }
    }
    if(a[newi][newj]==num2 && a[newi][newj-2]==num2 && a[newi][newj+1]==num2&&a[newi][newj-1] == 0)
    {
        if(a[newi][newj-3]==num1&&a[newi][newj+2]==0)
        {
            a[newi][newj+2]=num1;
            putchess(a);
            return 5;
        }
        if(a[newi][newj+2]==num1&&a[newi][newj-3]==0)
        {
            a[newi][newj-3]=num1;
            putchess(a);
            return 5;
        }
    }
    if(a[newi][newj]==num2&&a[newi][newj-1]==num2&&a[newi][newj+1]==num2)
    {
        if(a[newi][newj-2]==num1&&a[newi][newj+2]==0)
        {
            a[newi][newj+2]=num1;
            putchess(a);
            return 5;
        }
        if(a[newi][newj+2]==num1&&a[newi][newj-2]==0)
        {
            a[newi][newj-2]=num1;
            putchess(a);
            return 5;
        }
    }
    if(a[newi][newj]==num2&&a[newi][newj-1]==num2&&a[newi][newj+2]==num2&&a[newi][newj+1]==0)
    {
        if(a[newi][newj-2]==num1&&a[newi][newj+3]==0)
        {
            a[newi][newj+3]=num1;
            putchess(a);
            return 5;
        }
        if(a[newi][newj+3]==num1&&a[newi][newj-2]==0)
        {
            a[newi][newj-2]=num1;
            putchess(a);
            return 5;
        }
    }
    if(a[newi][newj]==num2&&a[newi][newj+1]==num2&&a[newi][newj+2]==num2)
    {
        if(a[newi][newj-1]==num1&&a[newi][newj+3]==0)
        {
            a[newi][newj+3]=num1;
            putchess(a);
            return 5;
        }
        if(a[newi][newj+3]==num1&&a[newi][newj-1]==0)
        {
            a[newi][newj-1]=num1;
            putchess(a);
            return 5;
        }
    }
    if(a[newi][newj]==num2&&a[newi][newj+1]==num2&&a[newi][newj+3]==num2&&a[newi][newj+2]==0)
    {
        if(a[newi][newj-1]==num1&&a[newi][newj+4]==0)
        {
            a[newi][newj+4]=num1;
            putchess(a);
            return 5;
        }
        if(a[newi][newj+4]==num1&&a[newi][newj-1]==0)
        {
            a[newi][newj-1]=num1;
            putchess(a);
            return 5;
        }
    }
    if(a[newi][newj]==num2&&a[newi][newj+2]==num2&&a[newi][newj+3]==num2&&a[newi][newj+1]==0)
    {
        if(a[newi][newj-1]==num1&&a[newi][newj+4]==0)
        {
            a[newi][newj+4]=num1;
            putchess(a);
            return 5;
        }
        if(a[newi][newj+4]==num1&&a[newi][newj-1]==0)
        {
            a[newi][newj-1]=num1;
            putchess(a);
            return 5;
        }
    }
    //shu lian 3
    if(a[newi][newj]==num2&&a[newi-3][newj+3]==num2&&a[newi-2][newj+2]==num2&&a[newi-1][newj+1]==0)
    {
        if(a[newi-4][newj+4]==num1&&a[newi+1][newj-1]==0)
        {
            a[newi+1][newj-1]=num1;
            putchess(a);
            return 5;
        }
        if(a[newi+1][newj-1]==num1&&a[newi-4][newj+4]==0)
        {
            a[newi-4][newj+4]=num1;
            putchess(a);
            return 5;
        }
    }
    if(a[newi][newj]==num2&&a[newi-1][newj+1]==num2&&a[newi-3][newj+3]==num2&&a[newi-2][newj+2]==0)
    {
        if(a[newi-4][newj+4]==num1&&a[newi+1][newj-1]==0)
        {
            a[newi+1][newj-1]=num1;
            putchess(a);
            return 5;
        }
        if(a[newi+1][newj-1]==num1&&a[newi-4][newj+4]==0)
        {
            a[newi-4][newj+4]=num1;
            putchess(a);
            return 5;
        }
    }
    if(a[newi][newj]==num2&&a[newi-1][newj+1]==num2&&a[newi-2][newj+2]==num2)
    {
        if(a[newi-3][newj+3]==num1&&a[newi+1][newj-1]==0)
        {
            a[newi+1][newj-1]=num1;
            putchess(a);
            return 5;
        }
        if(a[newi+1][newj-1]==num1&&a[newi-3][newj+3]==0)
        {
            a[newi-3][newj+3]=num1;
            putchess(a);
            return 5;
        }
    }
    if(a[newi][newj]==num2 && a[newi-2][newj+2]==num2 && a[newi+1][newj-1]==num2&&a[newi-1][newj+1] == 0)
    {
        if(a[newi-3][newj+3]==num1&&a[newi+2][newj-2]==0)
        {
            a[newi+2][newj-2]=num1;
            putchess(a);
            return 5;
        }
        if(a[newi+2][newj-2]==num1&&a[newi-3][newj+3]==0)
        {
            a[newi-3][newj+3]=num1;
            putchess(a);
            return 5;
        }
    }
    if(a[newi][newj]==num2&&a[newi-1][newj+1]==num2&&a[newi+1][newj-1]==num2)
    {
        if(a[newi-2][newj+2]==num1&&a[newi+2][newj-2]==0)
        {
            a[newi+2][newj-2]=num1;
            putchess(a);
            return 5;
        }
        if(a[newi+2][newj-2]==num1&&a[newi-2][newj+2]==0)
        {
            a[newi-2][newj+2]=num1;
            putchess(a);
            return 5;
        }
    }
    if(a[newi][newj]==num2&&a[newi-1][newj+1]==num2&&a[newi+2][newj-2]==num2&&a[newi+1][newj-1]==0)
    {
        if(a[newi-2][newj+2]==num1&&a[newi+3][newj-3]==0)
        {
            a[newi+3][newj-3]=num1;
            putchess(a);
            return 5;
        }
        if(a[newi+3][newj-3]==num1&&a[newi-2][newj+2]==0)
        {
            a[newi-2][newj+2]=num1;
            putchess(a);
            return 5;
        }
    }
    if(a[newi][newj]==num2&&a[newi+1][newj-1]==num2&&a[newi+2][newj-2]==num2)
    {
        if(a[newi-1][newj+1]==num1&&a[newi+3][newj-3]==0)
        {
            a[newi+3][newj-3]=num1;
            putchess(a);
            return 5;
        }
        if(a[newi+3][newj-3]==num1&&a[newi-1][newj+1]==0)
        {
            a[newi-1][newj+1]=num1;
            putchess(a);
            return 5;
        }
    }
    if(a[newi][newj]==num2&&a[newi+1][newj-1]==num2&&a[newi+3][newj-3]==num2&&a[newi+2][newj-2]==0)
    {
        if(a[newi-1][newj+1]==num1&&a[newi+4][newj-4]==0)
        {
            a[newi+4][newj-4]=num1;
            putchess(a);
            return 5;
        }
        if(a[newi+4][newj-4]==num1&&a[newi-1][newj+1]==0)
        {
            a[newi-1][newj+1]=num1;
            putchess(a);
            return 5;
        }
    }
    if(a[newi][newj]==num2&&a[newi+2][newj-2]==num2&&a[newi+3][newj-3]==num2&&a[newi+1][newj-1]==0)
    {
        if(a[newi-1][newj+1]==num1&&a[newi+4][newj-4]==0)
        {
            a[newi+4][newj-4]=num1;
            putchess(a);
            return 5;
        }
        if(a[newi+4][newj-4]==num1&&a[newi-1][newj+1]==0)
        {
            a[newi-1][newj+1]=num1;
            putchess(a);
            return 5;
        }
    }
//zuo xie lian 3
/* Yi Shang Lian 3 */
}
judg2_1(int a[16][16],int newi,int newj,int num1,int num2)
{
    if(a[newi][newj]==num2&&a[newi-1][newj]==num2 &&a[newi-2][newj]==0&&a[newi+1][newj]==0)
    {
        if(random(1)==0)
        {
            a[newi+1][newj]=num1;
            putchess(a);
            return 5;
        }
        if(random(1)==1)
        {
            a[newi-2][newj]=num1;
            putchess(a);
            return 5;
        }
    }
    if(a[newi][newj]==num2&&a[newi+1][newj]==num2 &&a[newi-1][newj]==0&&a[newi+2][newj]==0)
    {
        if(random(1)==0)
        {
            a[newi+2][newj]=num1;
            putchess(a);
            return 5;
        }
        if(random(1)==1)
        {
            a[newi-1][newj]=num1;
            putchess(a);
            return 5;
        }
    }
    if(a[newi][newj]==num2&&a[newi-2][newj]==num2 &&a[newi-3][newj]==0&&a[newi-1][newj]==0&&a[newi+1][newj]==0)
    {
        a[newi-1][newj]=num1;
        putchess(a);
        return 5;
    }
    if(a[newi][newj]==num2&&a[newi+2][newj]==num2 &&a[newi-1][newj]==0&&a[newi+1][newj]==0&&a[newi+3][newj]==0)
    {
        a[newi+1][newj]=num1;
        putchess(a);
        return 5;
    }
//hen 2
    if(a[newi][newj]==num2&&a[newi-1][newj-1]==num2 &&a[newi-2][newj-2]==0&&a[newi+1][newj+1]==0)
    {
        if(random(1)==0)
        {
            a[newi+1][newj+1]=num1;
            putchess(a);
            return 5;
        }
        if(random(1)==1)
        {
            a[newi-2][newj-2]=num1;
            putchess(a);
            return 5;
        }
    }
    if(a[newi][newj]==num2&&a[newi+1][newj+1]==num2 &&a[newi-1][newj-1]==0&&a[newi+2][newj+2]==0)
    {
        if(random(1)==0)
        {
            a[newi+2][newj+2]=num1;
            putchess(a);
            return 5;
        }
        if(random(1)==1)
        {
            a[newi-1][newj-1]=num1;
            putchess(a);
            return 5;
        }
    }
    if(a[newi][newj]==num2&&a[newi-2][newj-2]==num2 &&a[newi-3][newj-3]==0&&a[newi-1][newj-1]==0&&a[newi+1][newj+1]==0)
    {
        a[newi-1][newj-1]=num1;
        putchess(a);
        return 5;
    }
    if(a[newi][newj]==num2&&a[newi+2][newj+2]==num2 &&a[newi-1][newj-1]==0&&a[newi+1][newj+1]==0&&a[newi+3][newj+3]==0)
    {
        a[newi+1][newj+1]=num1;
        putchess(a);
        return 5;
    }
//you xie 2

    if(a[newi][newj]==num2&&a[newi][newj-1]==num2 &&a[newi][newj-2]==0&&a[newi][newj+1]==0)
    {
        if(random(1)==0)
        {
            a[newi][newj+1]=num1;
            putchess(a);
            return 5;
        }
        if(random(1)==1)
        {
            a[newi][newj-2]=num1;
            putchess(a);
            return 5;
        }
    }
    if(a[newi][newj]==num2&&a[newi][newj+1]==num2 &&a[newi][newj-1]==0&&a[newi][newj+2]==0)
    {
        if(random(1)==0)
        {
            a[newi][newj+2]=num1;
            putchess(a);
            return 5;
        }
        if(random(1)==1)
        {
            a[newi][newj-1]=num1;
            putchess(a);
            return 5;
        }
    }
    if(a[newi][newj]==num2&&a[newi][newj-2]==num2 &&a[newi][newj-3]==0&&a[newi][newj-1]==0&&a[newi][newj+1]==0)
    {
        a[newi][newj-1]=num1;
        putchess(a);
        return 5;
    }
    if(a[newi][newj]==num2&&a[newi][newj+2]==num2 &&a[newi][newj-1]==0&&a[newi][newj+1]==0&&a[newi][newj+3]==0)
    {
        a[newi+1][newj+1]=num1;
        putchess(a);
        return 5;
    }
//shu 2

    if(a[newi][newj]==num2&&a[newi+1][newj-1]==num2 &&a[newi+2][newj-2]==0&&a[newi-1][newj+1]==0)
    {
        if(random(1)==0)
        {
            a[newi-1][newj+1]=num1;
            putchess(a);
            return 5;
        }
        if(random(1)==1)
        {
            a[newi+2][newj-2]=num1;
            putchess(a);
            return 5;
        }
    }
    if(a[newi][newj]==num2&&a[newi-1][newj+1]==num2 &&a[newi+1][newj-1]==0&&a[newi-2][newj+2]==0)
    {
        if(random(1)==0)
        {
            a[newi-2][newj+2]=num1;
            putchess(a);
            return 5;
        }
        if(random(1)==1)
        {
            a[newi+1][newj-1]=num1;
            putchess(a);
            return 5;
        }
    }
    if(a[newi][newj]==num2&&a[newi+2][newj-2]==num2 &&a[newi+3][newj-3]==0&&a[newi+1][newj-1]==0&&a[newi-1][newj+1]==0)
    {
        a[newi+1][newj-1]=num1;
        putchess(a);
        return 5;
    }
    if(a[newi][newj]==num2&&a[newi-2][newj+2]==num2 &&a[newi+1][newj-1]==0&&a[newi-1][newj+1]==0&&a[newi-3][newj+3]==0)
    {
        a[newi-1][newj+1]=num1;
        putchess(a);
        return 5;
    }
//zuo xie 2
}
judg2_2(int a[16][16],int newi,int newj,int num1,int num2)
{
    if(a[newi][newj]==num2&&a[newi-1][newj]==num2)
    {
        if(a[newi+1][newj]==0)
        {
            a[newi+1][newj]=num1;
            putchess(a);
            return 5;
        }
        if(a[newi-2][newj]==0)
        {
            a[newi-2][newj]=num1;
            putchess(a);
            return 5;
        }
    }
    if(a[newi][newj]==num2&&a[newi+1][newj]==num2)
    {
        if(a[newi+2][newj]==0)
        {
            a[newi+2][newj]=num1;
            putchess(a);
            return 5;
        }
        if(a[newi+2][newj]==0)
        {
            a[newi-1][newj]=num1;
            putchess(a);
            return 5;
        }
    }
    if(a[newi][newj]==num2&&a[newi-2][newj]==num2)
        if(a[newi-1][newj]==0)
        {
            a[newi-1][newj]=num1;
            putchess(a);
            return 5;
        }
    if(a[newi][newj]==num2&&a[newi+2][newj]==num2)
        if(a[newi+1][newj]==0)
        {
            a[newi+1][newj]=num1;
            putchess(a);
            return 5;
        }

    if(a[newi][newj]==num2&&a[newi-1][newj-1]==num2)
    {
        if(a[newi+1][newj+1]==0)
        {
            a[newi+1][newj+1]=num1;
            putchess(a);
            return 5;
        }
        if(a[newi-2][newj-2]==0)
        {
            a[newi-2][newj-2]=num1;
            putchess(a);
            return 5;
        }
    }
    if(a[newi][newj]==num2&&a[newi+1][newj+1]==num2)
    {
        if(a[newi+2][newj+2]==0)
        {
            a[newi+2][newj+2]=num1;
            putchess(a);
            return 5;
        }
        if(a[newi-1][newj-1]==0)
        {
            a[newi-1][newj-1]=num1;
            putchess(a);
            return 5;
        }
    }
    if(a[newi][newj]==num2&&a[newi-2][newj-2]==num2)
        if(a[newi-1][newj-1]==0)
        {
            a[newi-1][newj-1]=num1;
            putchess(a);
            return 5;
        }
    if(a[newi][newj]==num2&&a[newi+2][newj+2]==num2)
        if(a[newi+1][newj+1]==0)
        {
            a[newi+1][newj+1]=num1;
            putchess(a);
            return 5;
        }

    if(a[newi][newj]==num2&&a[newi][newj-1]==num2)
    {
        if(a[newi][newj+1]==0)
        {
            a[newi][newj+1]=num1;
            putchess(a);
            return 5;
        }
        if(a[newi][newj-2]==0)
        {
            a[newi][newj-2]=num1;
            putchess(a);
            return 5;
        }
    }
    if(a[newi][newj]==num2&&a[newi][newj+1]==num2)
    {
        if(a[newi][newj+2]==0)
        {
            a[newi][newj+2]=num1;
            putchess(a);
            return 5;
        }
        if(a[newi][newj-1]==0)
        {
            a[newi][newj-1]=num1;
            putchess(a);
            return 5;
        }
    }
    if(a[newi][newj]==num2&&a[newi][newj-2]==num2)
        if(a[newi][newj-1]==0)
        {
            a[newi][newj-1]=num1;
            putchess(a);
            return 5;
        }
    if(a[newi][newj]==num2&&a[newi][newj+2]==num2)
        if(a[newi][newj+1]==0)
        {
            a[newi][newj+1]=num1;
            putchess(a);
            return 5;
        }

    if(a[newi][newj]==num2&&a[newi-1][newj+1]==num2)
    {
        if(a[newi+1][newj-1]==0)
        {
            a[newi+1][newj-1]=num1;
            putchess(a);
            return 5;
        }
        if(a[newi-2][newj+2]==0)
        {
            a[newi-2][newj+2]=num1;
            putchess(a);
            return 5;
        }
    }
    if(a[newi][newj]==num2&&a[newi+1][newj-1]==num2)
    {
        if(a[newi+2][newj-2]==0)
        {
            a[newi+2][newj-2]=num1;
            putchess(a);
            return 5;
        }
        if(a[newi-1][newj+1]==0)
        {
            a[newi-1][newj+1]=num1;
            putchess(a);
            return 5;
        }
    if(a[newi][newj]==num2&&a[newi+2][newj-2]==num2)
        if(a[newi+1][newj-1]==0)
        {
            a[newi+1][newj-1]=num1;
            putchess(a);
            return 5;
        }
    if(a[newi][newj]==num2&&a[newi-2][newj+2]==num2)
        if(a[newi-1][newj+1]==0)
        {
            a[newi-1][newj+1]=num1;
            putchess(a);
            return 5;
        }

    }
}

judg1_1(int a[16][16],int newi,int newj,int num1,int num2)
{
    if(a[newi][newj]==num2)
    {
        if(random(7)==0&&a[newi][newj-1]==0)
        {
            a[newi][newj-1]=num1;
            putchess(a);
            return 5;
        }
        if(random(7)==1&&a[newi][newj+1]==0)
        {
            a[newi][newj+1]=num1;
            putchess(a);
            return 5;
        }
        if(random(7)==2&&a[newi-1][newj]==0)
        {
            a[newi-1][newj]=num1;
            putchess(a);
            return 5;
        }
        if(random(7)==3&&a[newi+1][newj]==0)
        {
            a[newi+1][newj]=num1;
            putchess(a);
            return 5;
        }
        if(random(7)==4&&a[newi-1][newj-1]==0)
        {
            a[newi-1][newj-1]=num1;
            putchess(a);
            return 5;
        }
        if(random(7)==5&&a[newi+1][newj+1]==0)
        {
            a[newi+1][newj+1]=num1;
            putchess(a);
            return 5;
        }
        if(random(7)==6&&a[newi+1][newj-1]==0)
        {
            a[newi+1][newj-1]=num1;
            putchess(a);
            return 5;
        }
        if(random(7)==7&&a[newi-1][newj+1]==0)
        {
            a[newi-1][newj+1]=num1;
            putchess(a);
            return 5;
        }
    }
}

int comp_4_1put(int a[16][16])
{
    int i,j;
    for(i=4;i<=11;i++)
        for(j=4;j<=11;j++)
            if(judg4_1(a,i,j,1,1)==5)
                return 6;
}
int user_4_1put(int a[16][16])
{
    int i,j;
    for(i=4;i<=11;i++)
        for(j=4;j<=11;j++)
            if(judg4_1(a,i,j,1,2)==5)
                return 6;
}
int comp_3_1put(int a[16][16])
{
    int i,j;
    for(i=4;i<=11;i++)
        for(j=4;j<=11;j++)
            if(judg3_1(a,i,j,1,1)==5)
                return 6;
}
int user_3_1put(int a[16][16])
{
    int i,j;
    for(i=4;i<=11;i++)
        for(j=4;j<=11;j++)
            if(judg3_1(a,i,j,1,2)==5)
                return 6;
}
int comp_3_2put(int a[16][16])
{
    int i,j;
    for(i=4;i<=11;i++)
        for(j=4;j<=11;j++)
            if(judg3_2(a,i,j,1,1)==5)
                return 6;
}
int user_3_2put(int a[16][16])
{
    int i,j;
    for(i=4;i<=11;i++)
        for(j=4;j<=11;j++)
            if(judg3_2(a,i,j,1,2)==5)
                return 6;
}

int comp_2_1put(int a[16][16])
{
    int i,j;
    for(i=4;i<=11;i++)
        for(j=4;j<=11;j++)
            if(judg2_1(a,i,j,1,1)==5)
                return 6;
}
int user_2_1put(int a[16][16])
{
    int i,j;
    for(i=4;i<=11;i++)
        for(j=4;j<=11;j++)
            if(judg2_1(a,i,j,1,2)==5)
                return 6;
}
int comp_2_2put(int a[16][16])
{
    int i,j;
    for(i=4;i<=11;i++)
        for(j=4;j<=11;j++)
            if(judg2_2(a,i,j,1,1)==5)
                return 6;
}
int user_2_2put(int a[16][16])
{
    int i,j;
    for(i=4;i<=11;i++)
        for(j=4;j<=11;j++)
            if(judg2_2(a,i,j,1,2)==5)
                return 6;
}
int comp_1_1put(int a[16][16])
{
    int i,j;
    for(i=4;i<=11;i++)
        for(j=4;j<=11;j++)
            if(judg1_1(a,i,j,1,1)==5)
                return 6;
}
int user_1_1put(int a[16][16])
{
    int i,j;
    for(i=4;i<=11;i++)
        for(j=4;j<=11;j++)
            if(judg1_1(a,i,j,1,2)==5)
                return 6;
}

chesstable()
{
    int i,j;
    setlinestyle(0,0,0);
    setcolor(2);
    for(i=0;i<=15;i++)
        for(j=0;j<=15;j++)
            rectangle(50+i*20,50+j*20,i*20+70,j*20+70);
}

main(void)
{
    int i = 0,j = 0, k, l, m, n, x = 0, y = 0;
    int weii, weij;
    int a[16][16], b[16][16];
    int gd=0, gm;
    for(k = 0; k < 16; k++)
        for(l = 0; l < 16; l++)
            a[k][l]=0;

    initgraph(&gd, &gm, "f:\\shiter\\tc\\");
    setbkcolor(0);
    chesstable();

    gotoxy(55, 4);    printf("PLAY_1       ");
    gotoxy(60, 5);    printf("E     -- 上  ");
    gotoxy(60, 7);    printf("D     -- 下  ");
    gotoxy(60, 9);    printf("S     -- 左  ");
    gotoxy(60, 11);    printf("F     -- 右  ");
    gotoxy(60, 13);    printf("SPACE --确定 ");
    gotoxy(55, 15);    printf("PLAY_2       ");
    gotoxy(60, 16);    printf("UP    -- 上  ");
    gotoxy(60, 18);    printf("DOWN  -- 下  ");
    gotoxy(60, 20);    printf("LEFT  -- 左  ");
    gotoxy(60, 22);    printf("RIGHT -- 右  ");
    gotoxy(60, 24);    printf("DEL   -- 确定");

    while(1)
    {
//        setlinestyle(0, 0, 3);
//        line(x + 50 - 8, y + 58, x + 58, y + 58);
        if(f%2==0)
        {
            if(comp_4_1put(a)==6)
                continue;
            if(user_4_1put(a)==6)
                continue;
            if(comp_3_1put(a)==6)
                continue;
            if(user_3_1put(a)==6)
                continue;
            if(comp_3_2put(a)==6)
                continue;
            if(comp_2_1put(a)==6)
                continue;
            if(user_3_2put(a)==6)
                continue;
            if(comp_1_1put(a)==6)
                continue;
            if(user_2_1put(a)==6)
                continue;
            if(user_1_1put(a)==6)
                continue;
            f++;
        }
        else
        {
            while(bioskey(1)!=0)
            {
                i=x/20;
                j=y/20;
                switch(bioskey(0))
                {
                    case KEY_UP:    setlinestyle(0,0,3);
                            setcolor(0);
                            line(x+42,y+58,x+58,y+58);
                            setcolor(2);
                            setlinestyle(0,0,0);
                            line(x+50,y+57,x+50,y+59);
                            y-=20;
                            if(y<0)
                                y=0;
                            setlinestyle(0,0,3);
                            line(x+42,y+58,x+58,y+58);
                            break;
                    case KEY_DOWN:  setlinestyle(0,0,3);
                            setcolor(0);
                            line(x+42,y+58,x+58,y+58);
                            setcolor(2);
                            setlinestyle(0,0,0);
                            line(x+50,y+57,x+50,y+59);
                            y+=20;
                            if(y>300)
                                y=300;
                            setlinestyle(0,0,3);
                            line(x+42,y+58,x+58,y+58);
                            break;
                    case KEY_LEFT:  setlinestyle(0,0,3);
                            setcolor(0);
                            line(x+42,y+58,x+58,y+58);
                            setcolor(2);
                            setlinestyle(0,0,0);
                            line(x+50,y+57,x+50,y+59);
                            x-=20;
                            if(x<0)
                                x=0;
                            setlinestyle(0,0,3);
                            line(x+42,y+58,x+58,y+58);
                            break;
                    case KEY_RIGHT: setlinestyle(0,0,3);
                            setcolor(0);
                            line(x+42,y+58,x+58,y+58);
                            setcolor(2);
                            setlinestyle(0,0,0);
                            line(x+50,y+57,x+50,y+59);
                            x+=20;
                            if(x>320)
                                x=320;
                            setlinestyle(0,0,3);
                            line(x+42,y+58,x+58,y+58);
                            break;
                    case KEY_SPACE:if(a[i][j]==0)
                            {
                                a[i][j]=4;
                                setlinestyle(0,0,3);
                                setcolor(0);
                                line(x+42,y+58,x+58,y+58);
                                putchess(a);
                                continue;
                            }
                            continue;
                    case KEY_ESC:      again();
                    line(x+42,y+58,x+58,y+58);
                }
            }
        }
    }
    getch();
}

回复列表 (共51个回复)

31 楼

楼主兄弟:
你好,很高兴能看到你的贴,我最近也想用C语言编写五子棋程序,刚好能借鉴一下,向你学习了,敬礼!
多年前我学过FOXBASE(我是学会计的),就只有这一点基础了,我想用三个月时间,每天大概3小时,然后用C语言编出简单的五子棋(无禁的)程序,楼主兄弟你认为可行吗?最近二个月因为我迷上了下五子棋,把业余时间全误了,老婆就生气了[em6],说我要好好学点东西,不然哼哼……,于是我就想到用C语言编写五子棋程序,这样又学到C语言又能结合自己的兴趣,一举二得,哈哈……
我在联众和中国游戏中心都有一个号,名字和这的都一样name_liantian,联众的有3151分,胜率只有50%,中游的是业余七段1164分,胜率也只是60%,五子棋水平在这二个网站都算很一般的,有兴趣的五子棋网友,可以互相切磋学习一下。五子棋本身有很多规则,比如黑有禁手,三手可换,五手二打,不知楼主兄弟有没有编在程序里(对不起我现在还看不懂你的程序)。
最后有一个请求:能不能把编译后的程序也发一份给我,谢谢,主要是学习一下,我也想编,如果你有空的话,请发到我的邮箱ltdnpx@tom.com,再次感谢!祝楼主兄弟天天开心,[em3]OK!

32 楼

对了,哪位网友有楼主编译后的程序,请你有空发一份给我,ltdnpx@tom.com,我怕楼主万一没空,我在这里先谢谢了。

33 楼

兄弟有空也给我一份,谢谢了!(原程序及头文件)谢了!
heisini@126.com[em1][em1][em1][em1][em1][em1]

34 楼

各位大哥,小妹急需一个用c++编译的五子棋程序。那位有的话,可以发给我吗??多谢啦。。jiali0527.student@sina.com 不胜感激!!!

35 楼

请问一下楼主,在TC里面运行时,出现 out of space 是啥意思啊?
  出现了这个问题以后,就不让人动程序了啊。
  真是急死人了。


  我这里还有一个五子棋的程序,是《C3.0速成》里的,一样的不能运行。
  我把它贴出来,兄弟们谁能改的就改一下吧。

36 楼

/**********************************************************/
/*      本程序在Turbo C或Borland C下编译通过              */
/*      源程序在光盘 \source\ 目录下                      */
/*      文件名: afive.c                                   */
/**********************************************************/

/**********************************************************/
/* 程序中用到的库函数所在头文件应用 #include 命令包含进来 */

#include <stdio.h>
#include <bios.h>
#include <ctype.h>
#include <conio.h>
#include <dos.h>

/**********************************************************/
/* 定义符号常量                                           */

/*定义画棋盘所需的制表符*/
#define CROSSRU     0xbf  /*右上角点*/
#define CROSSLU     0xda  /*左上角点*/
#define CROSSLD     0xc0  /*左下角点*/
#define CROSSRD     0xd9  /*右下角点*/
#define CROSSL      0xc3  /*左边*/
#define CROSSR      0xb4  /*右边*/
#define CROSSU      0xc2  /*上边*/
#define CROSSD      0xc1  /*下边*/
#define CROSS       0xc5  /*十字交叉点*/

/*定义棋盘左上角点在屏幕上的位置*/
#define MAPXOFT     5
#define MAPYOFT     2

/*定义1号玩家的操作键键码*/
#define PLAY1UP     0x1157/*上移--'W'*/
#define PLAY1DOWN   0x1f53/*下移--'S'*/
#define PLAY1LEFT   0x1e41/*左移--'A'*/
#define PLAY1RIGHT  0x2044/*右移--'D'*/
#define PLAY1DO     0x3920/*落子--空格键*/

/*定义2号玩家的操作键键码*/
#define PLAY2UP     0x4800/*上移--方向键up*/
#define PLAY2DOWN   0x5000/*下移--方向键down*/
#define PLAY2LEFT   0x4b00/*左移--方向键left*/
#define PLAY2RIGHT  0x4d00/*右移--方向键right*/
#define PLAY2DO     0x1c0d/*落子--回车键Enter*/

/*若想在游戏中途退出, 可按 Esc 键*/
#define ESCAPE      0x011b

/*定义棋盘上交叉点的状态, 即该点有无棋子 */
/*若有棋子, 还应能指出是哪个玩家的棋子   */
#define CHESSNULL   0  //没有棋子
#define CHESS1      'O'//一号玩家的棋子
#define CHESS2      'X'//二号玩家的棋子

/*定义按键类别*/
#define KEYEXIT        0/*退出键*/
#define KEYFALLCHESS   1/*落子键*/
#define KEYMOVECURSOR  2/*光标移动键*/
#define KEYINVALID     3/*无效键*/

/*定义符号常量: 真, 假 --- 真为1, 假为0 */
#define TRUE        1
#define FALSE       0

/**********************************************************/
/* 定义数据结构                                           */

/*棋盘交叉点坐标的数据结构*/
struct point
{
   int x,y;
};

/**********************************************************/
/*自定义函数原型说明                                      */
void Init(void);
int  GetKey(void);
int CheckKey(int press);
int  ChangeOrder(void);
int  ChessGo(int Order,struct point Cursor);
void DoError(void);
void DoOK(void);
void DoWin(int Order);
void MoveCursor(int Order,int press);
void DrawCross(int x,int y);
void DrawMap(void);
int  JudgeWin(int Order,struct point Cursor);
int  JudgeWinLine(int Order,struct point Cursor,int direction);
void ShowOrderMsg(int Order);
void EndGame(void);
/**********************************************************/

/**********************************************************/
/* 定义全局变量                                           */
int  gPlayOrder;         /*指示当前行棋方          */
struct point gCursor;    /*光标在棋盘上的位置      */
char gChessBoard[19][19];/*用于记录棋盘上各点的状态*/
/**********************************************************/

/**********************************************************/
/*主函数*/
void main()
{
  int press;
  int bOutWhile=FALSE;/*退出循环标志*/

  Init();/*初始化图象,数据*/

  while(1)
  {
    press=GetKey();/*获取用户的按键值*/
    switch(CheckKey(press))/*判断按键类别*/
    {
    /*是退出键*/
    case KEYEXIT:
      clrscr();/*清屏*/
      bOutWhile = TRUE;
      break;

    /*是落子键*/
    case KEYFALLCHESS:
      if(ChessGo(gPlayOrder,gCursor)==FALSE)/*走棋*/
        DoError();/*落子错误*/
      else
      {
        DoOK();/*落子正确*/

        /*如果当前行棋方赢棋*/
        if(JudgeWin(gPlayOrder,gCursor)==TRUE)
        {
          DoWin(gPlayOrder);
          bOutWhile = TRUE;/*退出循环标志置为真*/
        }
        /*否则*/
        else
          /*交换行棋方*/
          ChangeOrder();
      }
      break;

    /*是光标移动键*/
    case KEYMOVECURSOR:
      MoveCursor(gPlayOrder,press);
      break;

    /*是无效键*/
    case KEYINVALID:
      break;
    }

    if(bOutWhile==TRUE)
      break;
  }

  /*游戏结束*/
  EndGame();
}
/**********************************************************/

/*界面初始化,数据初始化*/
void Init(void)
{
  int i,j;
  char *Msg[]=
  {
    "Player1 key:",
    "  UP----w",
    "  DOWN--s",
    "  LEFT--a",
    "  RIGHT-d",
    "  DO----space",
    "",
    "Player2 key:",
    "  UP----up",
    "  DOWN--down",
    "  LEFT--left",
    "  RIGHT-right",
    "  DO----ENTER",
    "",
    "exit game:",
    "  ESC",
    NULL,
  };

  /*先手方为1号玩家*/
  gPlayOrder = CHESS1;
  /*棋盘数据清零, 即棋盘上各点开始的时候都没有棋子*/
  for(i=0;i<19;i++)
    for(j=0;j<19;j++)
      gChessBoard[i][j]=CHESSNULL;
  /*光标初始位置*/
  gCursor.x=gCursor.y=0;

  /*画棋盘*/
  textmode(C40);
  DrawMap();

  /*显示操作键说明*/
  i=0;
  textcolor(BROWN);
  while(Msg[i]!=NULL)
  {
    gotoxy(25,3+i);
    cputs(Msg[i]);
    i++;
  }

  /*显示当前行棋方*/
  ShowOrderMsg(gPlayOrder);
  /*光标移至棋盘的左上角点处*/
  gotoxy(gCursor.x+MAPXOFT,gCursor.y+MAPYOFT);
}

/*画棋盘*/
void DrawMap(void)
{
  int i,j;

  clrscr();

  for(i=0;i<19;i++)
    for(j=0;j<19;j++)
      DrawCross(i,j);

}

/*画棋盘上的交叉点*/
void DrawCross(int x,int y)
{
  gotoxy(x+MAPXOFT,y+MAPYOFT);
  /*交叉点上是一号玩家的棋子*/
  if(gChessBoard[x][y]==CHESS1)
  {
    textcolor(LIGHTBLUE);
    putch(CHESS1);
    return;
  }
  /*交叉点上是二号玩家的棋子*/
  if(gChessBoard[x][y]==CHESS2)
  {
    textcolor(LIGHTBLUE);
    putch(CHESS2);
    return;
  }

  textcolor(GREEN);

  /*左上角交叉点*/
  if(x==0&&y==0)
  {
    putch(CROSSLU);
    return;
  }

  /*左下角交叉点*/
  if(x==0&&y==18)
  {
    putch(CROSSLD);
    return;
  }
  
  /*右上角交叉点*/
  if(x==18&&y==0)
  {
    putch(CROSSRU);
    return;
  }

  /*右下角交叉点*/
  if(x==18&&y==18)
  {
    putch(CROSSRD);
    return;
  }

  /*左边界交叉点*/
  if(x==0)
  {
    putch(CROSSL);
    return;
  }

  /*右边界交叉点*/
  if(x==18)
  {
    putch(CROSSR);
    return;
  }

  /*上边界交叉点*/
  if(y==0)
  {
    putch(CROSSU);
    return;
  }

  /*下边界交叉点*/
  if(y==18)
  {
    putch(CROSSD);
    return;
  }

  /*棋盘中间的交叉点*/
  putch(CROSS);
}

/*交换行棋方*/
int ChangeOrder(void)
{
  if(gPlayOrder==CHESS1)
    gPlayOrder=CHESS2;
  else
    gPlayOrder=CHESS1;

  return(gPlayOrder);
}

/*获取按键值*/
int GetKey(void)
{
   char lowbyte;
   int press;

   while (bioskey(1) == 0)
      ;/*如果用户没有按键,空循环*/

   press=bioskey(0);
   lowbyte=press&0xff;
   press=press&0xff00 + toupper(lowbyte);
   return(press);
}

/*落子错误处理*/
void DoError(void)
{
   sound(1200);
   delay(50);
   nosound();
}

/*赢棋处理*/
void DoWin(int Order)
{
   sound(1500);delay(100);
   sound(0);   delay(50);
   sound(800); delay(100);
   sound(0);   delay(50);
   sound(1500);delay(100);
   sound(0);   delay(50);
   sound(800); delay(100);
   sound(0);   delay(50);
   nosound();

   textcolor(RED+BLINK);
   gotoxy(25,20);
   if(Order==CHESS1)
     cputs("PLAYER1 WIN!");
   else
     cputs("PLAYER2 WIN!");
   gotoxy(25,21);
   cputs("  \\<^+^>/");
   getch();
}

/*走棋*/
int  ChessGo(int Order,struct point Cursor)
{
   /*判断交叉点上有无棋子*/
   if(gChessBoard[Cursor.x][Cursor.y]==CHESSNULL)
   {
     /*若没有棋子, 则可以落子*/
     gotoxy(Cursor.x+MAPXOFT,Cursor.y+MAPYOFT);
     textcolor(LIGHTBLUE);
     putch(Order);
     gotoxy(Cursor.x+MAPXOFT,Cursor.y+MAPYOFT);
     gChessBoard[Cursor.x][Cursor.y]=Order;
     return TRUE;
   }
   else
     return FALSE;
}

/*判断当前行棋方落子后是否赢棋*/
int  JudgeWin(int Order,struct point Cursor)
{
  int i;
  for(i=0;i<4;i++)
    /*判断在指定方向上是否有连续5个行棋方的棋子*/
    if(JudgeWinLine(Order,Cursor,i))
      return TRUE;
  return FALSE;
}

/*判断在指定方向上是否有连续5个行棋方的棋子*/
int  JudgeWinLine(int Order,struct point Cursor,int direction)
{
   int i;
   struct point pos,dpos;
   const int testnum = 5;
   int count;

   switch(direction)
   {
   case 0:/*在水平方向*/
     pos.x=Cursor.x-(testnum-1);
     pos.y=Cursor.y;
     dpos.x=1;
     dpos.y=0;
     break;
   case 1:/*在垂直方向*/
     pos.x=Cursor.x;
     pos.y=Cursor.y-(testnum-1);
     dpos.x=0;
     dpos.y=1;
     break;
   case 2:/*在左下至右上的斜方向*/
     pos.x=Cursor.x-(testnum-1);
     pos.y=Cursor.y+(testnum-1);
     dpos.x=1;
     dpos.y=-1;
     break;
   case 3:/*在左上至右下的斜方向*/
     pos.x=Cursor.x-(testnum-1);
     pos.y=Cursor.y-(testnum-1);
     dpos.x=1;
     dpos.y=1;
     break;
   }

   count=0;
   for(i=0;i<testnum*2+1;i++)
   {
     if(pos.x>=0&&pos.x<=18&&pos.y>=0&&pos.y<=18)
     {
       if(gChessBoard[pos.x][pos.y]==Order)
       {
             count++;
             if(count>=testnum)
             return TRUE;
       }
       else
         count=0;
     }
     pos.x+=dpos.x;
     pos.y+=dpos.y;
   }

   return FALSE;
}

/*移动光标*/
void MoveCursor(int Order,int press)
{
  switch(press)
  {
  case PLAY1UP:
    if(Order==CHESS1&&gCursor.y>0)
      gCursor.y--;
    break;
  case PLAY1DOWN:
    if(Order==CHESS1&&gCursor.y<18)
      gCursor.y++;
    break;
  case PLAY1LEFT:
    if(Order==CHESS1&&gCursor.x>0)
      gCursor.x--;
    break;
  case PLAY1RIGHT:
    if(Order==CHESS1&&gCursor.x<18)
      gCursor.x++;
    break;

  case PLAY2UP:
    if(Order==CHESS2&&gCursor.y>0)
      gCursor.y--;
    break;
  case PLAY2DOWN:
    if(Order==CHESS2&&gCursor.y<18)
      gCursor.y++;
    break;
  case PLAY2LEFT:
    if(Order==CHESS2&&gCursor.x>0)
      gCursor.x--;
    break;
  case PLAY2RIGHT:
    if(Order==CHESS2&&gCursor.x<18)
      gCursor.x++;
    break;
  }

  gotoxy(gCursor.x+MAPXOFT,gCursor.y+MAPYOFT);
}

/*游戏结束处理*/
void EndGame(void)
{
   textmode(C80);
}

/*显示当前行棋方*/
void ShowOrderMsg(int Order)
{
  gotoxy(6,MAPYOFT+20);
  textcolor(LIGHTRED);
  if(Order==CHESS1)
     cputs("Player1 go!");
  else
     cputs("Player2 go!");

  gotoxy(gCursor.x+MAPXOFT,gCursor.y+MAPYOFT);
}

/*落子正确处理*/
void DoOK(void)
{
   sound(500);
   delay(70);
   sound(600);
   delay(50);
   sound(1000);
   delay(100);
   nosound();
}

/*检查用户的按键类别*/
int CheckKey(int press)
{
    if(press==ESCAPE)
      return KEYEXIT;/*是退出键*/

    else
    if
    ( ( press==PLAY1DO && gPlayOrder==CHESS1) ||
      ( press==PLAY2DO && gPlayOrder==CHESS2)
    )
      return KEYFALLCHESS;/*是落子键*/

    else
    if
    ( press==PLAY1UP   || press==PLAY1DOWN  ||
      press==PLAY1LEFT || press==PLAY1RIGHT ||
      press==PLAY2UP   || press==PLAY2DOWN  ||
      press==PLAY2LEFT || press==PLAY2RIGHT
    )
      return KEYMOVECURSOR;/*是光标移动键*/

    else
      return KEYINVALID;/*按键无效*/
}

37 楼

好像缺少一些头文件。

38 楼

36楼的大哥,
我怎么运行不了你的程序啊,是不是有的头文件没有包括进来
运行后也错提示是:fatal error C1083: Cannot open include file: 'bios.h': No such file or directory
请解释啊,!![em11]

39 楼

我也急需要,这样的程序,可是第一个太长,第二个好象不好用,请解释啊!

40 楼

need yours #include "mousea.h"

我来回复

您尚未登录,请登录后再回复。点此登录或注册