正文

五子棋(人机对下)2007-10-02 21:22:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/vfdff/29795.html

分享到:

/***************************************************************************************\ modify at 2006.3.28 编译器:MYTC \***************************************************************************************/ #include #include #include #include #include #include #include #define MAX 15 #define OFFSET 8 /* 14*14=196>OFFSET; int id; struct LIST *newlist=malloc(sizeof(*newlist)); if(!newlist) return 1; while(tmp) { id=(tmp->id)>>OFFSET; if(idatemp) { temp=&(tmp->next); tmp=tmp->next; } } newlist->id=add; newlist->next=tmp; *temp=newlist; return 0; } /*函数获得指定链中最大优先级的值 */ static int GetMax(struct LIST *List) { if(List) return (List->id>>OFFSET); return 0; } static int GetLast(struct LIST **List) /*函数获得指定链中的链首数据 */ { if(*List) { int ret; struct LIST *temp; ret=((*List)->id& 0xff); /* 取低字节棋盘位置数据 , 0xff与OFFSET位数一致 */ temp=*List; /* 记住需要销毁的结点,使用的结点销毁 */ *List=(*List)->next; free(temp); return ret; } return 0; } #define DestroyList(L) while(GetLast(&L)) /*宏——销毁链表 */ /*函数探测参数tmp指定的棋盘位置的优先级并加入相应的链表中 */ /*凡进入该函数扫描的点,皆为棋盘上的空位置。我们将在此处分析该位置在棋局中的地位。*/ static int AddTo_List(int tmp) { int temp,py,px; py=tmp/MAX; px=tmp%MAX; /*探测计算机在此位置的优先级 ,tmp=y*MAX+x */ qp[py][px]=COMPUTER; temp=scan(px,py,0); /*最后一个参数必须为0,否则将进入死循环。 */ AddList(&CList,(tempMAX) side=1 ; else { x+=2 ; y+=2 ; for(j=0;j=0&&qp[y][x]==play); if(y+5>MAX) side=1 ; else { y+=2 ; for(j=0;j=0&&yMAX||y-5

阅读(4390) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册