电脑下象棋是如何程式设计的

  象棋程式是让人跟电脑下棋的,下面我给你介绍,欢迎阅读。

  

  棋类游戏一般都能建立起数学模型,电脑做的只是判断这一步棋的下一步的每种可能走法,以及每种走法的下一步……以此类推,也就是说电脑能判断下一步怎么走,才能对自己在下下一步以致以后的多少步内都对自己有利。随着电脑预测的步数的增加,计算量成指数级增加,计算时间也会更长,这样除了棋类程式的演算法因素以外,考验的就是计算机的CPU计算速度了~所以要在电脑的“预测能力”和等待时间之间取一个折中的步数,比如20步。1997年IBM的“深蓝”战败世界棋王卡西帕罗夫,就是因为他的计算机的计算能力是当时世界顶尖的。

  中国象棋原始码-C语言小程式

  *--------------------che;#includedos.h;#includestdio.h&qu;/*----------------------;#defineRED7;#defineBLACK14;#definetrue1;#definefalse0;#defineSELECT0;#defineMOVE*--------------------chess.c----------------------*/#includedos.h#includestdio.h/*----------------------------------------------------*/#defineRED7#defineBLACK14#definetrue1#definefalse0#defineSELECT0#defineMOVE1#defineRED_UP0x1100#defineRED_DOWN0x1f00#defineRED_LEFT0x1e00#defineRED_RIGHT0x2000#defineRED_DO0x3900#defineRED_UNDO0x1000#defineBLACK_UP0x4800#defineBLACK_DOWN0x5000#defineBLACK_LEFT0x4b00#defineBLACK_RIGHT0x4d00#defineBLACK_DO0x1c00#defineBLACK_UNDO0x2b00#defineESCAPE0x0100#defineRED_JU1#defineRED_MA2#defineRED_XIANG3#defineRED_SHI4#defineRED_JIANG5#defineRED_PAO6#defineRED_BIN7#defineBLACK_JU8#defineBLACK_MA9#defineBLACK_XIANG10#defineBLACK_SHI11#defineBLACK_JIANG12#defineBLACK_PAO13#defineBLACK_BIN14/*----------------------------------------------------*/intfirsttime=1;intsavemode;charpage_new=0,page_old=0;intfinish=false,turn=BLACK,winner=0;intkey;intredstate=SELECT,blackstate=SELECT;intboard[10][9];/*----------------------------------------------------*/char*chessfile[15]={,bmp\\rju.wfb,bmp\\rma.wfb,bmp\\rxiang.wfb,bmp\\rshi.wfb,bmp\\rjiang.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.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.wfb,bmp\\108.wfb,bmp\\108.wfb,bmp\\109.wfb}};charcursor[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};structpos{intx;inty;}position[10][9],redcurpos,redtemppos,redoldpos,blackcurpos,blacktemppos,blackoldpos;/*----------------------------------------------------*/selectpage***registercharpage***/*换页函式*/{unionREGSr;r.x.ax=0x4f05;r.x.bx=0;r.x.dx=page;/*选择页面*/int86***0x10,&r,&r***;}unsignedcharset_SVGA_mode***intvmode***/*设定SVGA萤幕模式*/{unionREGSr;r.x.ax=0x4f02;r.x.bx=vmode;int86***0x10,&r,&r***;return***r.h.ah***;}unsignedintget_SVGA_mode******/*获取当前SVGA萤幕模式*/{unionREGSr;r.x.ax=0x4f03;int86***0x10,&r,&r***;return***r.x.bx***;}drawbmp***intstart_x,intstart_y,charfilename[]***{charbuffer[640];inti,j,k,n,r,g,b,width,length;longposition;FILE*fp;if******fp=fopen***filename,rb******==NULL***{printf***Error!Can'topenfile!***;getch******;return;}fseek***fp,28,SEEK_SET***;fread***&i,2,1,fp***;if***i!=8***/*检查是否为256色点阵图*/{puts***Error!Can'tfindbitmap!***;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>2***;/*右移是要转化为VGA的6位暂存器形式*/outportb***0x3c9,g>>2***;outportb***0x3c9,b>>2***;fgetc***fp***;}}elsefseek***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

免责声明:本站发布的游戏攻略(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场。
如果本文侵犯了您的权益,请联系站长邮箱进行举报反馈,一经查实,我们将在第一时间处理,感谢您对本站的关注!