static int think(int race) { int i,j,k=0; int da_x=0,da_y,da_v=0,tmp; int haha[442][3]; haha[0][0]=0; for(i=1;i<22;i++) for(j=1;j<22;j++) { /* enemy's situation */ tmp=value(i,j,abs(race-2)+1); if(tmp>da_v) {da_x=i; da_y=j; da_v=tmp;} /* mine */ tmp=value(i,j,race); if(tmp>haha[k][0]) { k=0; haha[0][0]=tmp; haha[0][1]=i; haha[0][2]=j; } else if(tmp==haha[k][0]) { k++; haha[k][0]=tmp; haha[k][1]=i; haha[k][2]=j; } } i=random()%(k+1); gotoxy(63,15); if(haha[i][0]>7) bell(); m=haha[i][1]; n=haha[i][2]; if((da_v>haha[i][0])||(da_v==haha[i][0]&&!attack[race])) {m=da_x; n=da_y;} put_box(mm,nn,0); put_box(m,n,race); mm=m; nn=n; gotoxy(48,15); prints("目前位置(%2d,%2d)",m,n); return put_chess(m,n,race); }
static int __load_tree(TREE *tree, FILE *fp, cmp_box *cmp, size_t n) { size_t size; void *tmp; while (n--) { fread(&size, sizeof(size), 1, fp); if ((tmp = malloc(size)) == NULL) return -1; fread(tmp, size, 1, fp); if (put_box(tree, tmp, size, cmp) == -1) return -1; free(tmp); } return 0; }
static int fplayer(int race) { int l; while(-1) { gotoxy(48,15); prints("目前位置(%2d,%2d)",m,n); put_box(mm,nn,0); put_box(m,n,race); mm=m; nn=n; l=igetkey(); switch(l) { // case '1': case '2': if(role[l-'1']==1) { role[l-'1']=2; attack[l-'1']=0; } else if(attack[l-'1']==0) attack[l-'1']=1; else role[l-'1']=1; who(l-'1'); break; case 'q': return 2; case 'r': return 1; case 'b': if(sum>2) { int i; for(i=0;i<2;i++) { int x=repent[sum-1][1],y=repent[sum-1][2]; put_chess(x,y,0); move(y+1,x*2); outs("┼"); sum-=2; } for(i=sum;i>=sum-5;i--) { gotoxy(48,i-sum+13); if(i>0) prints("第%d步: %s (%2d,%2d) ",i,(repent[i-1][0]==1)?"●":"○", repent[i-1][1],repent[i-1][2]); else outs(" "); } } break; case ' ': if(!chess[m-1][n-1]) { int hk=put_chess(m,n,race); if(hk) { int dk = show_win(hk); if(dk=='n'||dk=='q') return 2; return 1; } return 0; } break; case KEY_DOWN: //down if(legal(m,n+1)) n++; break; case KEY_UP: //up if(legal(m,n-1)) n--; break; case KEY_RIGHT: //right if(legal(m+1,n)) m++; break; case KEY_LEFT: //left if(legal(m-1,n)) m--; break; } } }