ImageVerifierCode 换一换
格式:DOCX , 页数:32 ,大小:24.62KB ,
资源ID:5701085      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/5701085.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(黑白棋.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

黑白棋.docx

1、黑白棋C语言: 某黑白棋代码/othello by vilinov#include #include #include #include #define NONE 0#define BLACK 1#define WHITE 2#define DUMMY 3#define f(x,y) (x)*9+yvoiddraw();voidMoveGenerator(int deep);/*intgetnum();voidturn(int deep,int num);/*voidback(int deep);/*intAI();voidhelp();intcheck(int num);intCheckWa

2、y(int num);intSetLevel();voidEndGenerator(int deep);intHappyEnding(int deep);intBadEnding(int deep,int alpha,int beta);intEnding(int deep,int alpha,int beta);intsearch(int deep);intAlphaBeta(int deep,int alpha,int beta);intPVS(int deep,int alpha,int beta);intMAX_DEPTH=10;intEND_DEPTH=14;intcolour=BL

3、ACK;intcomputer=WHITE;intblack=2,white=2;intnote;charboard91= 3,3,3,3,3,3,3,3,3, 3,0,0,0,0,0,0,0,0, 3,0,0,0,0,0,0,0,0, 3,0,0,0,0,0,0,0,0, 3,0,0,0,2,1,0,0,0, 3,0,0,0,1,2,0,0,0, 3,0,0,0,0,0,0,0,0, 3,0,0,0,0,0,0,0,0, 3,0,0,0,0,0,0,0,0, 3,3,3,3,3,3,3,3,3,3;intdirection8=-10,-9,-8,-1,1,8,9,10;intvalue91=

4、 0,0,0,0,0,0,0,0,0, 0, 40,-8,4,3,3,4,-8, 40, 0,-8,-10,2,1,1,2,-10,-8, 0, 4, 2,3,1,1,3, 2, 4, 0, 3, 1,1,2,2,1, 1, 3, 0, 3, 1,1,2,2,1, 1, 3, 0, 4, 2,3,1,1,3, 2, 4, 0,-8,-10,2,1,1,2,-10,-8, 0, 40,-8,4,3,3,4,-8, 40, 0,0,0,0,0,0,0,0,0;intMoveList2030;intTurnList2010;/0-7 各方向上的吃子个数。8 num。9 总吃子个数intspace20

5、;/ENDing searchintflag20;intBestScore;intBestMove;intmove61=0,/这个零是“捣乱”的。说笑,为了一点点的效率提升/*C4*/31,32,58,59,39,42,48,51,/*C3*/30,33,57,60,/*A1*/10,17,73,80,/*A3*/12,15,75,78,28,35,55,62,/*A4*/13,14,76,77,37,44,46,53,/*B3*/21,24,66,69,29,34,56,61,/*B4*/22,23,67,68,38,43,47,52,/*A2*/11,16,74,79,19,26,64,7

6、1,/*B2*/20,25,65,70;intway;/check()&CheckWay()&turn()&back()intnow;/CheckWay()intcount;/CheckWay()inttemp;/MoveGenerator()&turn()&back()&AI()&G()clock_ttime1,time2;voidNEW() colour=BLACK; computer=WHITE; black=2,white=2; int x,y; for(x=0;x91;x+) boardx=3; for(x=1;x9;x+) for(y=1;y9;y+) boardf(x,y)=0;

7、 boardf(4,4)=2; boardf(5,5)=2; boardf(4,5)=1; boardf(5,4)=1;voiddraw() int x,y; printf( 12345678); for(x=1;x9;x+) printf(n%c,(char)x-1+a); for(y=1;y0;temp-) if(check(movetemp) MoveListdeep +MoveListdeep0 =movetemp; return;intcheck(int num) if(boardnum) return 0; for(way=7;way=0;way-) if(CheckWay(num

8、) return 1; return 0;intCheckWay(int num) count=0; for(now=num+directionway; boardnow&boardnow!=DUMMY;now+=directionway ) if(boardnow=colour) return count; count+; return 0;voidturn(int deep,int num) TurnListdeep9=0; for(way=7;way=0;way-) temp=CheckWay(num); TurnListdeepway=temp; TurnListdeep9+=temp

9、; for(now=num+directionway;temp0;temp-,now+=directionway) boardnow=colour; TurnListdeep8=num; boardnum=colour; if(colour=WHITE) white+=TurnListdeep9+1; black-=TurnListdeep9; else white-=TurnListdeep9; black+=TurnListdeep9+1; return;voidback(int deep) int temp2=3-colour,num=TurnListdeep8; for(way=7;w

10、ay=0;way-) for(temp=TurnListdeepway,now=num+directionway;temp0;temp-,now+=directionway) board now =temp2; board num =NONE; if(colour=WHITE) white-=TurnListdeep9+1; black+=TurnListdeep9; else white+=TurnListdeep9; black-=TurnListdeep9+1; return;intgetnum() char s30; int lenS; int num; for(;) if(colou

11、r=computer) return AI(); printf(); scanf(%s,s); lenS=strlen(s); if(lenS=2) if(s0=a&s0=1&s1=8) num=f(s0-a+1,s1-1+1); if(check(num) return num; if(lenS=1) if(s0=q) exit(2); if(s0=h) help(); if(s0=c) computer=3-computer; if(s0=s) computer=1-computer; if(s0=d) draw(); if(s0=n) return 0; if(s0=l) SetLeve

12、l(); if(lenS=4&!strcmp(exit,s) exit(2); if(lenS=4&!strcmp(help,s) help(); if(lenS=4&!strcmp(draw,s) draw(); if(lenS=3&!strcmp(new,s) return 0; if(lenS=5&!strcmp(level,s) SetLevel(); intSetLevel() char c; printf(当前中盘搜索深度%d层,终盘搜索深度%d层n,MAX_DEPTH,END_DEPTH); while(1) printf(设置中盘搜索深度(1-12):); scanf(%d,&

13、MAX_DEPTH); if (feof(stdin) | ferror(stdin) printf(n输入错误n); exit(2); while ( (c = getchar() != n & c != EOF ) ; if(MAX_DEPTH12) continue; break; ; while(1) printf(设置尾盘搜索深度(1-16):); scanf(%d,&END_DEPTH); if (feof(stdin) | ferror(stdin) printf(n输入错误n); exit(2); while ( (c = getchar() != n & c != EOF )

14、 ; if(END_DEPTH16) continue; break; ; return 0;voidhelp() printf(-HELP-n); printf(h,help 帮助n); printf(a1.h8 棋子地点n); printf(q,exit 退出n); printf(d,draw 画出棋盘n); printf(n,new 重新开始n); printf(l,level 设置等级n); printf(c 让步n); printf(s 双人下棋(再按一次则返回人机)n); printf(-END-n); return;intAI() space0=64-white-black; m

15、emset(flag,0,sizeof(flag); if(space0END_DEPTH) return search(MAX_DEPTH); space0=0; for(temp=60;temp0;temp-) if(!board movetemp ) space +space0 =movetemp; return HappyEnding(space0);/o(_)ointG() int val=0; for(temp=10;temp0;temp-) if(check(spacetemp) MoveListdeep +MoveListdeep0 =spacetemp; return;int

16、HappyEnding(int deep) int score; note+; EndGenerator(deep); /the first note turn(deep,MoveListdeep MoveListdeep0 ); BestScore=-Ending(deep-1,-65,65); BestMove=MoveListdeep MoveListdeep0 ; back(deep); MoveListdeep0-; /first note end for(;MoveListdeep00;MoveListdeep0-) turn(deep,MoveListdeep MoveListd

17、eep0 ); score=-BadEnding(deep-1,-BestScore-1,-BestScore); if(scoreBestScore) BestScore=-Ending(deep-1,-65,-score); BestMove=MoveListdeep MoveListdeep0 ; back(deep); return BestMove;intBadEnding(int deep,int alpha,int beta) int current=-65,score; note+; if(!deep) if(colour=WHITE) return black-white;

18、else return white-black; colour=3-colour; EndGenerator(deep); if(!MoveListdeep0)/no move if(flagdeep)/game over if(colour=WHITE) colour=3-colour; return white-black; else colour=3-colour; return black-white; /让步英语怎么说? flagdeep=1; score=-BadEnding(deep,-beta,-alpha); flagdeep=0; colour=3-colour; retu

19、rn score; for(;MoveListdeep00;MoveListdeep0-) turn(deep,MoveListdeep MoveListdeep0 ); score=-BadEnding(deep-1,-beta,-alpha); back(deep); if(scorecurrent) current=score; if(score=beta) break; colour=3-colour; return current;intEnding(int deep,int alpha,int beta) int best,score; note+; if(!deep) if(co

20、lour=WHITE) return black-white; else return white-black; colour=3-colour; EndGenerator(deep); if(!MoveListdeep0)/no move if(flagdeep)/game over if(colour=WHITE) colour=3-colour; return white-black; else colour=3-colour; return black-white; /让步 flagdeep=1; score=-Ending(deep,-beta,-alpha); flagdeep=0

21、; colour=3-colour; return score; /first note turn(deep,MoveListdeep MoveListdeep0 ); best=-Ending(deep-1,-beta,-alpha); back(deep); MoveListdeep0-; /note end for(;MoveListdeep00;MoveListdeep0-) if(bestalpha) alpha=best; turn(deep,MoveListdeep MoveListdeep0 ); score=-BadEnding(deep-1,-alpha-1,-alpha)

22、; if(scorealpha&scorebest) best=score; back(deep); colour=3-colour; return best;/eNDing eND/searchintsearch(int deep) int score; note+; MoveGenerator(deep); /the first note turn(deep,MoveListdeep MoveListdeep0 ); BestScore=-PVS(deep-1,-32767,32767); BestMove=MoveListdeep MoveListdeep0 ; back(deep);

23、MoveListdeep0-; /first note end for(;MoveListdeep00;MoveListdeep0-) turn(deep,MoveListdeep MoveListdeep0 ); score=-AlphaBeta(deep-1,-BestScore-1,-BestScore); if(scoreBestScore) BestScore=-PVS(deep-1,-32767,-score); BestMove=MoveListdeep MoveListdeep0 ; back(deep); return BestMove;intAlphaBeta(int de

24、ep,int alpha,int beta) int current=-32767,score; note+; if(!deep) if(colour=WHITE) return -G(); else return G(); colour=3-colour; MoveGenerator(deep); if(!MoveListdeep0)/no move if(flagdeep)/game over if(colour=WHITE) colour=3-colour; return G(); else colour=3-colour; return -G(); /让步英语怎么说? flagdeep

25、=1; score=-AlphaBeta(deep,-beta,-alpha); flagdeep=0; colour=3-colour; return score; for(;MoveListdeep00;MoveListdeep0-) turn(deep,MoveListdeep MoveListdeep0 ); score=-AlphaBeta(deep-1,-beta,-alpha); back(deep); if(scorecurrent) current=score; if(score=beta) break; colour=3-colour; return current;intPVS(int deep,int alpha,int beta) int best,

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1