Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of project by
main.cpp
00001 /******************************************************************************/ 00002 /* This Nicleo is state 0 */ 00003 /******************************************************************************/ 00004 #include "mbed.h" 00005 #include "ColorMbed.h" 00006 00007 // Setting 00008 int ifUrJirat = 1; 00009 00010 // Initail I/O. 00011 AnalogIn VRx(A0); 00012 AnalogIn VRy(A1); 00013 DigitalIn Button(PA_4); 00014 Serial bt(PA_15, PB_7); 00015 ColorMbed dotmatrix; 00016 00017 // Initial function. 00018 char posit2char(int posit); 00019 char check_joys(int jx,int jy); 00020 int IamWin(); 00021 int TellUrEnemy_uWin(); 00022 int char2posit(char cha); 00023 int check_joys_int(int jx,int jy); 00024 int check_correctPosition(int X,int Y); 00025 int protect_ship(int head_position,int ship_type); 00026 int get_ship_platform(int input_position,int ship_type); 00027 void atk_enemy(); 00028 void enemy_atk(); 00029 void check_end(); 00030 void check_ready(); 00031 void mark_ship_destroyed(); 00032 void Select_Position(char M,int SetOrPlay); 00033 void get_atk_platform(int atkpos); 00034 00035 //inessential 00036 void print_ship_destroyed(); 00037 void print_enemy_platform(); 00038 void print_ship_platform(); 00039 void print_atk_platform(); 00040 00041 // Nasarun's function. 00042 int _power(int number , int power); 00043 void hex_to_array(int* ar); 00044 void place_ship3(char dir); 00045 void array_to_hex(int ar1[8][8]); 00046 void place_ship2_4(int ship,char dir); 00047 void ch_same_position(int ar1[8][8],int ar2[8][8]); 00048 void discard_same_position(int ar1[8][8],int ar2[8][8]); 00049 00050 // Initial variable. 00051 int check_ship_underATK = 0; 00052 int select_Position = 0; 00053 int ATKposition = 0; 00054 int enemy_ready = 0; 00055 int check_ship1 = 0; 00056 int check_ship2 = 0; 00057 int iShipType = 0; 00058 int iWaitATK = 0; 00059 int check_win = 0; 00060 int state = 0; 00061 int ship_SelectType[8] = {4,3,2,2,1,1,1,1}; 00062 int enemy_platform[8][8] = {{0}}; 00063 int ship_platform[8][8] = {{0}}; //______________________________________________This is ship area. 00064 int atk_platform[8][8] = {{0}}; 00065 int ship_underATK[15] = {9,9,9,9,9,9,9,9,9,9,9,9,9,9,9}; 00066 int ship_destroyed[8] = {0}; 00067 int ship4[4] = {0}; 00068 int ship3[3] = {0}; 00069 int ship2[2][2] = {{0}}; 00070 int ship1[4] = {0}; 00071 //fuction nasrun 00072 int return_position[8][8] ; 00073 int for_hex = 0; 00074 int ch_post[8][8] = {{1,1,1,1,1,1,1,1}, 00075 {1,1,1,1,1,1,1,1}, 00076 {1,1,1,1,1,1,1,1}, 00077 {1,1,1,1,1,1,1,1}, 00078 {1,1,1,1,1,1,1,1}, 00079 {1,1,1,1,1,1,1,1}, 00080 {1,1,1,1,1,1,1,1}, 00081 {1,1,1,1,1,1,1,1}}; 00082 int return_hex[8]; 00083 int display_battle[8][8][3] = {0}; 00084 int _temppic[8] = {0x01,0x01,0x01,0x01,0,0,0,0}; 00085 int temppic2[8] = {0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; 00086 int temppic3[7][8] = {{0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00},{0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00},{0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00},{0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00},{0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00},{0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00},{0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}; 00087 int temppic4[8] = {0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; 00088 int forshift[8] = {0}; 00089 int pic[8] = {0}; 00090 int i,j; 00091 int check_boat3=0; 00092 int check_hex=0; 00093 00094 // function Test! 00095 int main(){ //-------------------------------------------------------------------Main Function. 00096 bt.baud(9600); 00097 float Vx; 00098 float Vy; 00099 int SW,iVxVy,iSW,n = 0; 00100 int uli = 0; 00101 char m; 00102 int rgb[3] = {60,0,0}; 00103 int state_place_ship = 0; 00104 dotmatrix.init(); 00105 00106 while(1) { 00107 dotmatrix.display_pic(_temppic,rgb); 00108 if(iShipType<8){ 00109 Vx = VRx.read() * 1024; 00110 Vy = VRy.read() * 1024; 00111 SW = Button.read(); 00112 m = check_joys(Vx,Vy); 00113 n = check_joys_int(Vx,Vy); 00114 if(n == 1){ //_______________________________________________________ For make sure coordinate is press 1 time. 00115 iVxVy = 0; 00116 check_ready(); 00117 } 00118 if(SW == 1){ //______________________________________________________ For make sure switch is press 1 time. 00119 iSW = 0; 00120 check_ready(); 00121 } 00122 if(m!=NULL && iVxVy==0){ //__________________________________________ Get position that wait for press switch. 00123 Select_Position(m,0); 00124 if(state_place_ship == 0){ 00125 place_ship2_4(0,m); // 4 00126 } 00127 else if(state_place_ship == 1){ 00128 place_ship3(m); // 3 00129 } 00130 else if(state_place_ship == 2){ 00131 place_ship2_4(1,m); // 2 00132 } 00133 else if(state_place_ship == 3){ 00134 place_ship2_4(2,m); //2 00135 } 00136 else if(state_place_ship == 4){ 00137 place_ship2_4(3,m); // 1 00138 } 00139 else if(state_place_ship == 5){ 00140 place_ship2_4(4,m); // 1 00141 } 00142 else if(state_place_ship == 6){ 00143 place_ship2_4(5,m); // 1 00144 } 00145 else if(state_place_ship == 7){ 00146 place_ship2_4(6,m); // 1 00147 } 00148 printf("select_Position = %d\n",select_Position); 00149 check_ready(); 00150 iVxVy = 1; 00151 check_ready(); 00152 } 00153 if(SW==0 && iSW==0){ //______________________________________________If switch pressing by human. 00154 printf("Wait!\n"); 00155 00156 check_ready(); 00157 if(get_ship_platform(select_Position,ship_SelectType[iShipType])==0){ //__Please read explanation in function get_ship_platform. 00158 printf("Please input correct position\n"); 00159 }else{ 00160 iShipType++; 00161 if(state_place_ship == 0){ 00162 for(j=0;j<8;j++){ 00163 printf("state_place_ship == 0 ++\n"); 00164 pic[j] = temppic3[0][j]+pic[j]; 00165 } 00166 } 00167 else if(state_place_ship == 1){ 00168 for(j=0;j<8;j++){ 00169 printf("state_place_ship == 1 ++\n"); 00170 pic[j] = temppic2[j]+pic[j]; 00171 } 00172 } 00173 else if(state_place_ship == 2){ 00174 for(j=0;j<8;j++){ 00175 printf("state_place_ship == 2 ++\n"); 00176 pic[j] = temppic3[1][j]+pic[j]; 00177 } 00178 } 00179 else if(state_place_ship == 3){ 00180 for(j=0;j<8;j++){ 00181 printf("state_place_ship == 3 ++\n"); 00182 pic[j] = temppic3[2][j]+pic[j]; 00183 } 00184 } 00185 else if(state_place_ship == 4){ 00186 for(j=0;j<8;j++){ 00187 printf("state_place_ship == 4 ++\n"); 00188 pic[j] = temppic3[3][j]+pic[j]; 00189 } 00190 } 00191 else if(state_place_ship == 5){ 00192 for(j=0;j<8;j++){ 00193 printf("state_place_ship == 5 ++\n"); 00194 pic[j] = temppic3[4][j]+pic[j]; 00195 } 00196 } 00197 else if(state_place_ship == 6){ 00198 for(j=0;j<8;j++){ 00199 printf("state_place_ship == 6 ++\n"); 00200 pic[j] = temppic3[5][j]+pic[j]; 00201 } 00202 } 00203 else if(state_place_ship == 7){ 00204 for(j=0;j<8;j++){ 00205 printf("state_place_ship == 7 ++\n"); 00206 pic[j] = temppic3[6][j]+pic[j]; 00207 } 00208 } 00209 state_place_ship = state_place_ship + 1; 00210 select_Position = 0; 00211 } 00212 check_ready(); 00213 iSW = 1; 00214 print_ship_platform(); 00215 check_ready(); 00216 } 00217 }else{ 00218 if(enemy_ready!=1){ 00219 printf("sent E\n"); 00220 while(uli<50){ 00221 bt.printf("E"); 00222 uli++; 00223 } 00224 }else{ 00225 bt.putc('l'); 00226 } 00227 printf("\n"); 00228 break; 00229 } 00230 } 00231 if(enemy_ready == 0){ 00232 printf("Wait for enemy\n"); 00233 while(1){if(bt.readable()){if(bt.getc()=='l'){break;}}} 00234 state = 0; 00235 }else{state = 1;} 00236 wait(5); 00237 while(1) { //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Play 00238 if(state == 0){ 00239 atk_enemy(); 00240 printf("This is enemy_platform.\n"); 00241 print_enemy_platform(); 00242 state = 1; 00243 }else{ 00244 enemy_atk(); 00245 if(check_win==1){ 00246 printf("BOO!! You Win!\n"); 00247 break; 00248 } 00249 printf("This is atk_platform.\n"); 00250 print_atk_platform(); 00251 printf("This is ship_destroyed. : "); 00252 print_ship_destroyed(); 00253 if(TellUrEnemy_uWin()==1){ 00254 while(uli<100){ 00255 bt.putc('q'); 00256 uli++; 00257 } 00258 printf("BOO!! You lost!\n"); 00259 break; 00260 }else{state = 0;} 00261 } 00262 } 00263 while(1){printf("END\n");wait(1);} 00264 } 00265 00266 /******************************************************************************/ 00267 /* */ 00268 /* */ 00269 /* Another function */ 00270 /* */ 00271 /* */ 00272 /******************************************************************************/ 00273 00274 char check_joys(int jx,int jy){ //-----------------------------------------------Check joystick that it up,down,left or right. 00275 00276 if(ifUrJirat==1){ 00277 if(jx < 14.0){ return 'a';} 00278 else if(jx > 1010.0){return 'd';} 00279 else if(jy < 14.0){ return 'w';} 00280 else if(jy > 1010.0){return 's';} 00281 else{return NULL;} 00282 }else{ 00283 if(jx < 14.0){ return 'd';} 00284 else if(jx > 1010.0){return 'a';} 00285 else if(jy < 14.0){ return 's';} 00286 else if(jy > 1010.0){return 'w';} 00287 else{return NULL;} 00288 } 00289 } 00290 int check_joys_int(int jx,int jy){ //--------------------------------------------Check joystick that it is centre. 00291 if(jx>=450.0&&jx<=600.0){ 00292 if(jy>=450.0&&jy<=600.0){ 00293 return 1; 00294 }else{ 00295 return 0; 00296 } 00297 }else{ 00298 return 0; 00299 } 00300 } 00301 void Select_Position(char M,int SetOrPlay){ //-------------------------------------------------Change position of cursor (Joystick). 00302 int protect_ships; 00303 protect_ships = protect_ship(select_Position,ship_SelectType[iShipType]); 00304 switch(M){ 00305 case 'a': 00306 if(select_Position%10!=0){ 00307 select_Position = select_Position - 1; 00308 } 00309 break; 00310 case 'd': 00311 if(select_Position%10!=7){ 00312 if(protect_ships==1 or protect_ships==0){ 00313 select_Position = select_Position + 1; 00314 } 00315 if(SetOrPlay==1){ 00316 select_Position = select_Position + 1; 00317 } 00318 } 00319 break; 00320 case 'w': 00321 if(select_Position/10!=0){ 00322 select_Position = select_Position - 10; 00323 } 00324 break; 00325 case 's': 00326 if(select_Position/10!=7){ 00327 if(protect_ships==1 or protect_ships==2){ 00328 select_Position = select_Position + 10; 00329 } 00330 if(SetOrPlay==1){ 00331 select_Position = select_Position + 10; 00332 } 00333 } 00334 break; 00335 } 00336 } 00337 int protect_ship(int head_position,int ship_type){ 00338 int x,y = 0; 00339 y = head_position/10; 00340 x = head_position%10; 00341 if(ship_type==4){if((y+4)>7){return 0;}else{return 1;}} 00342 else if(ship_type==3){if((x+3)>7){return 2;}else{return 1;}} 00343 else if(ship_type==2){if((y+2)>7){return 0;}else{return 1;}} 00344 else{return 1;} 00345 } 00346 int get_ship_platform(int input_position,int ship_type){ //-----------------------Plot ship in ship area. 00347 int i,x,y = 0; 00348 int error = 0; 00349 00350 y = input_position/10; 00351 x = input_position%10; 00352 00353 for(i=0;i<ship_type;i++){ 00354 if(check_correctPosition(y,x) == 1){ 00355 if(ship_type == 4){ship4[i] = (y*10)+x;} 00356 else if(ship_type == 3){ship3[i] = (y*10)+x;} 00357 else if(ship_type == 2){ship2[check_ship2][i] = (y*10)+x;} 00358 else if(ship_type == 1){ship1[check_ship1] = (y*10)+x;check_ship1++;} 00359 }else{error = 1;break;} 00360 if(ship_type%2 == 0){y++;}else{x++;} 00361 } 00362 if(ship_type==2){check_ship2++;} 00363 if(error == 1){return 0;}else{ 00364 y = input_position/10; 00365 x = input_position%10; 00366 for(i=0;i<ship_type;i++){ 00367 ship_platform[y][x] = ship_type; 00368 if(ship_type%2 == 0){y++;}else{x++;} 00369 } 00370 return 1; 00371 } 00372 } 00373 int check_correctPosition(int X,int Y){ 00374 if(X<=7){ 00375 if(Y<=7){ 00376 if(ship_platform[X][Y] == 0){return 1;}else{return 0;} 00377 }else{return 0;} 00378 }else{return 0;} 00379 } 00380 void print_ship_platform(){ 00381 for(int i=0;i<8;i++){ 00382 for(int j=0;j<8;j++){ 00383 printf("| %d |",ship_platform[i][j]); 00384 } 00385 printf("\n"); 00386 } 00387 } 00388 void print_enemy_platform(){ 00389 for(int i=0;i<8;i++){ 00390 for(int j=0;j<8;j++){ 00391 printf("| %d |",enemy_platform[i][j]); 00392 } 00393 printf("\n"); 00394 } 00395 } 00396 void print_atk_platform(){ 00397 for(int i=0;i<8;i++){ 00398 for(int j=0;j<8;j++){ 00399 printf("| %d |",atk_platform[i][j]); 00400 } 00401 printf("\n"); 00402 } 00403 } 00404 void print_ship_destroyed(){ 00405 printf("{"); 00406 for(int i=0;i<8;i++){ 00407 printf("%d",ship_destroyed[i]); 00408 if(i!=14){printf(",");} 00409 } 00410 printf("}\n"); 00411 } 00412 void check_ready(){ 00413 if(bt.readable()){enemy_ready = 1;} 00414 } 00415 char posit2char(int posit){ 00416 int as = posit+48; 00417 char ch = as; 00418 return ch ; 00419 } 00420 int char2posit(char cha){ 00421 int as = cha; 00422 as = as-48; 00423 return as; 00424 } 00425 void get_atk_platform(int atkpos){ 00426 int i,j,x,y = 0; 00427 00428 x = atkpos/10; 00429 y = atkpos%10; 00430 00431 if(ship_platform[x][y]!=0 and atk_platform[x][y]==0){ 00432 atk_platform[x][y] = ship_platform[x][y]; 00433 bt.putc(posit2char(atk_platform[x][y])); 00434 ship_underATK[check_ship_underATK] = (x*10)+y; 00435 if(atk_platform[x][y]==4){ 00436 for(i=0;i<4;i++){ 00437 for(j=0;j<15;j++){ 00438 if(ship4[i]==ship_underATK[j]){ship_destroyed[0]++;} 00439 } 00440 } 00441 }else if(atk_platform[x][y]==3){ 00442 for(i=0;i<3;i++){ 00443 for(j=0;j<15;j++){ 00444 if(ship3[i]==ship_underATK[j]){ship_destroyed[1]++;} 00445 } 00446 } 00447 }else if(atk_platform[x][y]==2){ 00448 for(i=0;i<4;i++){ 00449 for(j=0;j<15;j++){ 00450 if(ship2[0][i]==ship_underATK[j]){ship_destroyed[2]++;} 00451 if(ship2[1][i]==ship_underATK[j]){ship_destroyed[3]++;} 00452 } 00453 } 00454 }else if(atk_platform[x][y]==1){ 00455 for(i=0;i<4;i++){ 00456 for(j=0;j<15;j++){ 00457 if(ship3[i]==ship_underATK[j]){ 00458 ship_destroyed[4+i]++; 00459 atk_platform[x][y] = 11; 00460 } 00461 } 00462 } 00463 } 00464 }else{ 00465 atk_platform[x][y] = 8; 00466 bt.putc(posit2char(atk_platform[x][y])); 00467 } 00468 } 00469 void mark_ship_destroyed(){ 00470 int i,j,k = 0; 00471 00472 if(ship_destroyed[0]==10){ 00473 for(i=0;i<8;i++){ 00474 for(j=0;j<8;j++){ 00475 if(atk_platform[i][j]==4){atk_platform[i][j] = 11;} 00476 } 00477 } 00478 } 00479 if(ship_destroyed[1]==6){ 00480 for(i=0;i<8;i++){ 00481 for(j=0;j<8;j++){ 00482 if(atk_platform[i][j]==3){atk_platform[i][j] = 11;} 00483 } 00484 } 00485 } 00486 if(ship_destroyed[2]==3){ 00487 for(k=0;k<2;k++){ 00488 i = ship2[0][k]/10; 00489 j = ship2[0][k]%10; 00490 atk_platform[i][j] = 11; 00491 } 00492 } 00493 if(ship_destroyed[3]==3){ 00494 for(k=0;k<2;k++){ 00495 i = ship2[1][k]/10; 00496 j = ship2[1][k]%10; 00497 atk_platform[i][j] = 11; 00498 } 00499 } 00500 } 00501 void atk_enemy(){ 00502 float Vx; 00503 float Vy; 00504 int SW,iVxVy,iSW,n = 0; 00505 int iPrintUturn = 0; 00506 char m; 00507 00508 select_Position = 0; 00509 while(1){ 00510 if(iPrintUturn==0){ 00511 printf("Your turn.\n"); 00512 iPrintUturn = 1; 00513 } 00514 Vx = VRx.read() * 1024; 00515 Vy = VRy.read() * 1024; 00516 SW = Button.read(); 00517 m = check_joys(Vx,Vy); 00518 n = check_joys_int(Vx,Vy); 00519 if(n == 1){ iVxVy = 0;} 00520 if(SW == 1){ 00521 iSW = 0; 00522 if(bt.readable()){ 00523 enemy_platform[select_Position/10][select_Position%10] = char2posit(bt.getc()); 00524 break; 00525 } 00526 } 00527 if(m!=NULL && iVxVy==0){ 00528 Select_Position(m,1); 00529 printf("select_Position = %d\n",select_Position); 00530 bt.putc(posit2char(select_Position)); 00531 iVxVy = 1; 00532 } 00533 if(SW==0 && iSW==0){ 00534 bt.putc('B'); 00535 printf("You attacking at position %d\n",select_Position); 00536 iSW = 1; 00537 } 00538 } 00539 } 00540 void enemy_atk(){ 00541 int data_fromEnemy; 00542 char replica_data_fromEnemy; 00543 printf("Wait for enemy attack.\n"); 00544 select_Position = 0; 00545 while(1){ 00546 if(bt.readable()){ 00547 replica_data_fromEnemy = bt.getc(); 00548 if(replica_data_fromEnemy!='q' and replica_data_fromEnemy!=8){ 00549 data_fromEnemy = char2posit(replica_data_fromEnemy); 00550 if(data_fromEnemy!=18){ 00551 select_Position = data_fromEnemy; 00552 printf("enemy select_Position = %d\n",select_Position); 00553 }else{ 00554 ATKposition = select_Position; 00555 break; 00556 } 00557 } 00558 if(replica_data_fromEnemy=='q'){ 00559 check_win = 1; 00560 break; 00561 } 00562 } 00563 } 00564 if(check_win!=1){ 00565 printf("Enemy attack at your area %d\n",ATKposition); 00566 get_atk_platform(ATKposition); 00567 check_ship_underATK++; 00568 mark_ship_destroyed(); 00569 } 00570 } 00571 int TellUrEnemy_uWin(){ 00572 int sub_end = 0; 00573 00574 for(int i=0;i<15;i++){ 00575 if(ship_underATK[i]!=9){sub_end++;} 00576 } 00577 if(sub_end==15){return 1;}else{return 0;} 00578 } 00579 int IamWin(){ 00580 char chare; 00581 if(bt.readable()){ 00582 chare = bt.getc(); 00583 if(chare=='q'){return 1;}else{return 0;} 00584 }else{return 0;} 00585 } 00586 00587 // ______________________________________________________________________________Nasarun's function. 00588 00589 void hex_to_array(int* ar){ 00590 int i; 00591 int j; 00592 int temp; 00593 for(i = 0;i<8;i++){ 00594 temp = ar[i]; 00595 for(j = 0;j<8;j++){ 00596 if(0x80 & temp){ 00597 return_position[i][j] = 1; 00598 } 00599 else{ 00600 return_position[i][j] = 0; 00601 } 00602 temp = temp << 1; 00603 } 00604 } 00605 } 00606 00607 void ch_same_position(int ar1[8][8],int ar2[8][8]){ 00608 int i; 00609 int j; 00610 for(i = 0;i<8;i++){ 00611 for(j = 0;j<8;j++){ 00612 if(ar1[i][j] == 1 && ar2[i][j] == 1){ 00613 ch_post[i][j] = 1; 00614 } 00615 else{ 00616 ch_post[i][j] = 0; 00617 } 00618 } 00619 } 00620 00621 } 00622 00623 void discard_same_position(int ar1[8][8],int ar2[8][8]){ 00624 int i; 00625 int j; 00626 for(i = 0;i<8;i++){ 00627 for(j = 0;j<8;j++){ 00628 if(ar1[i][j] == ch_post[i][j] && ar2[i][j] == ch_post[i][j] ){ 00629 ar1[i][j] = 0; 00630 ar2[i][j] = 0; 00631 } 00632 } 00633 } 00634 } 00635 00636 00637 int _power(int number , int power){ 00638 int i = 0; 00639 int number1 = number; 00640 if(power == 0){return 1;} 00641 for(i = 1 ; i <= power ; i++ ){ 00642 if(power == 1){return number;} 00643 if(i == 1){number = number * 1;} 00644 else{number1 = number1 * number;} 00645 } 00646 return number1; 00647 } 00648 00649 00650 void array_to_hex(int ar1[8][8]){ 00651 int prompt; 00652 int i; 00653 int j; 00654 for(i = 0;i<8;i++){ 00655 for(j = 0;j<8;j++){ 00656 prompt = _power(2,7-j); 00657 if(ar1[i][j] == 1){ 00658 for_hex = for_hex + prompt; 00659 } 00660 else{ 00661 for_hex = for_hex + 0; 00662 } 00663 } 00664 return_hex[i] = for_hex; 00665 prompt = 0; 00666 for_hex = 0; 00667 } 00668 } 00669 00670 void place_ship3(char dir){ 00671 int post1[8][8] = {0}; 00672 int post2[8][8] = {0}; 00673 int hex_post1[8] = {0}; 00674 int hex_post2[8] = {0}; 00675 int hex_post_cut[8] = {0}; 00676 int get_same_position[8][8]; 00677 int wow=0; 00678 00679 if(dir == 'w'&& temppic2[0] == 0){ 00680 printf("w\n"); 00681 for(j=0;j<8;j++){ 00682 if(j == 7){ 00683 forshift[7] = 0; 00684 } 00685 else{ 00686 forshift[j] = temppic2[j+1]; 00687 } 00688 } 00689 for(j=0;j<8;j++){ 00690 temppic2[j] = forshift[j]; 00691 _temppic[j] = temppic2[j]; 00692 } 00693 // begin to compare and combine two frame 00694 hex_to_array(_temppic); 00695 for(i = 0;i<8;i++){ 00696 for(j = 0;j<8;j++){ 00697 post1[i][j] = return_position[i][j]; 00698 } 00699 } 00700 hex_to_array(pic); 00701 for(i = 0;i<8;i++){ 00702 for(j = 0;j<8;j++){ 00703 post2[i][j] = return_position[i][j]; 00704 } 00705 } 00706 00707 // begin to check boypeacemaker 00708 ch_same_position(post1,post2); 00709 for(i=0;i<8;i++){ 00710 for(j=0;j<8;j++){ 00711 get_same_position[i][j] = ch_post[i][j]; 00712 if(get_same_position[i][j] == 1){ 00713 wow = 1; 00714 } 00715 } 00716 } 00717 if(wow == 0){ 00718 for(i=0;i<8;i++){_temppic[i] = temppic2[i]+pic[i];} 00719 } 00720 else{ 00721 discard_same_position(post1,post2); 00722 array_to_hex(post1); 00723 for(i = 0;i<8;i++){ 00724 hex_post1[i] = return_hex[i]; 00725 } 00726 array_to_hex(post2); 00727 for(i = 0;i<8;i++){ 00728 hex_post2[i] = return_hex[i]; 00729 } 00730 array_to_hex(get_same_position); 00731 for(i = 0;i<8;i++){ 00732 hex_post_cut[i] = return_hex[i]; 00733 } 00734 for(i = 0;i<8;i++){ 00735 _temppic[i] = hex_post1[i] + hex_post2[i] + hex_post_cut[i]; 00736 } 00737 } 00738 } 00739 if(dir == 'd'){ 00740 printf("d\n"); 00741 00742 for(i=0;i<8;i++){ 00743 if(temppic2[i] == 0xe0){ 00744 check_boat3 = 1; 00745 } 00746 } 00747 if(check_boat3 == 0){ 00748 for(j=0;j<8;j++){ 00749 if(temppic2[j] != 0){ 00750 temppic2[j] = temppic2[j]*2; 00751 } 00752 else{ 00753 temppic2[j] = 0; 00754 } 00755 _temppic[j] = temppic2[j]; 00756 } 00757 // begin to compare and combine two frame 00758 hex_to_array(_temppic); 00759 for(i = 0;i<8;i++){ 00760 for(j = 0;j<8;j++){ 00761 post1[i][j] = return_position[i][j]; 00762 } 00763 } 00764 hex_to_array(pic); 00765 for(i = 0;i<8;i++){ 00766 for(j = 0;j<8;j++){ 00767 post2[i][j] = return_position[i][j]; 00768 } 00769 } 00770 00771 // begin to check boypeacemaker 00772 ch_same_position(post1,post2); 00773 for(i=0;i<8;i++){ 00774 for(j=0;j<8;j++){ 00775 get_same_position[i][j] = ch_post[i][j]; 00776 if(get_same_position[i][j] == 1){ 00777 wow = 1; 00778 } 00779 } 00780 } 00781 if(wow == 0){ 00782 for(i=0;i<8;i++){_temppic[i] = temppic2[i]+pic[i];} 00783 } 00784 else{ 00785 discard_same_position(post1,post2); 00786 array_to_hex(post1); 00787 for(i = 0;i<8;i++){ 00788 hex_post1[i] = return_hex[i]; 00789 } 00790 array_to_hex(post2); 00791 for(i = 0;i<8;i++){ 00792 hex_post2[i] = return_hex[i]; 00793 } 00794 array_to_hex(get_same_position); 00795 for(i = 0;i<8;i++){ 00796 hex_post_cut[i] = return_hex[i]; 00797 } 00798 for(i = 0;i<8;i++){ 00799 _temppic[i] = hex_post1[i] + hex_post2[i] + hex_post_cut[i]; 00800 } 00801 } 00802 } 00803 check_boat3 = 0; 00804 } 00805 if(dir == 'a'){ 00806 printf("a\n"); 00807 for(i=0;i<8;i++){ 00808 if(temppic2[i] == 0x07){ 00809 check_boat3 = 1; 00810 } 00811 } 00812 if(check_boat3 == 0){ 00813 for(j=0;j<8;j++){ 00814 if(temppic2[j] != 0){ 00815 temppic2[j] = temppic2[j]/2; 00816 } 00817 else{ 00818 temppic2[j] = 0; 00819 } 00820 _temppic[j] = temppic2[j]; 00821 } 00822 // begin to compare and combine two frame 00823 hex_to_array(_temppic); 00824 for(i = 0;i<8;i++){ 00825 for(j = 0;j<8;j++){ 00826 post1[i][j] = return_position[i][j]; 00827 } 00828 } 00829 hex_to_array(pic); 00830 for(i = 0;i<8;i++){ 00831 for(j = 0;j<8;j++){ 00832 post2[i][j] = return_position[i][j]; 00833 } 00834 } 00835 00836 // begin to check boypeacemaker 00837 ch_same_position(post1,post2); 00838 for(i=0;i<8;i++){ 00839 for(j=0;j<8;j++){ 00840 get_same_position[i][j] = ch_post[i][j]; 00841 if(get_same_position[i][j] == 1){ 00842 wow = 1; 00843 } 00844 } 00845 } 00846 if(wow == 0){ 00847 for(i=0;i<8;i++){_temppic[i] = temppic2[i]+pic[i];} 00848 } 00849 else{ 00850 discard_same_position(post1,post2); 00851 array_to_hex(post1); 00852 for(i = 0;i<8;i++){ 00853 hex_post1[i] = return_hex[i]; 00854 } 00855 array_to_hex(post2); 00856 for(i = 0;i<8;i++){ 00857 hex_post2[i] = return_hex[i]; 00858 } 00859 array_to_hex(get_same_position); 00860 for(i = 0;i<8;i++){ 00861 hex_post_cut[i] = return_hex[i]; 00862 } 00863 for(i = 0;i<8;i++){ 00864 _temppic[i] = hex_post1[i] + hex_post2[i] + hex_post_cut[i]; 00865 } 00866 } 00867 } 00868 check_boat3 = 0; 00869 } 00870 if(dir == 's' && temppic2[7] == 0){ 00871 printf("s\n"); 00872 for(j=0;j<8;j++){ 00873 if(j == 0){ 00874 forshift[0] = 0; 00875 } 00876 else{ 00877 forshift[j] = temppic2[j-1]; 00878 } 00879 } 00880 for(j=0;j<8;j++){ 00881 temppic2[j] = forshift[j]; 00882 _temppic[j] = temppic2[j]; 00883 } 00884 // begin to compare and combine two frame 00885 hex_to_array(_temppic); 00886 for(i = 0;i<8;i++){ 00887 for(j = 0;j<8;j++){ 00888 post1[i][j] = return_position[i][j]; 00889 } 00890 } 00891 hex_to_array(pic); 00892 for(i = 0;i<8;i++){ 00893 for(j = 0;j<8;j++){ 00894 post2[i][j] = return_position[i][j]; 00895 } 00896 } 00897 00898 // begin to check boypeacemaker 00899 ch_same_position(post1,post2); 00900 for(i=0;i<8;i++){ 00901 for(j=0;j<8;j++){ 00902 get_same_position[i][j] = ch_post[i][j]; 00903 if(get_same_position[i][j] == 1){ 00904 wow = 1; 00905 } 00906 } 00907 } 00908 if(wow == 0){ 00909 for(i=0;i<8;i++){_temppic[i] = temppic2[i]+pic[i];} 00910 } 00911 else{ 00912 discard_same_position(post1,post2); 00913 array_to_hex(post1); 00914 for(i = 0;i<8;i++){ 00915 hex_post1[i] = return_hex[i]; 00916 } 00917 array_to_hex(post2); 00918 for(i = 0;i<8;i++){ 00919 hex_post2[i] = return_hex[i]; 00920 } 00921 array_to_hex(get_same_position); 00922 for(i = 0;i<8;i++){ 00923 hex_post_cut[i] = return_hex[i]; 00924 } 00925 for(i = 0;i<8;i++){ 00926 _temppic[i] = hex_post1[i] + hex_post2[i] + hex_post_cut[i]; 00927 } 00928 } 00929 00930 } 00931 } 00932 // ******************************************************************** ship 2 channal ****************************************************************** 00933 00934 void place_ship2_4(int ship,char dir){ 00935 00936 int post1[8][8] = {0}; 00937 int post2[8][8] = {0}; 00938 int hex_post1[8] = {0}; 00939 int hex_post2[8] = {0}; 00940 int hex_post_cut[8] = {0}; 00941 int get_same_position[8][8]; 00942 int wow=0; 00943 00944 if(dir == 'w'&& temppic3[ship][0] == 0){ 00945 printf("w\n"); 00946 for(j=0;j<8;j++){ 00947 if(j == 7){ 00948 forshift[7] = 0; 00949 } 00950 else{ 00951 forshift[j] = temppic3[ship][j+1]; 00952 } 00953 } 00954 for(j=0;j<8;j++){ 00955 temppic3[ship][j] = forshift[j]; 00956 _temppic[j] = temppic3[ship][j]; 00957 } 00958 // begin to compare and combine two frame 00959 hex_to_array(_temppic); 00960 for(i = 0;i<8;i++){ 00961 for(j = 0;j<8;j++){ 00962 post1[i][j] = return_position[i][j]; 00963 } 00964 } 00965 hex_to_array(pic); 00966 for(i = 0;i<8;i++){ 00967 for(j = 0;j<8;j++){ 00968 post2[i][j] = return_position[i][j]; 00969 } 00970 } 00971 00972 // begin to check boypeacemaker 00973 ch_same_position(post1,post2); 00974 for(i=0;i<8;i++){ 00975 for(j=0;j<8;j++){ 00976 get_same_position[i][j] = ch_post[i][j]; 00977 if(get_same_position[i][j] == 1){ 00978 wow = 1; 00979 } 00980 } 00981 } 00982 if(wow == 0){ 00983 for(i=0;i<8;i++){_temppic[i] = temppic3[ship][i]+pic[i];} 00984 } 00985 else{ 00986 discard_same_position(post1,post2); 00987 array_to_hex(post1); 00988 for(i = 0;i<8;i++){ 00989 hex_post1[i] = return_hex[i]; 00990 } 00991 array_to_hex(post2); 00992 for(i = 0;i<8;i++){ 00993 hex_post2[i] = return_hex[i]; 00994 } 00995 array_to_hex(get_same_position); 00996 for(i = 0;i<8;i++){ 00997 hex_post_cut[i] = return_hex[i]; 00998 } 00999 for(i = 0;i<8;i++){ 01000 _temppic[i] = hex_post1[i] + hex_post2[i] + hex_post_cut[i]; 01001 } 01002 } 01003 01004 } 01005 if(dir == 'd' && temppic3[ship][3] != 0x80 && temppic3[ship][4] != 0x80 ){ 01006 printf("d\n"); 01007 for(j=0;j<8;j++){ 01008 if(temppic3[j] != 0){ 01009 temppic3[ship][j] = temppic3[ship][j]*2; 01010 } 01011 else{ 01012 temppic3[ship][j] = 0; 01013 } 01014 _temppic[j] = temppic3[ship][j]; 01015 } 01016 // begin to compare and combine two frame 01017 hex_to_array(_temppic); 01018 for(i = 0;i<8;i++){ 01019 for(j = 0;j<8;j++){ 01020 post1[i][j] = return_position[i][j]; 01021 } 01022 } 01023 hex_to_array(pic); 01024 for(i = 0;i<8;i++){ 01025 for(j = 0;j<8;j++){ 01026 post2[i][j] = return_position[i][j]; 01027 } 01028 } 01029 01030 // begin to check boypeacemaker 01031 ch_same_position(post1,post2); 01032 for(i=0;i<8;i++){ 01033 for(j=0;j<8;j++){ 01034 get_same_position[i][j] = ch_post[i][j]; 01035 if(get_same_position[i][j] == 1){ 01036 wow = 1; 01037 } 01038 } 01039 } 01040 if(wow == 0){ 01041 for(i=0;i<8;i++){_temppic[i] = temppic3[ship][i]+pic[i];} 01042 } 01043 else{ 01044 discard_same_position(post1,post2); 01045 array_to_hex(post1); 01046 for(i = 0;i<8;i++){ 01047 hex_post1[i] = return_hex[i]; 01048 } 01049 array_to_hex(post2); 01050 for(i = 0;i<8;i++){ 01051 hex_post2[i] = return_hex[i]; 01052 } 01053 array_to_hex(get_same_position); 01054 for(i = 0;i<8;i++){ 01055 hex_post_cut[i] = return_hex[i]; 01056 } 01057 for(i = 0;i<8;i++){ 01058 _temppic[i] = hex_post1[i] + hex_post2[i] + hex_post_cut[i]; 01059 } 01060 } 01061 01062 } 01063 if(dir == 'a' && temppic3[ship][3] != 0x01 && temppic3[ship][4] != 0x01 ){ 01064 printf("a\n"); 01065 for(j=0;j<8;j++){ 01066 if(temppic3[ship][j] != 0){ 01067 temppic3[ship][j] = temppic3[ship][j]/2; 01068 } 01069 else{ 01070 temppic3[ship][j] = 0; 01071 } 01072 _temppic[j] = temppic3[ship][j]; 01073 } 01074 // begin to compare and combine two frame 01075 hex_to_array(_temppic); 01076 for(i = 0;i<8;i++){ 01077 for(j = 0;j<8;j++){ 01078 post1[i][j] = return_position[i][j]; 01079 } 01080 } 01081 hex_to_array(pic); 01082 for(i = 0;i<8;i++){ 01083 for(j = 0;j<8;j++){ 01084 post2[i][j] = return_position[i][j]; 01085 } 01086 } 01087 01088 // begin to check boypeacemaker 01089 ch_same_position(post1,post2); 01090 for(i=0;i<8;i++){ 01091 for(j=0;j<8;j++){ 01092 get_same_position[i][j] = ch_post[i][j]; 01093 if(get_same_position[i][j] == 1){ 01094 wow = 1; 01095 } 01096 } 01097 } 01098 if(wow == 0){ 01099 for(i=0;i<8;i++){_temppic[i] = temppic3[ship][i]+pic[i];} 01100 } 01101 else{ 01102 discard_same_position(post1,post2); 01103 array_to_hex(post1); 01104 for(i = 0;i<8;i++){ 01105 hex_post1[i] = return_hex[i]; 01106 } 01107 array_to_hex(post2); 01108 for(i = 0;i<8;i++){ 01109 hex_post2[i] = return_hex[i]; 01110 } 01111 array_to_hex(get_same_position); 01112 for(i = 0;i<8;i++){ 01113 hex_post_cut[i] = return_hex[i]; 01114 } 01115 for(i = 0;i<8;i++){ 01116 _temppic[i] = hex_post1[i] + hex_post2[i] + hex_post_cut[i]; 01117 } 01118 } 01119 01120 } 01121 if(dir == 's' && temppic3[ship][7] == 0){ 01122 printf("s\n"); 01123 for(j=0;j<8;j++){ 01124 if(j == 0){ 01125 forshift[0] = 0; 01126 } 01127 else{ 01128 forshift[j] = temppic3[ship][j-1]; 01129 } 01130 } 01131 for(j=0;j<8;j++){ 01132 temppic3[ship][j] = forshift[j]; 01133 _temppic[j] = temppic3[ship][j]; 01134 } 01135 // begin to compare and combine two frame 01136 hex_to_array(_temppic); 01137 for(i = 0;i<8;i++){ 01138 for(j = 0;j<8;j++){ 01139 post1[i][j] = return_position[i][j]; 01140 } 01141 } 01142 hex_to_array(pic); 01143 for(i = 0;i<8;i++){ 01144 for(j = 0;j<8;j++){ 01145 post2[i][j] = return_position[i][j]; 01146 } 01147 } 01148 01149 // begin to check boypeacemaker 01150 ch_same_position(post1,post2); 01151 for(i=0;i<8;i++){ 01152 for(j=0;j<8;j++){ 01153 get_same_position[i][j] = ch_post[i][j]; 01154 if(get_same_position[i][j] == 1){ 01155 wow = 1; 01156 } 01157 } 01158 } 01159 if(wow == 0){ 01160 for(i=0;i<8;i++){_temppic[i] = temppic3[ship][i]+pic[i];} 01161 } 01162 else{ 01163 discard_same_position(post1,post2); 01164 array_to_hex(post1); 01165 for(i = 0;i<8;i++){ 01166 hex_post1[i] = return_hex[i]; 01167 } 01168 array_to_hex(post2); 01169 for(i = 0;i<8;i++){ 01170 hex_post2[i] = return_hex[i]; 01171 } 01172 array_to_hex(get_same_position); 01173 for(i = 0;i<8;i++){ 01174 hex_post_cut[i] = return_hex[i]; 01175 } 01176 for(i = 0;i<8;i++){ 01177 _temppic[i] = hex_post1[i] + hex_post2[i] + hex_post_cut[i]; 01178 } 01179 } 01180 01181 } 01182 }
Generated on Fri Aug 5 2022 01:42:03 by
1.7.2
