搜档网
当前位置:搜档网 › C语言编写象棋程序代码

C语言编写象棋程序代码

C语言编写象棋程序代码
C语言编写象棋程序代码

/*--------------------chess.c----------------------*/ #include "dos.h"

#include "stdio.h"

/*----------------------------------------------------*/ #define RED 7

#define BLACK 14

#define true 1

#define false 0

#define SELECT 0

#define MOVE 1

#define RED_UP 0x1100

#define RED_DOWN 0x1f00

#define RED_LEFT 0x1e00

#define RED_RIGHT 0x2000

#define RED_DO 0x3900

#define RED_UNDO 0x1000

#define BLACK_UP 0x4800

#define BLACK_DOWN 0x5000

#define BLACK_LEFT 0x4b00

#define BLACK_RIGHT 0x4d00

#define BLACK_DO 0x1c00

#define BLACK_UNDO 0x2b00

#define ESCAPE 0x0100

#define RED_JU 1

#define RED_MA 2

#define RED_XIANG 3

#define RED_SHI 4

#define RED_JIANG 5

#define RED_PAO 6

#define RED_BIN 7

#define BLACK_JU 8

#define BLACK_MA 9

#define BLACK_XIANG 10

#define BLACK_SHI 11

#define BLACK_JIANG 12

#define BLACK_PAO 13

#define BLACK_BIN 14

/*----------------------------------------------------*/ int firsttime=1;

int savemode;

char page_new=0,page_old=0;

int finish=false,turn=BLACK,winner=0;

int key;

int redstate=SELECT,blackstate=SELECT;

int board[10][9];

/*----------------------------------------------------*/

char *chessfile[15]={"",

"bmp\\rju.wfb", "bmp\\rma.wfb", "bmp\\rxiang.wfb","bmp\\rshi.wfb",

"bmp\\rjiang.wfb","bmp\\rpao.wfb","bmp\\rbin.wfb",

"bmp\\bju.wfb", "bmp\\bma.wfb", "bmp\\bxiang.wfb","bmp\\bshi.wfb",

"bmp\\bjiang.wfb","bmp\\bpao.wfb","bmp\\bbin.wfb"

};

char *boardfile[10][9]={

{"bmp\\11.wfb","bmp\\1t.wfb","bmp\\1t.wfb","bmp\\14.wfb","bmp\\15.wfb","bmp\\16.wfb","bmp \\1t.wfb","bmp\\1t.wfb","bmp\\19.wfb"},

{"bmp\\21.wfb","bmp\\2c.wfb","bmp\\2c.wfb","bmp\\24.wfb","bmp\\25.wfb","bmp\\26.wfb","bm p\\2c.wfb","bmp\\2c.wfb","bmp\\29.wfb"},

{"bmp\\21.wfb","bmp\\3a.wfb","bmp\\3t.wfb","bmp\\34.wfb","bmp\\3t.wfb","bmp\\36.wfb","bmp \\3t.wfb","bmp\\3a.wfb","bmp\\29.wfb"},

{"bmp\\41.wfb","bmp\\4t.wfb","bmp\\4a.wfb","bmp\\4t.wfb","bmp\\4a.wfb","bmp\\4t.wfb","bmp\ \4a.wfb","bmp\\4t.wfb","bmp\\49.wfb"},

{"bmp\\51.wfb","bmp\\52.wfb","bmp\\5t.wfb","bmp\\54.wfb","bmp\\5t.wfb","bmp\\56.wfb","bmp \\5t.wfb","bmp\\58.wfb","bmp\\59.wfb"},

{"bmp\\61.wfb","bmp\\62.wfb","bmp\\6t.wfb","bmp\\64.wfb","bmp\\6t.wfb","bmp\\66.wfb","bmp \\6t.wfb","bmp\\68.wfb","bmp\\69.wfb"},

{"bmp\\71.wfb","bmp\\7t.wfb","bmp\\7a.wfb","bmp\\7t.wfb","bmp\\7a.wfb","bmp\\7t.wfb","bmp\ \7a.wfb","bmp\\7t.wfb","bmp\\79.wfb"},

{"bmp\\81.wfb","bmp\\8a.wfb","bmp\\8t.wfb","bmp\\84.wfb","bmp\\85.wfb","bmp\\86.wfb","bm p\\8t.wfb","bmp\\8a.wfb","bmp\\89.wfb"},

{"bmp\\91.wfb","bmp\\9t.wfb","bmp\\9t.wfb","bmp\\9t.wfb","bmp\\95.wfb","bmp\\9t.wfb","bmp\ \9t.wfb","bmp\\9t.wfb","bmp\\99.wfb"},

{"bmp\\101.wfb","bmp\\102.wfb","bmp\\102.wfb","bmp\\104.wfb","bmp\\105.wfb","bmp\\106.wf b","bmp\\108.wfb","bmp\\108.wfb","bmp\\109.wfb"}

};

char cursor[14][14]={

0,0,0,0,0,0,0,0,0,0,0,0,1,1,

0,0,0,0,0,0,0,0,0,0,0,1,1,1,

0,255,255,255,255,255,255,255,0,0,1,1,1,1,

0,255,255,255,255,255,255,0,0,1,1,1,1,1,

0,255,255,255,255,255,255,0,0,1,1,1,1,1,

0,255,255,255,255,255,255,255,0,0,1,1,1,1,

0,255,255,255,255,255,255,255,255,0,0,1,1,1,

0,255,255,255,255,255,255,255,255,255,0,0,1,1,

0,255,255,0,255,255,255,255,255,255,255,0,0,1,

0,255,0,1,1,0,255,255,255,255,255,255,255,0,

0,0,1,1,1,1,0,255,255,255,255,255,0,1,

0,1,1,1,1,1,1,0,255,255,255,0,1,1,

1,1,1,1,1,1,1,1,0,255,0,1,1,1,

1,1,1,1,1,1,1,1,1,0,1,1,1,1

};

struct pos{

int x;

int y;

}position[10][9],redcurpos,redtemppos,redoldpos,blackcurpos,blacktemppos,blackoldpos; /*----------------------------------------------------*/

selectpage(register char page) /*换页函数*/

{

union REGS r;

r.x.ax=0x4f05;

r.x.bx=0;

r.x.dx=page; /*选择页面*/

int86(0x10,&r,&r);

}

unsigned char set_SVGA_mode(int vmode) /*设置SVGA屏幕模式*/

{

union REGS r;

r.x.ax=0x4f02;

r.x.bx=vmode;

int86(0x10,&r,&r);

return(r.h.ah);

}

unsigned int get_SVGA_mode() /*获取当前SVGA屏幕模式*/

{

union REGS r;

r.x.ax=0x4f03;

int86(0x10,&r,&r);

return(r.x.bx);

}

drawbmp(int start_x,int start_y,char filename[])

