// only set the column and two down diagnals inline void place(board*pb,int row,int col){ int i; for(i=row+1;i<=N;i++) setboard(pb,i,col); int c1=col,c2=col; for(i=row+1;i<=N;i++){ --c1; ++c2; if(inboard(i,c1)) setboard(pb,i,c1); if(inboard(i,c2)) setboard(pb,i,c2); } }
char *search(char *board, char me) { // 0 = black, 1 = white int i, j, x, y, p, q; char *best_board = board; int best_score = -49; int this_score; // choose a piece to investigate for (x=0; x<7; x++) for (y=0; y<7; y++) { if (getboard(board,x,y) != me) continue; // not my piece for (i=-2; i<=2; i++) for (j=-2; j<=2; j++) { char *new_board; if (i==0 && j==0) continue; if (!inboard(x+i,y+j)) continue; // not on the board if (getboard(board,x+i,y+j) != '-') continue; // not empty new_board = copy_board(board); if ((abs(i) > 1) || (abs(j) > 1)) // this is an extension setboard(new_board,x,y,'-'); setboard(new_board,x+i,y+j,me); // claim the surrounding squares for (p=-1; p<=1; p++) for (q=-1; q<=1; q++) { if (inboard(x+i+p,y+j+q) && (getboard(new_board,x+i+p,y+j+q) != '-')) setboard(new_board,x+i+p,y+j+q,me); } if (me == 'b') this_score = score(search(new_board,'w'),'b'); else this_score = 50 - score(new_board,'b'); if (this_score > best_score) { best_score = this_score; best_board = new_board; } } } return best_board; }
inline void check_board(int dir[][2], int moves, int sign, int r, int c) { for (int j = 0; j < moves; j++) { if (inboard(r + sign * dir[j][0], c + sign * dir[j][1]) && board[r + sign * dir[j][0]] [c + sign * dir[j][1]] != OCCUPIED) { board[r + sign * dir[j][0]] [c + sign * dir[j][1]] = ATTACKED; } } }
inline void check_board_across(int dir[][2], int moves, int r, int c) { for (int j = 0; j < moves; j++) { int k = 1; while (inboard(r + k * dir[j][0], c + k * dir[j][1]) && board[r + k * dir[j][0]] [c + k * dir[j][1]] != OCCUPIED) { board[r + k * dir[j][0]] [c + k * dir[j][1]] = ATTACKED; ++k; } } }
V3f v3i_to_v3f(V3i i) { V3f f; Block3 *b; assert(inboard(i)); b = block(i); f.x = (float)i.x * BLOCK_SIZE; f.y = (float)i.y * BLOCK_SIZE; f.z = (float)i.z * BLOCK_SIZE_2; if (b) { f.z += (BLOCK_SIZE_2 / BLOCK_HEIGHT) * (float)b->h; } return f; }
/// Gets the articulated body boost::shared_ptr<ARTICULATED_BODY> JOINT::get_articulated_body() { // get the inboard and outboard links boost::shared_ptr<RIGIDBODY> inboard(_inboard_link); boost::shared_ptr<RIGIDBODY> outboard(_outboard_link); // get the two articulated bodies boost::shared_ptr<ARTICULATED_BODY> abi = inboard->get_articulated_body(); boost::shared_ptr<ARTICULATED_BODY> abo = outboard->get_articulated_body(); // see whether the two bodies are equal if (abi == abo) return abi; else return boost::shared_ptr<ARTICULATED_BODY>(); }
void playing(int sockfd,User_List play_list[]){ point t1,t2; int i,j,t,a=0,x,y,rv; int luot,moved,predone; char *pch; char nick_name[LEN]; char mesg[LEN],mesg2[LEN]; char buff[LEN],buff1[LEN]="0",buff2[LEN]="0",buff3[LEN]="0"; fd_set readSet; struct timeval tv; if (blwh==1) luot=0; else luot=1; a=1; strcpy(you,play_list[0].nick_name); inboard(); while(1){ predone=0; tv.tv_sec = 0; tv.tv_usec =10000; FD_SET(sockfd, &readSet); FD_SET(fileno(stdin), &readSet); select(sockfd +1, &readSet, NULL, NULL, &tv); if(a>0){ // if (FD_ISSET(fileno(stdin), &readSet)) if (luot==0) {//Gui nuoc di if (blwh==1) { printf("Quan trang.\n"); } else printf("Quan den.\n"); printf("Hay nhap nuoc di (dang A3:B3): "); if(a==1){ while(1){ fgets(buff,LEN,stdin); if(buff[0]!='\n') break; } buff[strlen(buff)-1]='\0'; if(strlen(buff)==1 && ((buff[0]=='q') || (buff[0]=='Q'))) { strcpy(mesg,""); strcpy(mesg,"7|"); strcat(mesg,play_list[0].nick_name); strcpy(nick_name,play_list[0].nick_name); strcat(mesg,"|0|0|0|"); send(sockfd,mesg,strlen(mesg),0); printf("%s\n",you_lost); a = del_partner(nick_name,play_list); }else{ //Xu ly nuoc co trong buff moved=0; do{ t1.i=changenu(buff[1]); t1.j=changech(buff[0]); t2.i=changenu(buff[4]); t2.j=changech(buff[3]); // if (abs(board[t2.i][t2.j])==king) // { // predone=1; // } if ((blwh*board[t1.i][t1.j]>0)&(move(t1,t2)==1)) moved=1; else { printf("Nuoc di khong hop le.\n"); fgets(buff,LEN,stdin); if((buff[0]=='q') || (buff[0]=='Q')) { strcpy(mesg,""); strcpy(mesg,"7|"); strcat(mesg,play_list[0].nick_name); strcpy(nick_name,play_list[0].nick_name); strcat(mesg,"|0|0|0|"); send(sockfd,mesg,strlen(mesg),0); a = del_partner(nick_name,play_list); break; } } }while(moved==0); if (blwh==-1) strcpy(buff1,"-1"); else strcpy(buff1,"1"); inboard(); creat_mesg(6,play_list[0].nick_name,buff,buff1,buff2,mesg); send(sockfd,mesg,strlen(mesg),0); // //Thong bao ket thuc van co // if (predone && moved==1) // { // strcpy(mesg,""); // strcpy(mesg,"7|"); // strcat(mesg,play_list[0].nick_name); // strcpy(nick_name,play_list[0].nick_name); // strcat(mesg,"|1|0|0|"); // send(sockfd,mesg,strlen(mesg),0); // printf("%s\n",you_won); // a = del_partner(nick_name,play_list); // } } } FD_CLR(fileno(stdin), &readSet); } if (luot==1) // if (FD_ISSET(sockfd, &readSet)) {//Nhan duoc nuoc di predone=0; printf("Xin cho doi phuong di....\n"); strcpy(mesg,""); recv(sockfd,mesg,LEN,0); t=check_mark(mesg); if(t == 6){ strcpy(mesg2,mesg); pch=strtok(mesg2,"|"); pch=strtok(NULL,"|"); strcpy(nick_name,pch); pch=strtok(NULL,"|"); t1.i=changenu(pch[1]); t1.j=changech(pch[0]); t2.i=changenu(pch[4]); t2.j=changech(pch[3]); if (abs(board[t2.i][t2.j])==king) { predone=1; } if ((predone & move(t1,t2))==1) { inboard(); strcpy(mesg,""); strcpy(mesg,"7|"); strcat(mesg,play_list[0].nick_name); strcpy(nick_name,play_list[0].nick_name); strcat(mesg,"|1|0|0|"); send(sockfd,mesg,strlen(mesg),0); printf("%s\n",you_lost); a = del_partner(nick_name,play_list); } else inboard(); } if(t == 7) { strcpy(mesg2,mesg); pch=strtok(mesg2,"|"); pch=strtok(NULL,"|"); strcpy(nick_name,pch); a=del_partner(nick_name,play_list); strcpy(mesg2,mesg); pch=strtok(mesg2,"|"); pch=strtok(NULL,"|"); strcpy(nick_name,pch); pch=strtok(NULL,"|"); printf("%s\n",you_won); if (strcmp(pch,"0")==0) { printf("\n@%s da dung choi voi ban!!",nick_name); } } // if(t == 3){ // answer_request(sockfd,mesg,play_list); // a=0; // while(strcmp(play_list[a].nick_name,"") != 0 ){ // a++; // } // } FD_CLR(sockfd, &readSet); } luot=1 - luot; }else { printf("\nKet thuc!"); return; } } }