{

char buffer[640];

int i,j,k,n,r,g,b,width,length;

long position;

FILE *fp;

if((fp=fopen(filename,"rb"))==NULL)

{

printf("Error! Can't open file!");

getch();

return;

}

fseek(fp,28,SEEK_SET);

fread(&i,2,1,fp);

if(i!=8) /*检查是否为256色位图*/

{

puts("Error!Can't find bitmap!");

fclose(fp);

getch();

exit(0);

}

fseek(fp,18,SEEK_SET);

fread(&width,4,1,fp);

fread(&length,4,1,fp);

if(firsttime)

{

fseek(fp,54,SEEK_SET);

for(i=0;i<256;i++) /*按照该图片的DAC色表设置色彩寄存器*/

{

b=fgetc(fp);g=fgetc(fp);r=fgetc(fp); /*获取R、G、B分量*/

outportb(0x3c8,i);

outportb(0x3c9,r>>2); /*右移是要转化为VGA的6位寄存器形式*/ outportb(0x3c9,g>>2);

outportb(0x3c9,b>>2);

fgetc(fp);

}

}

else

fseek(fp,300,SEEK_SET);

k=(width%4)?(4-width%4):0; /*宽度修正值*/

for(j=length-1+start_x;j>=start_x;j--)

{

fread(buffer,width,1,fp);

for(i=start_y,n=0;i

{

position=j*640l+i; /*计算要显示点的显存位置*/

page_new=position/65536; /*计算显示页*/

if(page_new!=page_old) /*当显示页不同时更换页面,提高一定的输出速度*/ {selectpage(page_new);page_old=page_new;}

pokeb(0xa000,position%65536,buffer[n]); /*写到显存位置*/

}

fseek(fp,k,SEEK_CUR); /*每行绘制完后修正宽度*/

}

fclose(fp);

}

init()

{

savemode=get_SVGA_mode(); /*先保存原来的屏幕模式*/

set_SVGA_mode(0x101); /*硬件无关性初始化屏幕为640*480 256色模式*/

}

end()

{

set_SVGA_mode(savemode); /*恢复屏幕*/

}

/*----------------------------------------------------*/

initpos()

{

int i,j;

for(i=0;i<10;i++)

for (j=0;j<9;j++)

{

position[i][j].x=35+i*39;

position[i][j].y=43+j*40;

}

}

initchessmap()

{

board[0][0]=BLACK_JU;

board[0][1]=BLACK_MA;

board[0][2]=BLACK_XIANG;

board[0][3]=BLACK_SHI;

board[0][4]=BLACK_JIANG;

board[0][5]=BLACK_SHI;

board[0][6]=BLACK_XIANG;

board[0][7]=BLACK_MA;

board[0][8]=BLACK_JU;

board[2][1]=BLACK_PAO;

board[2][7]=BLACK_PAO;

board[3][0]=BLACK_BIN;

board[3][2]=BLACK_BIN;

board[3][4]=BLACK_BIN;

board[3][6]=BLACK_BIN;

board[3][8]=BLACK_BIN;

board[9][0]=RED_JU;

board[9][1]=RED_MA;

board[9][2]=RED_XIANG;

board[9][3]=RED_SHI;

board[9][4]=RED_JIANG;

board[9][5]=RED_SHI;

board[9][6]=RED_XIANG;

board[9][7]=RED_MA;

board[9][8]=RED_JU;

board[7][1]=RED_PAO;

board[7][7]=RED_PAO;

board[6][0]=RED_BIN;

board[6][2]=RED_BIN;

board[6][4]=RED_BIN;

board[6][6]=RED_BIN;

board[6][8]=RED_BIN;

}

initdrawchess()

{

int i,j;;

for(i=0;i<10;i++)

for(j=0;j<9;j++)

{

if(board[i][j])

drawbmp(position[i][j].x,position[i][j].y,chessfile[board[i][j]]);

}

}

drawcursor(struct pos p)

{

int i,j,n,m,x,y;

long thisposition;

x=position[p.x][p.y].x+20;

y=position[p.x][p.y].y+25;

for(j=13-1+x,m=13;j>=x;j--,m--)

{

for(i=y,n=0;i<13+y;i++,n++)

{

thisposition=j*640l+i; /*计算要显示点的显存位置*/

page_new=thisposition/65536; /*计算显示页*/

if(page_new!=page_old) /*当显示页不同时更换页面,提高一定的输出速度*/

{selectpage(page_new);page_old=page_new;}

if(cursor[m][n]!=1)

if(cursor[m][n]==0)

pokeb(0xa000,thisposition%65536,0);

else

if(turn==RED)

pokeb(0xa000,thisposition%65536,153);

else

pokeb(0xa000,thisposition%65536,255);

}

}

}

drawselecursor(struct pos p)

{

int i,j,n,m,x,y;

long thisposition;

x=position[p.x][p.y].x+20;

y=position[p.x][p.y].y+25;

for(j=13-1+x,m=13;j>=x;j--,m--)

{

for(i=y,n=0;i<13+y;i++,n++)

{

thisposition=j*640l+i; /*计算要显示点的显存位置*/

page_new=thisposition/65536; /*计算显示页*/

if(page_new!=page_old) /*当显示页不同时更换页面,提高一定的输出速度*/

{selectpage(page_new);page_old=page_new;}

if(cursor[m][n]!=1)

pokeb(0xa000,thisposition%65536,0);

}

}

}

/*----------------------------------------------------*/

int getkey()

{

int press;

while(bioskey(1) == 0);

press=bioskey(0);

press=press&0xff00;

return(press);

}

/*--------------------红方操作--------------------*/

int redcanselect()

{

int x,y;

x=redcurpos.x;

y=redcurpos.y;

if(board[x][y]>=RED_JU&&board[x][y]<=RED_BIN)

return 1;

else

return 0;

}

int redcanmove()

{

int i,j,min,max,oldx,oldy,x,y;

oldx=redoldpos.x;

oldy=redoldpos.y;

x=redcurpos.x;

y=redcurpos.y;

/*case1 目标位置是否是自己人*/

if(board[x][y]>=RED_JU&&board[x][y]<=RED_BIN)

return 0;

/* 军、马、炮、相、士、将、卒的走法正确性的判断*/

switch(board[oldx][oldy])

{

case RED_BIN: /*完成*/ if(oldx>=5)

{ if(y!=oldy||(oldx-x)!=1) return 0;}

else

{ if(x==(oldx-1)&&y==oldy) return 1;

else

if(x==oldx&&y==(oldy+1)) return 1;

else

if(x==oldx&&y==(oldy-1)) return 1;

else

return 0;

}

break;

case RED_JIANG: /*完成*/ if(x!=oldx&&y!=oldy) return 0;

if(x!=oldx)

if((x-oldx)>1||(oldx-x)>1) return 0;

else if(x<7) return 0;

else if(y!=oldy)

if((y-oldy)>1||(oldy-y)>1) return 0;

else if(y<3||y>5) return 0;

break;

case RED_JU: /*完成*/ if(x!=oldx&&y!=oldy) return 0;

else if(x!=oldx)

{ min=(x>oldx)?oldx:x;

max=(x>oldx)?x:oldx;

for(i=min+1;i

if(board[i][y]!=0) return 0;

}

else if(y!=oldy)

{ min=(y>oldy)?oldy:y;

max=(y>oldy)?y:oldy;

for(i=min+1;i

if(board[x][i]!=0) return 0;

}

break;

case RED_MA: /*完成*/ if((x-oldx)==2&&((y-oldy)==1||(oldy-y)==1))

{

if(board[oldx+1][oldy]!=0) return 0;

}else

if((oldx-x)==2&&((y-oldy)==1||(oldy-y)==1))

{

if(board[oldx-1][oldy]!=0) return 0;

}else

if((y-oldy)==2&&((x-oldx)==1||(oldx-x)==1))

{

if(board[oldx][oldy+1]!=0) return 0;

}else

if((oldy-y)==2&&((x-oldx)==1||(oldx-x)==1))

{

if(board[oldx][oldy-1]!=0) return 0;

}else

return 0;

break;

case RED_PAO: /*完成*/ if(x!=oldx&&y!=oldy) return 0;

if(board[x][y]==0)

{

if(x!=oldx)

{ min=(x>oldx)?oldx:x;

max=(x>oldx)?x:oldx;

for(i=min+1;i

if(board[i][y]!=0) return 0;

}

else if(y!=oldy)

{ min=(y>oldy)?oldy:y;

max=(y>oldy)?y:oldy;

for(i=min+1;i

if(board[x][i]!=0) return 0;

}

}

else

{

if(x!=oldx)

{ min=(x>oldx)?oldx:x;

max=(x>oldx)?x:oldx;

for(i=min+1,j=0;i

if(board[i][y]!=0) j++;

if(j!=1) return 0;

}

else if(y!=oldy)

{ min=(y>oldy)?oldy:y;

max=(y>oldy)?y:oldy;

for(i=min+1,j=0;i

if(board[x][i]!=0) j++;

if(j!=1) return 0;

}

}

break;

case RED_SHI: /*完成*/ if(oldx==9||oldx==7)

{if(x!=8||y!=4) return 0;}

else if(oldx==8)

{if(x==9&&y==3) return 1;

else

if(x==9&&y==5) return 1;

else

if(x==7&&y==3) return 1;

else

if(x==7&&y==5) return 1;

else return 0;

}else return 0;

break;

case RED_XIANG: /*完成*/ if(x<5) return 0;

if(x!=oldx&&y!=oldy)

{

if((x-oldx)==2&&(y-oldy)==2)

{i=oldx+1;j=oldy+1;}

else if((x-oldx)==2&&(oldy-y)==2)

{i=oldx+1;j=oldy-1;}

else if((oldx-x)==2&&(y-oldy)==2)

{i=oldx-1;j=oldy+1;}

else if((oldx-x)==2&&(oldy-y)==2)

{i=oldx-1;j=oldy-1;}

else return 0;

if(board[i][j]!=0) return 0;

}

else return 0;

break;

}

return 1;

}

redup()

{

int x,y,n;

if(redcurpos.x>0)

{

redcurpos.x--;

x=position[redtemppos.x][redtemppos.y].x;

y=position[redtemppos.x][redtemppos.y].y;

if(board[redtemppos.x][redtemppos.y]==0)

drawbmp(x,y,boardfile[redtemppos.x][redtemppos.y]);

else

if(!(redtemppos.x==redoldpos.x&&redtemppos.y==redoldpos.y&&redstate==MOVE)) {

n=board[redtemppos.x][redtemppos.y];

drawbmp(x,y,chessfile[n]);

}

if(redtemppos.x==redoldpos.x&&redtemppos.y==redoldpos.y&&redstate==MOVE)

drawselecursor(redoldpos);

drawcursor(redcurpos);

redtemppos.x=redcurpos.x;

redtemppos.y=redcurpos.y;

}

}

reddown()

{

int x,y,n;

if(redcurpos.x<9)

{

redcurpos.x++;

x=position[redtemppos.x][redtemppos.y].x;

y=position[redtemppos.x][redtemppos.y].y;

if(board[redtemppos.x][redtemppos.y]==0)

drawbmp(x,y,boardfile[redtemppos.x][redtemppos.y]);

else

if(!(redtemppos.x==redoldpos.x&&redtemppos.y==redoldpos.y&&redstate==MOVE)) {

n=board[redtemppos.x][redtemppos.y];

drawbmp(x,y,chessfile[n]);

}

if(redtemppos.x==redoldpos.x&&redtemppos.y==redoldpos.y&&redstate==MOVE)

drawselecursor(redoldpos);

drawcursor(redcurpos);

redtemppos.x=redcurpos.x;

redtemppos.y=redcurpos.y;

}

}

redleft()

{

int x,y,n;

if(redcurpos.y>0)

{

redcurpos.y--;

x=position[redtemppos.x][redtemppos.y].x;

y=position[redtemppos.x][redtemppos.y].y;

if(board[redtemppos.x][redtemppos.y]==0)

drawbmp(x,y,boardfile[redtemppos.x][redtemppos.y]);

else

if(!(redtemppos.x==redoldpos.x&&redtemppos.y==redoldpos.y&&redstate==MOVE)) {

n=board[redtemppos.x][redtemppos.y];

drawbmp(x,y,chessfile[n]);

}

if(redtemppos.x==redoldpos.x&&redtemppos.y==redoldpos.y&&redstate==MOVE)

drawselecursor(redoldpos);

drawcursor(redcurpos);

redtemppos.x=redcurpos.x;

redtemppos.y=redcurpos.y;

}

}

redright()

{

int x,y,n;

if(redcurpos.y<8)

{

redcurpos.y++;

x=position[redtemppos.x][redtemppos.y].x;

y=position[redtemppos.x][redtemppos.y].y;

if(board[redtemppos.x][redtemppos.y]==0)

drawbmp(x,y,boardfile[redtemppos.x][redtemppos.y]);

else

if(!(redtemppos.x==redoldpos.x&&redtemppos.y==redoldpos.y&&redstate==MOVE)) {

n=board[redtemppos.x][redtemppos.y];

drawbmp(x,y,chessfile[n]);

}

if(redtemppos.x==redoldpos.x&&redtemppos.y==redoldpos.y&&redstate==MOVE)

drawselecursor(redoldpos);

drawcursor(redcurpos);

redtemppos.x=redcurpos.x;

redtemppos.y=redcurpos.y;

}

}

reddo()

{

int i,j,x,y,n;

if(redstate==SELECT&&redcanselect())

{

if(board[redcurpos.x][redcurpos.y]<=RED&&board[redcurpos.x][redcurpos.y]>0) {

redstate=MOVE;

drawselecursor(redcurpos);

redoldpos.x=redcurpos.x;

redoldpos.y=redcurpos.y;

}

}

else if(redstate==MOVE&&redcanmove())

{

x=position[redoldpos.x][redoldpos.y].x;

y=position[redoldpos.x][redoldpos.y].y;

drawbmp(x,y,boardfile[redoldpos.x][redoldpos.y]);

x=position[redcurpos.x][redcurpos.y].x;

y=position[redcurpos.x][redcurpos.y].y;

n=board[redoldpos.x][redoldpos.y];

drawbmp(x,y,chessfile[n]);

if(board[redcurpos.x][redcurpos.y]==BLACK_JIANG)

{

winner=RED;

finish=1;

return;

}

board[redcurpos.x][redcurpos.y]=n;

board[redoldpos.x][redoldpos.y]=0;

for(i=0;i<=2;i++)

for(j=3;j<=5;j++)

if(board[i][j]==BLACK_JIANG)

{x=i;y=j;}

for(i=x+1,j=y,n=0;i<=9;i++)

{

if(board[i][j]==RED_JIANG&&n==0)

{winner=BLACK;finish=1;break;}

else if(board[i][j]!=0) n++;

}

turn=BLACK;

blackstate=SELECT;

drawcursor(blackcurpos);

drawbmp(30,438,"bmp\\bzq.wfb"); /*转交控制权给黑方*/ }

}

redundo()

{

int x,y,n;

if(redstate==MOVE)

{

x=position[redoldpos.x][redoldpos.y].x;

y=position[redoldpos.x][redoldpos.y].y;

n=board[redoldpos.x][redoldpos.y];

drawbmp(x,y,chessfile[n]);

redoldpos.x=redcurpos.x;

redoldpos.y=redcurpos.y;

drawcursor(redcurpos);

redstate=SELECT;

}

}

/*--------------------黑方操作----------------------*/

int blackcanselect()

{

int x,y;

x=blackcurpos.x;

y=blackcurpos.y;

if(board[x][y]>=BLACK_JU&&board[x][y]<=BLACK_BIN)

return 1;

else

return 0;

}

int blackcanmove()

{

int i,j,min,max,oldx,oldy,x,y;

oldx=blackoldpos.x;

oldy=blackoldpos.y;

x=blackcurpos.x;

y=blackcurpos.y;

/*case1 目标位置是否是自己人*/

if(board[x][y]>=BLACK_JU&&board[x][y]<=BLACK_BIN)

return 0;

/* 军、马、炮、相、士、将、卒的走法正确性的判断*/

switch(board[oldx][oldy])

{

case BLACK_JU: /*完成*/ if(x!=oldx&&y!=oldy) return 0;

else if(x!=oldx)

{ min=(x>oldx)?oldx:x;

max=(x>oldx)?x:oldx;

for(i=min+1;i

if(board[i][y]!=0) return 0;

}

else if(y!=oldy)

{ min=(y>oldy)?oldy:y;

max=(y>oldy)?y:oldy;

for(i=min+1;i

if(board[x][i]!=0) return 0;

}

break;

case BLACK_MA: /*完成*/ if((x-oldx)==2&&((y-oldy)==1||(oldy-y)==1))

{

if(board[oldx+1][oldy]!=0) return 0;

}else

if((oldx-x)==2&&((y-oldy)==1||(oldy-y)==1))

{

if(board[oldx-1][oldy]!=0) return 0;

}else

if((y-oldy)==2&&((x-oldx)==1||(oldx-x)==1))

{

if(board[oldx][oldy+1]!=0) return 0;

}else

if((oldy-y)==2&&((x-oldx)==1||(oldx-x)==1))

{

if(board[oldx][oldy-1]!=0) return 0;

}else

return 0;

break;

case BLACK_PAO: /*完成*/ if(x!=oldx&&y!=oldy) return 0;

if(board[x][y]==0)

{

if(x!=oldx)

{ min=(x>oldx)?oldx:x;

max=(x>oldx)?x:oldx;

for(i=min+1;i

if(board[i][y]!=0) return 0;

}

else if(y!=oldy)

{ min=(y>oldy)?oldy:y;

max=(y>oldy)?y:oldy;

for(i=min+1;i

if(board[x][i]!=0) return 0;

}

}

else

{

j=0;

if(x!=oldx)

{ min=(x>oldx)?oldx:x;

max=(x>oldx)?x:oldx;

for(i=min+1;i

if(board[i][y]!=0) j++;

if(j!=1) return 0;

}

else if(y!=oldy)

{ min=(y>oldy)?oldy:y;

max=(y>oldy)?y:oldy;

for(i=min+1;i

if(board[x][i]!=0) j++;

if(j!=1) return 0;

}

}

break;

case BLACK_XIANG:

if(x>4) return 0;

if(x!=oldx&&y!=oldy)

{

if((x-oldx)==2&&(y-oldy)==2)

{i=oldx+1;j=oldy+1;}

else if((x-oldx)==2&&(oldy-y)==2)

{i=oldx+1;j=oldy-1;}

else if((oldx-x)==2&&(y-oldy)==2)

{i=oldx-1;j=oldy+1;}

else if((oldx-x)==2&&(oldy-y)==2)

{i=oldx-1;j=oldy-1;}

else return 0;

if(board[i][j]!=0) return 0;

}

else return 0;

break;

case BLACK_SHI:

if(oldx==0||oldx==2)

{if(x!=1||y!=4) return 0;}

else if(oldx==1)

{if(x==0&&y==3) return 1;

else

if(x==0&&y==5) return 1;

else

if(x==2&&y==3) return 1;

else

if(x==2&&y==5) return 1;

else return 0;

}else return 0;

break;

case BLACK_JIANG:

if(x!=oldx&&y!=oldy) return 0;

if(x!=oldx)

if((x-oldx)>1||(oldx-x)>1) return 0;

else if(x>2) return 0;

else if(y!=oldy)

if((y-oldy)>1||(oldy-y)>1) return 0;

else if(y<3||y>5) return 0;

break;

case BLACK_BIN:

if(oldx<=4)

{ if(y!=oldy||(x-oldx)!=1) return 0;}

else

{ if(x==(oldx+1)&&y==oldy) return 1;

else

if(x==oldx&&y==(oldy+1)) return 1;

else

if(x==oldx&&y==(oldy-1)) return 1;

else

return 0;

}

break;

}

return 1;

}

blackup()

{

int x,y,n;

if(blackcurpos.x>0)

{

blackcurpos.x--;

x=position[blacktemppos.x][blacktemppos.y].x;

y=position[blacktemppos.x][blacktemppos.y].y;

if(board[blacktemppos.x][blacktemppos.y]==0)

drawbmp(x,y,boardfile[blacktemppos.x][blacktemppos.y]);

else

if(!(blacktemppos.x==blackoldpos.x&&blacktemppos.y==blackoldpos.y&&blackstate==MOVE)) {

n=board[blacktemppos.x][blacktemppos.y];

drawbmp(x,y,chessfile[n]);

}

if(blacktemppos.x==blackoldpos.x&&blacktemppos.y==blackoldpos.y&&blackstate==MOVE) drawselecursor(blackoldpos);

drawcursor(blackcurpos);

blacktemppos.x=blackcurpos.x;

blacktemppos.y=blackcurpos.y;

}

}

blackdown()

{

int x,y,n;

if(blackcurpos.x<9)

{

blackcurpos.x++;

x=position[blacktemppos.x][blacktemppos.y].x;

y=position[blacktemppos.x][blacktemppos.y].y;

if(board[blacktemppos.x][blacktemppos.y]==0)

drawbmp(x,y,boardfile[blacktemppos.x][blacktemppos.y]);

else

if(!(blacktemppos.x==blackoldpos.x&&blacktemppos.y==blackoldpos.y&&blackstate==MOVE)) {

n=board[blacktemppos.x][blacktemppos.y];

drawbmp(x,y,chessfile[n]);

}

if(blacktemppos.x==blackoldpos.x&&blacktemppos.y==blackoldpos.y&&blackstate==MOVE) drawselecursor(blackoldpos);

drawcursor(blackcurpos);

blacktemppos.x=blackcurpos.x;

blacktemppos.y=blackcurpos.y;

}

}

blackleft()

{

int x,y,n;

if(blackcurpos.y>0)

{

blackcurpos.y--;

x=position[blacktemppos.x][blacktemppos.y].x;

y=position[blacktemppos.x][blacktemppos.y].y;

if(board[blacktemppos.x][blacktemppos.y]==0)

drawbmp(x,y,boardfile[blacktemppos.x][blacktemppos.y]);

else

if(!(blacktemppos.x==blackoldpos.x&&blacktemppos.y==blackoldpos.y&&blackstate==MOVE)) {

n=board[blacktemppos.x][blacktemppos.y];

drawbmp(x,y,chessfile[n]);

}

if(blacktemppos.x==blackoldpos.x&&blacktemppos.y==blackoldpos.y&&blackstate==MOVE) drawselecursor(blackoldpos);

drawcursor(blackcurpos);

blacktemppos.x=blackcurpos.x;

blacktemppos.y=blackcurpos.y;

}

}

blackright()

{

int x,y,n;

if(blackcurpos.y<8)

{

blackcurpos.y++;

x=position[blacktemppos.x][blacktemppos.y].x;

y=position[blacktemppos.x][blacktemppos.y].y;

if(board[blacktemppos.x][blacktemppos.y]==0)

drawbmp(x,y,boardfile[blacktemppos.x][blacktemppos.y]);

中国象棋源代码Java程序

import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.*; import java.io.*; public class Chess{ public static void main(String args[]){ new ChessMainFrame("中国象棋:观棋不语真君子,棋死无悔大丈夫"); } } class ChessMainFrame extends JFrame implements ActionListener,MouseListener,Runnable{ //玩家 JLabel play[] = new JLabel[32]; //棋盘 JLabel image; //窗格 Container con; //工具栏 JToolBar jmain; //重新开始 JButton anew; //悔棋 JButton repent; //退出 JButton exit; //当前信息 JLabel text; //保存当前操作 Vector Var; //规则类对象(使于调用方法) ChessRule rule; /** ** 单击棋子 ** chessManClick = true 闪烁棋子并给线程响应 ** chessManClick = false 吃棋子停止闪烁并给线程响应 */ boolean chessManClick;

/** ** 控制玩家走棋 ** chessPlayClick=1 黑棋走棋 ** chessPlayClick=2 红棋走棋默认红棋 ** chessPlayClick=3 双方都不能走棋 */ int chessPlayClick=2; //控制棋子闪烁的线程 Thread tmain; //把第一次的单击棋子给线程响应 static int Man,i; ChessMainFrame(){ new ChessMainFrame("中国象棋"); } /** ** 构造函数 ** 初始化图形用户界面 */ ChessMainFrame(String Title){ //获行客格引用 con = this.getContentPane(); con.setLayout(null); //实例化规则类 rule = new ChessRule(); Var = new Vector(); //创建工具栏 jmain = new JToolBar(); text = new JLabel("欢迎使用象棋对弈系统"); //当鼠标放上显示信息 text.setToolTipText("信息提示"); anew = new JButton(" 新游戏 "); anew.setToolTipText("重新开始新的一局"); exit = new JButton(" 退出 "); exit.setToolTipText("退出象棋程序程序"); repent = new JButton(" 悔棋 "); repent.setToolTipText("返回到上次走棋的位置"); //把组件添加到工具栏 jmain.setLayout(new GridLayout(0,4)); jmain.add(anew);

c语言程序代码

1.要求在屏幕上输出下一行信息。 This is a c program. 程序: #include int main() { printf(“this is a c program.\n”); return 0; } 2.求两个整数之和。 程序: #include int main() { int a,b,sum; a=122; b=234; sum=a+b; printf(“sum is %d\n”,sum); return 0; } 3.求两个整数之间的较大者。

#include int main() { int max(int x,int y); int a,b,c; scanf("%d,%d",&a,&b); c=max(a,b); printf("max=%d\n",c); return 0; } int max(int x,int y) { int z; if(x>y)z=x; else z=y; return(z); } 4.有人用温度计测量出华氏发表示的温度(如69°F),今要求把 她转换成以摄氏法表示的温度(如20℃)。 公式:c=5(f-32)/9. 其中f代表华氏温度,c代表摄氏温度。

#include int main() { float f,c; f=64.0; c=(5.0/9)*(f-32); printf("f=%f\nc=%f\n",f,c); return 0; } 5.计算存款利息。有1000元,想存一年。有一下三种方法可选: (1)活期:年利率为r1;(2)一年定期:年利率为r2;(3)存两次半年定期:年利率为r3。分别计算一年后按三种方法所得到的本息和。 程序: #include int main() { float p0=1000,r1=0.0036,r2=0.0225,r3=0.0198,p1,p2,p3; p1=p0*(1+r1); p2=p0*(1+r2);

中国象棋(代码)

中国象棋(web版源代码) 程序: using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Data.SqlClient; namespace WebApplication1 {

public partial class WebForm1 : System.Web.UI.Page { int tru = 20; int fals = 40; public ImageButton[,] _Image=new ImageButton[11,10]; //将上一次点击点的坐标保存到数据库中的lastx和lasty public void SaveToLast() { if (Session["user"].ToString() == "red" && _GetUserState(Session["user"].ToString()) == 20) { int x, y, lastx, lasty; x = Getpointx(); y = Getpointy(); lastx = x; lasty = y; Updatalastx(lastx); Updatalasty(lasty); } if (Session["user"].ToString() == "black" && _GetUserState(Session["user"].ToString()) == 20) { int x, y, lastx, lasty; x = Getpointx(); y = Getpointy(); lastx = x; lasty = y; Updatalastx(lastx); Updatalasty(lasty); } } //将棋盘上所有棋子图片显示到棋盘上 private void _Drawqizi() { //_Init(); int i,j,k; if (_GetUserState("red") != 0 && _GetUserState("black") != 0)

中国象棋源代码-C语言小程序

*--------------------chess.c----------------------*/ #include "dos.h" #include "stdio.h" /*----------------------------------------------------*/ #define RED 7 #define BLACK 14 #define true 1 #define false 0 #define SELECT 0 #define MOVE 1 #define RED_UP 0x1100 #define RED_DOWN 0x1f00 #define RED_LEFT 0x1e00 #define RED_RIGHT 0x2000 #define RED_DO 0x3900 #define RED_UNDO 0x1000 #define BLACK_UP 0x4800 #define BLACK_DOWN 0x5000 #define BLACK_LEFT 0x4b00 #define BLACK_RIGHT 0x4d00 #define BLACK_DO 0x1c00 #define BLACK_UNDO 0x2b00 #define ESCAPE 0x0100 #define RED_JU 1 #define RED_MA 2 #define RED_XIANG 3 #define RED_SHI 4 #define RED_JIANG 5 #define RED_PAO 6 #define RED_BIN 7 #define BLACK_JU 8 #define BLACK_MA 9 #define BLACK_XIANG 10 #define BLACK_SHI 11 #define BLACK_JIANG 12 #define BLACK_PAO 13 #define BLACK_BIN 14 /*----------------------------------------------------*/ int firsttime=1; int savemode;

C语言编程游戏代码

#include #include #include #include #include #define L 1 #define LX 15 #define L Y 4 static struct BLOCK { int x0,y0,x1,y1,x2,y2,x3,y3; int color,next; intb[]={{0,1,1,1,2,1,3,1,4,1},{1,0,1,3,1,2,1,1,4,0},{1,1,2,2,1,2,2,1,1,2},{0,1,1,1,1,0,2,0,2,4}, {0,0,0,1,1,2,1,1,2,3},{0,0,1,0,1,1,2,1,3,8},{1,0,1,1,2,2,2,1,2,5},{0,2,1,2,1,1,2,1,2,6},{0,1,0,2,1,1,1 ,0,3,9},{0,1,1,1,1,2,2,2,3,10},{1,1,1,2,2,1,2,0,3,7},{ 1,0,1,1,1,2,2,2,7,12},{0,1,1,1,2,1,2,0,7,13},{0 ,0,1,2,1,1,1,0,7,14},{0,1,0,2,1,1,2,1,7,11},{0,2,1,2,1,1,1,0,5,16},{0,1,1,1,2,2,2,1,5,17},{1,0,1,1,1, 2,2,0,5,18},{0,0,0,1,1,11,2,1,5,15},{0,1,1,1,1,0,2,1,6,2,0},{0,1,1,2,1,1,1,0,6,21},{0,1,1,2,1,1,2,1,6 ,22},{1,0,1,1,1,2,2,1,6,19}}; static int d[10]={33000,3000,1600,1200,900,800,600,400,300,200}; int Llevel,Lcurrent,Lnext,Lable,lx,ly,Lsum; unsigned Lpoint; int La[19][10],FLAG,sum; unsigned ldelay; void scrint(),datainit(),dispb(),eraseeb(); void throw(),judge(),delayp(),move(0,note(0,show(); int Ldrop(),Ljudge(),nextb(),routejudge(); } main() { char c; datainit(); Label=nextb(); Label=Ldrop(); while(1){ delayp(); if(Label!=0) { Ljudge(); Lable=nextb(); } ldelay--; if(ldelay==0)

中国象棋算法

解剖大象的眼睛——中国象棋程序设计探索 黄晨*2005年6月 ( * 联系地址:复旦大学化学系表面化学实验室,eMail:morning_yellow@elephantbas https://www.sodocs.net/doc/6b11966522.html,) (一) 引言 我在今年2月写出了象棋程序ElephantEye的第一个版本(0.90),本来它只是象棋界面ElephantBoard的调试引擎。在设计程序的过程中,我尝试性地加入了很多算法,发现每次改进都能让程序的棋力有大幅度的提高,因此便对象棋程序的算法产生了浓厚的兴趣。到现在我已经陆续对ElephantEye作了几十次加工(目前版本为0.94),使得它的棋力接近了中等商业软件的水平,在公开源代码的象棋程序中,ElephantEye是最强的一个。 我希望能通过公开源代码的方式,推动中国象棋程序水平的整体发展,然而根据很 多网友的反馈意见,发现源代码中的很多部分并不是那么容易理解的。因此我才打算以《中国象棋程序设计探索》为题,写几篇详细介绍ElephantEye算法的连载,希望能让的源代码充分发挥它的作用。 下面我先简要谈一下我自己对ElephantEye的体会。 1.1 ElephantEye用到了哪些算法? 在我写本次连载以前,我已经完成了《象棋百科全书》网站上《对弈程序基本技术 》专题中所有文章的翻译,ElephantEye的大部分算法都参考了这些文章,这些算法我会在连载中一笔带过,详细的内容希望读者参考这些译文,那里还有我加的很多译注,希 望它们能够加深读者对这些算法的体会。 当然,仅根据这些文章所提供的算法,是写不出很好的程序的,我参考了王小春的《PC游戏编程——人机博弈》一书,也参考了一些国际象棋的源程序,并通过自己的探索,在ElephantEye中加入了另外的非常重要的算法,尤其是启发算法,我认为它们在程序中发挥了关键性的作用,而且很多细节在绝大多数文字资料中没有详细给出,我会在 我的连载中重点介绍。 我猜读者最感兴趣的内容是ElephantEye的着法生成器,这应该算是象棋程序的核心部分,同时也是各个程序差异最大的部分。在写ElephantEye以前,我在《象棋百科全书》网站上刊登了大量介绍“位棋盘”的文章,这是个非常有吸引力的思想,但是我试验 下来觉得它的速度并不快,在ElephantEye的程序里我只把位棋盘运用在将军判断上。尽管如此,ElephantEye短短10行的将军判断也许是程序的一个亮点吧,那么这部分内容我将尽量介绍得详细一点。 此外,一些看似和棋力关系不大的技术,诸如开局库、长将检测、后台思考、时间 策略、引擎协议等等,其实也直接影响着象棋程序的稳定性,因此也有必要逐一讲解。 总之,每个技术都很重要,我的连载虽然不能面面俱到,但我会尽我所能来作详细 阐述的。 1.2 如何正确评价ElephantEye目前的棋力?

c语言程序代码

创作编号: GB8878185555334563BT9125XW 创作者:凤呜大王* 1.要求在屏幕上输出下一行信息。 This is a c program. 程序: #include int main() { printf(“this is a c program.\n”); return 0; } 2.求两个整数之和。 程序: #include int main() { int a,b,sum; a=122; b=234;

sum=a+b; printf(“sum is %d\n”,sum); return 0; } 3.求两个整数之间的较大者。 程序: #include int main() { int max(int x,int y); int a,b,c; scanf("%d,%d",&a,&b); c=max(a,b); printf("max=%d\n",c); return 0; } int max(int x,int y) { int z; if(x>y)z=x; else z=y; return(z);

} 4.有人用温度计测量出华氏发表示的温度(如69°F),今要 求把她转换成以摄氏法表示的温度(如20℃)。 公式:c=5(f-32)/9. 其中f代表华氏温度,c代表摄氏温度。 程序: #include int main() { float f,c; f=64.0; c=(5.0/9)*(f-32); printf("f=%f\nc=%f\n",f,c); return 0; } 5.计算存款利息。有1000元,想存一年。有一下三种方法可 选:(1)活期:年利率为r1;(2)一年定期:年利率为r2; (3)存两次半年定期:年利率为r3。分别计算一年后按三种方法所得到的本息和。 程序: #include

c语言基本代码

c语言基本代码 Prepared on 22 November 2020

'\0':是字符串的结束标志 ‘‘:空格 auto:声明自动变量一般不使用 double:声明双精度变量或函数(和%lf连用), m=(double)(v-l)/l*100+; 这个式子加个double是将后面式子中非double类型强制转换类型为double float:声明浮点型变量或函数(和%f连用),单精度 int:声明整型变量或函数(与%d连用) struct:声明结构体变量或函数 long:声明长整型变量或函数 switch:用于开关语句 enum:声明枚举类型 register:声明积存器变量 typedef:用以给数据类型取别名(当然还有其他作用) extern:声明变量是在其他文件正声明(也可以看做是引用变量) return:子程序返回语句(可以带参数,也看不带参数) union:声明联合数据类型 const:声明只读变量 short:声明短整型变量或函数 unsigned:声明无符号类型变量或函数 signed:生命有符号类型变量或函数 void:声明函数无返回值或无参数,声明无类型指针(基本上就这三个作用)default:开关语句中的“其他”分支 goto:无条件跳转语句 sizeof:计算数据类型长度,,是整型表达式用法sizeof(类型说明符,数组名或表达式);sizeof()是获取类型占用的字节数,是整形的 volatile:说明变量在程序执行中可被隐含地改变 static:声明静态变量 char:声明字符型变量或函数 strcmp:strcmp(s1,s2)比较字符串大小两个字符串自左向右逐个字符相比(按ASCII值大小相比较),直到出现不同的字符或遇'\0'为止大于返回1小于返回-1等于返回0 循环: for:一种循环语句(可意会不可言传)for(表达式1;表达式2;表达式3)while:循环语句的循环条件 do:循环语句的循环体 break:跳出当前循环 continue:结束当前循环,开始下一轮循环 判断: d=a>30b:c:相当于if暨当a>30是d=b否则d=c;

象棋游戏的设计与实现

象棋游戏的设计与实现

目录 1引言 (1) 1.1象棋设计背景和研究意义 (1) 1.2象棋设计研究方法 (1) 2人工智能算法设计 (2) 2.1棋局表示 (3) 2.2着法生成 (4) 2.3搜索算法 (5) 2.4历史启发及着法排序 (9) 2.5局面评估 (9) 2.6程序组装 (11) 3界面及程序辅助设计 (12) 3.1界面基本框架 (12) 3.2多线程 (13) 3.3着法名称显示 (14) 3.4悔棋和还原 (15) 4系统实现 (16) 结论 (19) 参考文献 (20)

1引言 1.1 象棋设计背景和研究意义 电脑游戏行业经过二十年的发展,已经成为与影视、音乐等并驾齐驱的全球最重要的娱乐产业之一,其年销售额超过好莱坞的全年收入。游戏,作为一种娱乐活动。早期的人类社会由于生产力及科技的制约,只能进行一些户外的游戏。随着生产力的发展和科技进步,一种新的游戏方式——电子游戏也随之诞生。 当计算机发明以后,电子游戏又多了一个新的载体。电子游戏在整个计算机产业的带动下不断地创新、发展着。自从计算机发明,向各个领域发展,到成为我们现在每天工作和生活必不可少的一部分的这个过程中,电子游戏也逐步渗入我们每个人的娱乐活动中。而计算机已经普及的今天,对于可以用计算机进行程序编辑的人来说,开发属于自己的游戏,已经不再是梦想。事实上,个人计算机软件市场的大约80%销售份额是来自游戏软件。棋牌游戏属于休闲类游戏,相对于角色扮演类游戏和即时战略类游戏等其它游戏,具有上手快、游戏时间短的特点,更利于用户进行放松休闲,为人们所喜爱,特别是棋类游戏,方便、快捷、操作简单,在休闲娱乐中占主要位置。作为中华民族悠久文化的代表之一,中国象棋不仅源远流长,而且基础广泛,作为一项智力运动,中国象棋开始走向世界。 随着计算机处理速度的飞速提高,人们很早就提出了疑问:计算机是否会超越人类?世界国际象棋大师已被计算机打败,计算机已经超过了人类?而人工智能是综合性很强的一门边缘学科,它的中心任务是研究如何使计算机去做那些过去只能靠人的智力才能做的工作。因此,对游戏开发过程中的人工智能技术的研究自然也就成了业界的一个热门研究方向。 1.2 象棋设计研究方法 对于象棋来说,核心设计主要包括人工智能算法的以及整个游戏中界面及程序辅助部分的实现,主要用 Visual C++ 进行开发,里面的MFC类库,使游戏开发更加方便,并利用人工智能相关搜索算法实现人工智能的着法生成,从而完善整个游戏的功能。 本文的目标是实现一款有着一定下棋水平且交互友好的中国象棋人机对弈程序。 该程序功能包括: *人机对弈; *搜索深度设定; (电脑棋力选择)

(完整word版)一些简单的C语言程序代码

由键盘任意输入1个4位数整数,分别输出其中的个位、十位、百位、千位。 /* expe 3-10 */ #include #include void main(void) { int mun,a,b,c,d; scanf("%d",&mun); a=mun / 1000; /*千位*/ b=(mun % 1000) / 100; /*百位*/ c=(mun % 100) / 10; /*十位*/ d=(mun % 10); /*个位*/ printf("千位数字为=%d\n",a); printf("百位数字为=%d\n",b); printf("十位数字为=%d\n",c); printf("个位数字为=%d\n",d); } 由键盘任意输入3个数据,找出其中的最大数和最小数。 #include void main(void) { float a,b,c,k,g;/* k 小g 大*/ printf ("请输入三个数"); scanf("%f%f%f",&a,&b,&c); if (a < b) { k = a; g = b; } else { k = b; g = a; } if (k < c)/*最小*/ { printf ("\n最小的数=%5.2f",k);} else {printf ("\n最小的数=%5.2f",c);} if (g > c)/*最大*/ {printf ("\n最大的数=%5.2f",g);} else {printf ("\n最大的数=%5.2f",c);} } 判断三角形的形状 #include #include void main(void) { printf("请输入三角形三边"); float a,b,c,p,s,k1,k2,k3; scanf("%f%f%f",&a,&b,&c); while (a + b < c || b + c < a || a + c < b ) { printf("不能构成三角形,请重新输入"); scanf("%f%f%f",&a,&b,&c); } k1 = a * a; k2 = b * b; k3 = c * c; if (a == b && b == c && c ==a) {printf("此三角形为等边三角形");} else if (a == b || b == c || c ==a) {printf("此三角形为等腰三角形"); } else if ((k1 == b * b + c * c) || (k2 == a * a + c * c) || (k3 = a * a + b * b)) {printf("此三角形为直角三角形");} else {printf("此三角形为一般三角形");} } 九九乘法表 整体 #include void main(void) { int i,j;

一些比较简c语言程序源代码

/**返回的long型的最大值是startLongValue+count-1(产生一个随机数) * param needCount * param count * param startLongValue * return */ public static List randomNoRepeatLongArray(int needCount,int count,long startLongValue){ //这种情况会出现无限循环的 if(needCount>count) return null; Random random = new Random(); int[] ints = new int[count]; for(int i=0;i list = new ArrayList(); while(list.size() #include #include

中国象棋源代码及文档

摘要 象棋程序可以分为两大部分:人工智能和界面程序辅助。人工智能的主要部分,反 映了计算机下象棋的想法,电脑怎么想,最好的方法去完成下一步,优先搜索算法进行 搜索,和各种可能的行动,评估,选择胜利面最大的一步;界面和程序协助部分主要是界 面友好,以更好地适应用户下象棋的想法。 本文研究了中国象棋在电脑中如何表示,然后讨论如何产生走法的一系列相关技术。使用MFC架构和Visual C + +开发工具,实现一定技能的中国象棋人机对弈功能。 关键词:中国象棋;人工智能;下棋

Title The Design And Realize of human-computer Chess Game Abstract Chess program can be divided into two major auxiliary artificial intelligence and interface program. The AI part of the main reflected computer chess ideas, computer how to think and go to the best method to complete the next step, first search algorithm to search, and a variety of possible moves, valuations, choose victory surface step; the interface and the program assisted some of the major user-friendly game of chess by the previous step, to better adjust the chess ideas. This paper studies the Chinese chess computer, and then discuss how to generate a series of related moves. MFC architecture and Visual C development tools, to achieve a certain chess skills, Chinese chess, human-computer chess program. Keywords: Chess; artificial intelligence; chess

C语言程序代码

1.编写一个C程序,输入a、b、c三个数,输出其中最大者。 #include "stdio.h" void main() { int paixu(int a,int b,int c); int a1,a2,a3,m; scanf("%d %d %d",&a1,&a2,&a3); m=paixu(a1,a2,a3); printf("%d",m); } int paixu(int a,int b,int c) { int max(int x,int y); int m; m=max(a,b); m=max(m,c); } int max(int x,int y) { if(x>y) return x; else return y; } 依次将10个数输入,要求将其中最大的数打印出来。 #include "stdio.h" void main() { int a[10],i,m; for(i=0;i<10;i++) scanf("%d",&a[i]); m=a[0]; for(i=1;i<10;i++) if(a[i]>m){m=a[i];} printf("最大数是:"); printf("%d\n",m); } 有3个数a、b、c,要求按从大到小的顺序把它们打印出来。 #include "stdio.h" void main() { int a[3]; int m,i,j; for(i=0;i<3;i++) scanf("%d",&a[i]); for(i=1;i<3;i++) for(j=0;ja[j]) {m=a[j];a[j]=a[i];a[i]=m;} printf("按由大到小排列:"); for(i=0;i<3;i++) printf("%d ",a[i]); } 求1+2+3+ (100) #include "stdio.h" void main() { int i,sum=0; for(i=1;i<=100;i++) { sum=sum+i; } printf("1+2+3+……+100=%d\n" ,sum); } 判断一个数n能否同时被3和5除。 #include "stdio.h" void main() { int a,b; printf("请输入一个整数\n"); scanf("%d",&a); if(a%3==0 && a%5==0) printf("能同时被3和5整除\n"); else printf("不能同时被3和5整除\n"); } 将100~200之间的素数打印出来。

java中国象棋报告

贵州航天职业技术学院Java课程设计报告 专业:计算机软件技术 班级:09软件二 学号:A093GZ053020152 姓名:韦治成 指导老师:肖宏启 时间:

目录 摘要 ------------------------------------------------------------------- 3【摘要】 ------------------------------------------------------------ 3【关键字】 --------------------------------------------------------- 4系统概述 ---------------------------------------------------------------- 4 1.棋盘表示 ---------------------------------------------------------- 4 3.人人对弈 ---------------------------------------------------------- 4系统分析 ---------------------------------------------------------------- 4 1. 设计内容--------------------------------------------------------- 4 2. 设计要求--------------------------------------------------------- 5 3.中国象棋软件-------------------------------------------------- 6 4.运行效果-------------------------------------------------------- 8系统设计 ---------------------------------------------------------------- 8 1.总体设计 ---------------------------------------------------------- 8 运行界面: ------------------------------------------------------- 10 2.运行输出结果 -------------------------------------------------- 10 3.总结与说明 ----------------------------------------------------- 11 4.象棋界面实现: ----------------------------------------------- 11 5.对弈功能的实现: -------------------------------------------- 15 参考文献 -------------------------------------------------------------- 16

Java扫雷游戏源代码

import java.awt.BorderLayout; import java.awt.Container; import java.awt.Font; import java.awt.GridLayout; import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JPanel; import javax.swing.Timer; public class ScanLei1 extends JFrame implements ActionListener{ private static final long serialVersionUID = 1L; private Container contentPane; private JButton btn; private JButton[] btns; private JLabel b1; private JLabel b2; private JLabel b3; private Timer timer; private int row=9; private int col=9; private int bon=10; private int[][] a; private int b; private int[] a1; private JPanel p,p1,p2,p3; public ScanLei1(String title){ super(title); contentPane=getContentPane(); setSize(297,377); this.setBounds(400, 100, 400, 500); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); timer =new Timer(1000,(ActionListener) this); a = new int[row+2][col+2];

C语言源程序

C语言程序设计 <一> 1、程序运行从main()函数开始,也从main()函数结束。 2、函数是C程序的基本单位,由函数头和函数体组成。 3、C语言源程序是由函数组成,它们的数目可以有多个。 4、在C语言源程序中,是必须有一个函数名为main的函数。main()后的小括号()没有任何内容,它不可以省略。 5、C程序中的语句用分号结束,在一个程序行上可以有多个语句,一个C 语句能写在多个程序行上。 6、函数体是由一对大括号围起来语句序列组成。小括号是函数的标志。 二、C语言的组成元素 1、命令、函数和变量等是组成程序的基本对象,每一个程序对象都需要一个名字来标识,程序对象的名称就是标识符。 2、在C语言中,标识符分为用户标识符和系统标识符。 3、用户标识符是指在程序中由程序员为变量、函数、数组等程序对象自行命名的标识符。 4、系统标识符是指C语言编译系统内部预定义的用于表示命令数据内型的标识符,又称保留字符。 5、基本字符集 英文字母:a~z和A~Z。 阿拉伯数字:0~9。其他字符:()、[]、+、-、*、/、%、<、>、<=、>=、==、!=、!、&&、‖、++、--、+=、-=、*=、/=、%=。它们是由1~2个字符组成。用作C语言的运算符;还包括:空格、换行符,回车符,单双引号,大括号,逗号,分号,反斜线,它们在程序中起到分隔和定界作用。 6、标识符:是用于标识命令;变量、函数,数组,数据类型等程序对象名称的字符序列。 7、组成标识符的合法字符有:字母,数字,下划线,三种,数字不能作首字符。 三、执行C语言程序 1、单击“开始”——“程序”——“附件”——“命令提示符”。 2、按功能键<10>激活菜单,执行“File”——“NEW”(ALT+回车)全屏。 3、为保存,输入程序文件名。 4、+运行 有输入:等待输入→回车 通过 无输入:返回到编辑 未通过:回车→F6→修改 F3(打开)

C语言知识学习程序源代码-中国象棋

#include #include #include #include #include #include"c:\tc\LIB\1.c" #define W 119 #define S 115 #define A 97 #define D 100 #define space 32 #define UP 72 #define DOWN 80 #define LEFT 75 #define RIGHT 77 #define ENTER 13 void qipan(); void jiemian(int); void guangbiao1(int,int); void guangbiao2(int,int);

void xuanzhong(int,int); void gaizi(int,int); char array(int,int); void xiazi(int,int,int,int); /*int panding(char,int,int,int,int);*/ main() { int gdriver,gmode,i=0,c=0,x=190,y=190,m,n; char p; FILE *fp; gdriver=DETECT; gmode=0; if((fp=fopen("file.txt","at")) == NULL) { printf("Cannot open file!"); system("pause"); exit(0); } printf("%d,%d",gdriver,gmode); registerbgidriver(EGAVGA_driver);

相关主题