Nasrun

Dependencies:   mbed

Fork of project_ShipDot by Jirat Nakarit

Committer:
gunpuen2
Date:
Sun Dec 04 09:07:54 2016 +0000
Revision:
23:66a401850f2e
Parent:
22:5bc894988f11
Child:
24:03e12968119b
Fix with Jirat

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gunpuen2 0:a8e057156263 1 /******************************************************************************/
gunpuen2 1:6157c77da3d5 2 /* This Nicleo is state 0 */
gunpuen2 0:a8e057156263 3 /******************************************************************************/
gunpuen2 0:a8e057156263 4 #include "mbed.h"
dragondrunk 22:5bc894988f11 5 #include "ColorMbed.h"
gunpuen2 23:66a401850f2e 6
gunpuen2 23:66a401850f2e 7 // Setting
gunpuen2 23:66a401850f2e 8 int ifUrJirat = 1;
gunpuen2 23:66a401850f2e 9
gunpuen2 0:a8e057156263 10 // Initail I/O.
dragondrunk 22:5bc894988f11 11 AnalogIn VRx(A0);
dragondrunk 22:5bc894988f11 12 AnalogIn VRy(A1);
dragondrunk 22:5bc894988f11 13 DigitalIn Button(PA_4);
dragondrunk 22:5bc894988f11 14 Serial bt(PA_15, PB_7);
dragondrunk 22:5bc894988f11 15 ColorMbed dotmatrix;
gunpuen2 0:a8e057156263 16
gunpuen2 0:a8e057156263 17 // Initial function.
gunpuen2 4:8a86bacddcac 18 char posit2char(int posit);
gunpuen2 0:a8e057156263 19 char check_joys(int jx,int jy);
gunpuen2 23:66a401850f2e 20 int IamWin();
gunpuen2 23:66a401850f2e 21 int TellUrEnemy_uWin();
gunpuen2 4:8a86bacddcac 22 int char2posit(char cha);
gunpuen2 0:a8e057156263 23 int check_joys_int(int jx,int jy);
gunpuen2 0:a8e057156263 24 int check_correctPosition(int X,int Y);
gunpuen2 23:66a401850f2e 25 int protect_ship(int head_position,int ship_type);
gunpuen2 15:5902cf545449 26 int get_ship_platform(int input_position,int ship_type);
gunpuen2 6:7f99124272d9 27 void atk_enemy();
gunpuen2 6:7f99124272d9 28 void enemy_atk();
gunpuen2 23:66a401850f2e 29 void check_end();
gunpuen2 0:a8e057156263 30 void check_ready();
gunpuen2 16:3fac68a7fd7c 31 void mark_ship_destroyed();
gunpuen2 23:66a401850f2e 32 void Select_Position(char M,int SetOrPlay);
gunpuen2 16:3fac68a7fd7c 33 void get_atk_platform(int atkpos);
gunpuen2 23:66a401850f2e 34
gunpuen2 16:3fac68a7fd7c 35 //inessential
gunpuen2 7:e35ba3ddb9af 36 void print_ship_destroyed();
gunpuen2 6:7f99124272d9 37 void print_enemy_platform();
gunpuen2 6:7f99124272d9 38 void print_ship_platform();
gunpuen2 6:7f99124272d9 39 void print_atk_platform();
gunpuen2 0:a8e057156263 40
gunpuen2 23:66a401850f2e 41 // Nasarun's function.
gunpuen2 23:66a401850f2e 42 int _power(int number , int power);
gunpuen2 23:66a401850f2e 43 void hex_to_array(int* ar);
gunpuen2 23:66a401850f2e 44 void place_ship3(char dir);
gunpuen2 23:66a401850f2e 45 void array_to_hex(int ar1[8][8]);
gunpuen2 23:66a401850f2e 46 void place_ship2_4(int ship,char dir);
gunpuen2 23:66a401850f2e 47 void ch_same_position(int ar1[8][8],int ar2[8][8]);
gunpuen2 23:66a401850f2e 48 void discard_same_position(int ar1[8][8],int ar2[8][8]);
gunpuen2 23:66a401850f2e 49
gunpuen2 0:a8e057156263 50 // Initial variable.
gunpuen2 2:d93832fe8deb 51 int check_ship_underATK = 0;
gunpuen2 0:a8e057156263 52 int select_Position = 0;
gunpuen2 0:a8e057156263 53 int ATKposition = 0;
gunpuen2 1:6157c77da3d5 54 int enemy_ready = 0;
gunpuen2 2:d93832fe8deb 55 int check_ship1 = 0;
gunpuen2 2:d93832fe8deb 56 int check_ship2 = 0;
gunpuen2 17:aeb7cbfb8640 57 int iShipType = 0;
gunpuen2 0:a8e057156263 58 int iWaitATK = 0;
gunpuen2 19:d78586719868 59 int check_win = 0;
gunpuen2 0:a8e057156263 60 int state = 0;
gunpuen2 2:d93832fe8deb 61 int ship_SelectType[8] = {4,3,2,2,1,1,1,1};
gunpuen2 6:7f99124272d9 62 int enemy_platform[8][8] = {{0}};
gunpuen2 4:8a86bacddcac 63 int ship_platform[8][8] = {{0}}; //______________________________________________This is ship area.
gunpuen2 1:6157c77da3d5 64 int atk_platform[8][8] = {{0}};
gunpuen2 10:b8d45f9b00bf 65 int ship_underATK[15] = {9,9,9,9,9,9,9,9,9,9,9,9,9,9,9};
gunpuen2 2:d93832fe8deb 66 int ship_destroyed[8] = {0};
gunpuen2 0:a8e057156263 67 int ship4[4] = {0};
gunpuen2 0:a8e057156263 68 int ship3[3] = {0};
gunpuen2 0:a8e057156263 69 int ship2[2][2] = {{0}};
gunpuen2 0:a8e057156263 70 int ship1[4] = {0};
dragondrunk 22:5bc894988f11 71 //fuction nasrun
dragondrunk 22:5bc894988f11 72 int return_position[8][8] ;
dragondrunk 22:5bc894988f11 73 int for_hex = 0;
dragondrunk 22:5bc894988f11 74 int ch_post[8][8] = {{1,1,1,1,1,1,1,1},
dragondrunk 22:5bc894988f11 75 {1,1,1,1,1,1,1,1},
dragondrunk 22:5bc894988f11 76 {1,1,1,1,1,1,1,1},
dragondrunk 22:5bc894988f11 77 {1,1,1,1,1,1,1,1},
dragondrunk 22:5bc894988f11 78 {1,1,1,1,1,1,1,1},
dragondrunk 22:5bc894988f11 79 {1,1,1,1,1,1,1,1},
dragondrunk 22:5bc894988f11 80 {1,1,1,1,1,1,1,1},
dragondrunk 22:5bc894988f11 81 {1,1,1,1,1,1,1,1}};
dragondrunk 22:5bc894988f11 82 int return_hex[8];
dragondrunk 22:5bc894988f11 83 int display_battle[8][8][3] = {0};
dragondrunk 22:5bc894988f11 84 int _temppic[8] = {0x01,0x01,0x01,0x01,0,0,0,0};
dragondrunk 22:5bc894988f11 85 int temppic2[8] = {0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
gunpuen2 23:66a401850f2e 86 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}};
dragondrunk 22:5bc894988f11 87 int temppic4[8] = {0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
dragondrunk 22:5bc894988f11 88 int forshift[8] = {0};
dragondrunk 22:5bc894988f11 89 int pic[8] = {0};
dragondrunk 22:5bc894988f11 90 int i,j;
dragondrunk 22:5bc894988f11 91 int check_boat3=0;
dragondrunk 22:5bc894988f11 92 int check_hex=0;
dragondrunk 22:5bc894988f11 93
dragondrunk 22:5bc894988f11 94 // function Test!
gunpuen2 0:a8e057156263 95 int main(){ //-------------------------------------------------------------------Main Function.
gunpuen2 15:5902cf545449 96 bt.baud(9600);
gunpuen2 0:a8e057156263 97 float Vx;
gunpuen2 0:a8e057156263 98 float Vy;
gunpuen2 19:d78586719868 99 int SW,iVxVy,iSW,n = 0;
gunpuen2 18:ecef8382d41e 100 int uli = 0;
gunpuen2 0:a8e057156263 101 char m;
gunpuen2 23:66a401850f2e 102 int rgb[3] = {60,0,0};
dragondrunk 22:5bc894988f11 103 int state_place_ship = 0;
dragondrunk 22:5bc894988f11 104 dotmatrix.init();
gunpuen2 14:8abed4026326 105
gunpuen2 0:a8e057156263 106 while(1) {
dragondrunk 22:5bc894988f11 107 dotmatrix.display_pic(_temppic,rgb);
gunpuen2 0:a8e057156263 108 if(iShipType<8){
gunpuen2 0:a8e057156263 109 Vx = VRx.read() * 1024;
gunpuen2 0:a8e057156263 110 Vy = VRy.read() * 1024;
gunpuen2 0:a8e057156263 111 SW = Button.read();
gunpuen2 0:a8e057156263 112 m = check_joys(Vx,Vy);
gunpuen2 0:a8e057156263 113 n = check_joys_int(Vx,Vy);
gunpuen2 0:a8e057156263 114 if(n == 1){ //_______________________________________________________ For make sure coordinate is press 1 time.
gunpuen2 0:a8e057156263 115 iVxVy = 0;
gunpuen2 0:a8e057156263 116 check_ready();
gunpuen2 0:a8e057156263 117 }
gunpuen2 0:a8e057156263 118 if(SW == 1){ //______________________________________________________ For make sure switch is press 1 time.
gunpuen2 0:a8e057156263 119 iSW = 0;
gunpuen2 0:a8e057156263 120 check_ready();
gunpuen2 0:a8e057156263 121 }
gunpuen2 0:a8e057156263 122 if(m!=NULL && iVxVy==0){ //__________________________________________ Get position that wait for press switch.
gunpuen2 23:66a401850f2e 123 Select_Position(m,0);
dragondrunk 22:5bc894988f11 124 if(state_place_ship == 0){
gunpuen2 23:66a401850f2e 125 place_ship2_4(0,m); // 4
dragondrunk 22:5bc894988f11 126 }
dragondrunk 22:5bc894988f11 127 else if(state_place_ship == 1){
gunpuen2 23:66a401850f2e 128 place_ship3(m); // 3
dragondrunk 22:5bc894988f11 129 }
dragondrunk 22:5bc894988f11 130 else if(state_place_ship == 2){
gunpuen2 23:66a401850f2e 131 place_ship2_4(1,m); // 2
gunpuen2 23:66a401850f2e 132 }
gunpuen2 23:66a401850f2e 133 else if(state_place_ship == 3){
gunpuen2 23:66a401850f2e 134 place_ship2_4(2,m); //2
gunpuen2 23:66a401850f2e 135 }
gunpuen2 23:66a401850f2e 136 else if(state_place_ship == 4){
gunpuen2 23:66a401850f2e 137 place_ship2_4(3,m); // 1
dragondrunk 22:5bc894988f11 138 }
gunpuen2 23:66a401850f2e 139 else if(state_place_ship == 5){
gunpuen2 23:66a401850f2e 140 place_ship2_4(4,m); // 1
gunpuen2 23:66a401850f2e 141 }
gunpuen2 23:66a401850f2e 142 else if(state_place_ship == 6){
gunpuen2 23:66a401850f2e 143 place_ship2_4(5,m); // 1
gunpuen2 23:66a401850f2e 144 }
gunpuen2 23:66a401850f2e 145 else if(state_place_ship == 7){
gunpuen2 23:66a401850f2e 146 place_ship2_4(6,m); // 1
dragondrunk 22:5bc894988f11 147 }
gunpuen2 15:5902cf545449 148 printf("select_Position = %d\n",select_Position);
gunpuen2 0:a8e057156263 149 check_ready();
gunpuen2 0:a8e057156263 150 iVxVy = 1;
gunpuen2 3:baff75bbb78e 151 check_ready();
gunpuen2 0:a8e057156263 152 }
gunpuen2 0:a8e057156263 153 if(SW==0 && iSW==0){ //______________________________________________If switch pressing by human.
gunpuen2 0:a8e057156263 154 printf("Wait!\n");
dragondrunk 22:5bc894988f11 155
gunpuen2 0:a8e057156263 156 check_ready();
gunpuen2 15:5902cf545449 157 if(get_ship_platform(select_Position,ship_SelectType[iShipType])==0){ //__Please read explanation in function get_ship_platform.
gunpuen2 0:a8e057156263 158 printf("Please input correct position\n");
gunpuen2 0:a8e057156263 159 }else{
gunpuen2 0:a8e057156263 160 iShipType++;
dragondrunk 22:5bc894988f11 161 if(state_place_ship == 0){
dragondrunk 22:5bc894988f11 162 for(j=0;j<8;j++){
gunpuen2 23:66a401850f2e 163 printf("state_place_ship == 0 ++\n");
dragondrunk 22:5bc894988f11 164 pic[j] = temppic3[0][j]+pic[j];
dragondrunk 22:5bc894988f11 165 }
dragondrunk 22:5bc894988f11 166 }
dragondrunk 22:5bc894988f11 167 else if(state_place_ship == 1){
dragondrunk 22:5bc894988f11 168 for(j=0;j<8;j++){
gunpuen2 23:66a401850f2e 169 printf("state_place_ship == 1 ++\n");
dragondrunk 22:5bc894988f11 170 pic[j] = temppic2[j]+pic[j];
dragondrunk 22:5bc894988f11 171 }
dragondrunk 22:5bc894988f11 172 }
gunpuen2 23:66a401850f2e 173 else if(state_place_ship == 2){
gunpuen2 23:66a401850f2e 174 for(j=0;j<8;j++){
gunpuen2 23:66a401850f2e 175 printf("state_place_ship == 2 ++\n");
gunpuen2 23:66a401850f2e 176 pic[j] = temppic3[1][j]+pic[j];
gunpuen2 23:66a401850f2e 177 }
gunpuen2 23:66a401850f2e 178 }
gunpuen2 23:66a401850f2e 179 else if(state_place_ship == 3){
gunpuen2 23:66a401850f2e 180 for(j=0;j<8;j++){
gunpuen2 23:66a401850f2e 181 printf("state_place_ship == 3 ++\n");
gunpuen2 23:66a401850f2e 182 pic[j] = temppic3[2][j]+pic[j];
gunpuen2 23:66a401850f2e 183 }
gunpuen2 23:66a401850f2e 184 }
gunpuen2 23:66a401850f2e 185 else if(state_place_ship == 4){
dragondrunk 22:5bc894988f11 186 for(j=0;j<8;j++){
gunpuen2 23:66a401850f2e 187 printf("state_place_ship == 4 ++\n");
gunpuen2 23:66a401850f2e 188 pic[j] = temppic3[3][j]+pic[j];
gunpuen2 23:66a401850f2e 189 }
gunpuen2 23:66a401850f2e 190 }
gunpuen2 23:66a401850f2e 191 else if(state_place_ship == 5){
gunpuen2 23:66a401850f2e 192 for(j=0;j<8;j++){
gunpuen2 23:66a401850f2e 193 printf("state_place_ship == 5 ++\n");
gunpuen2 23:66a401850f2e 194 pic[j] = temppic3[4][j]+pic[j];
gunpuen2 23:66a401850f2e 195 }
gunpuen2 23:66a401850f2e 196 }
gunpuen2 23:66a401850f2e 197 else if(state_place_ship == 6){
gunpuen2 23:66a401850f2e 198 for(j=0;j<8;j++){
gunpuen2 23:66a401850f2e 199 printf("state_place_ship == 6 ++\n");
gunpuen2 23:66a401850f2e 200 pic[j] = temppic3[5][j]+pic[j];
gunpuen2 23:66a401850f2e 201 }
gunpuen2 23:66a401850f2e 202 }
gunpuen2 23:66a401850f2e 203 else if(state_place_ship == 7){
gunpuen2 23:66a401850f2e 204 for(j=0;j<8;j++){
gunpuen2 23:66a401850f2e 205 printf("state_place_ship == 7 ++\n");
gunpuen2 23:66a401850f2e 206 pic[j] = temppic3[6][j]+pic[j];
dragondrunk 22:5bc894988f11 207 }
dragondrunk 22:5bc894988f11 208 }
dragondrunk 22:5bc894988f11 209 state_place_ship = state_place_ship + 1;
gunpuen2 23:66a401850f2e 210 select_Position = 0;
gunpuen2 0:a8e057156263 211 }
gunpuen2 0:a8e057156263 212 check_ready();
gunpuen2 0:a8e057156263 213 iSW = 1;
gunpuen2 6:7f99124272d9 214 print_ship_platform();
gunpuen2 3:baff75bbb78e 215 check_ready();
gunpuen2 0:a8e057156263 216 }
gunpuen2 0:a8e057156263 217 }else{
gunpuen2 3:baff75bbb78e 218 if(enemy_ready!=1){
gunpuen2 3:baff75bbb78e 219 printf("sent E\n");
gunpuen2 12:287c6a9560ca 220 while(uli<50){
gunpuen2 4:8a86bacddcac 221 bt.printf("E");
gunpuen2 3:baff75bbb78e 222 uli++;
gunpuen2 3:baff75bbb78e 223 }
gunpuen2 12:287c6a9560ca 224 }else{
gunpuen2 12:287c6a9560ca 225 bt.putc('l');
gunpuen2 3:baff75bbb78e 226 }
gunpuen2 0:a8e057156263 227 printf("\n");
gunpuen2 0:a8e057156263 228 break;
gunpuen2 0:a8e057156263 229 }
gunpuen2 0:a8e057156263 230 }
gunpuen2 12:287c6a9560ca 231 if(enemy_ready == 0){
gunpuen2 12:287c6a9560ca 232 printf("Wait for enemy\n");
gunpuen2 12:287c6a9560ca 233 while(1){if(bt.readable()){if(bt.getc()=='l'){break;}}}
gunpuen2 12:287c6a9560ca 234 state = 0;
gunpuen2 12:287c6a9560ca 235 }else{state = 1;}
gunpuen2 19:d78586719868 236 wait(5);
gunpuen2 12:287c6a9560ca 237 while(1) { //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Play
gunpuen2 1:6157c77da3d5 238 if(state == 0){
gunpuen2 6:7f99124272d9 239 atk_enemy();
gunpuen2 6:7f99124272d9 240 printf("This is enemy_platform.\n");
gunpuen2 6:7f99124272d9 241 print_enemy_platform();
gunpuen2 19:d78586719868 242 state = 1;
gunpuen2 0:a8e057156263 243 }else{
gunpuen2 6:7f99124272d9 244 enemy_atk();
gunpuen2 19:d78586719868 245 if(check_win==1){
gunpuen2 19:d78586719868 246 printf("BOO!! You Win!\n");
gunpuen2 19:d78586719868 247 break;
gunpuen2 19:d78586719868 248 }
gunpuen2 6:7f99124272d9 249 printf("This is atk_platform.\n");
gunpuen2 6:7f99124272d9 250 print_atk_platform();
gunpuen2 7:e35ba3ddb9af 251 printf("This is ship_destroyed. : ");
gunpuen2 7:e35ba3ddb9af 252 print_ship_destroyed();
gunpuen2 14:8abed4026326 253 if(TellUrEnemy_uWin()==1){
gunpuen2 14:8abed4026326 254 while(uli<100){
gunpuen2 14:8abed4026326 255 bt.putc('q');
gunpuen2 14:8abed4026326 256 uli++;
gunpuen2 14:8abed4026326 257 }
gunpuen2 19:d78586719868 258 printf("BOO!! You lost!\n");
gunpuen2 7:e35ba3ddb9af 259 break;
gunpuen2 7:e35ba3ddb9af 260 }else{state = 0;}
gunpuen2 0:a8e057156263 261 }
gunpuen2 0:a8e057156263 262 }
gunpuen2 19:d78586719868 263 while(1){printf("END\n");wait(1);}
gunpuen2 0:a8e057156263 264 }
gunpuen2 0:a8e057156263 265
gunpuen2 4:8a86bacddcac 266 /******************************************************************************/
gunpuen2 4:8a86bacddcac 267 /* */
gunpuen2 4:8a86bacddcac 268 /* */
gunpuen2 4:8a86bacddcac 269 /* Another function */
gunpuen2 4:8a86bacddcac 270 /* */
gunpuen2 4:8a86bacddcac 271 /* */
gunpuen2 4:8a86bacddcac 272 /******************************************************************************/
gunpuen2 0:a8e057156263 273
gunpuen2 0:a8e057156263 274 char check_joys(int jx,int jy){ //-----------------------------------------------Check joystick that it up,down,left or right.
gunpuen2 8:a8d39b5d17ab 275
gunpuen2 7:e35ba3ddb9af 276 if(ifUrJirat==1){
gunpuen2 7:e35ba3ddb9af 277 if(jx < 14.0){ return 'a';}
gunpuen2 7:e35ba3ddb9af 278 else if(jx > 1010.0){return 'd';}
gunpuen2 7:e35ba3ddb9af 279 else if(jy < 14.0){ return 'w';}
gunpuen2 7:e35ba3ddb9af 280 else if(jy > 1010.0){return 's';}
gunpuen2 7:e35ba3ddb9af 281 else{return NULL;}
gunpuen2 8:a8d39b5d17ab 282 }else{
gunpuen2 9:102af5021c6c 283 if(jx < 14.0){ return 'd';}
gunpuen2 9:102af5021c6c 284 else if(jx > 1010.0){return 'a';}
gunpuen2 9:102af5021c6c 285 else if(jy < 14.0){ return 's';}
gunpuen2 9:102af5021c6c 286 else if(jy > 1010.0){return 'w';}
gunpuen2 7:e35ba3ddb9af 287 else{return NULL;}
gunpuen2 0:a8e057156263 288 }
gunpuen2 0:a8e057156263 289 }
gunpuen2 0:a8e057156263 290 int check_joys_int(int jx,int jy){ //--------------------------------------------Check joystick that it is centre.
gunpuen2 0:a8e057156263 291 if(jx>=450.0&&jx<=600.0){
gunpuen2 0:a8e057156263 292 if(jy>=450.0&&jy<=600.0){
gunpuen2 0:a8e057156263 293 return 1;
gunpuen2 0:a8e057156263 294 }else{
gunpuen2 0:a8e057156263 295 return 0;
gunpuen2 0:a8e057156263 296 }
gunpuen2 0:a8e057156263 297 }else{
gunpuen2 0:a8e057156263 298 return 0;
gunpuen2 0:a8e057156263 299 }
gunpuen2 0:a8e057156263 300 }
gunpuen2 23:66a401850f2e 301 void Select_Position(char M,int SetOrPlay){ //-------------------------------------------------Change position of cursor (Joystick).
gunpuen2 17:aeb7cbfb8640 302 int protect_ships;
gunpuen2 17:aeb7cbfb8640 303 protect_ships = protect_ship(select_Position,ship_SelectType[iShipType]);
gunpuen2 0:a8e057156263 304 switch(M){
gunpuen2 0:a8e057156263 305 case 'a':
gunpuen2 17:aeb7cbfb8640 306 if(select_Position%10!=0){
gunpuen2 17:aeb7cbfb8640 307 select_Position = select_Position - 1;
gunpuen2 17:aeb7cbfb8640 308 }
gunpuen2 0:a8e057156263 309 break;
gunpuen2 0:a8e057156263 310 case 'd':
gunpuen2 17:aeb7cbfb8640 311 if(select_Position%10!=7){
gunpuen2 17:aeb7cbfb8640 312 if(protect_ships==1 or protect_ships==0){
gunpuen2 17:aeb7cbfb8640 313 select_Position = select_Position + 1;
gunpuen2 23:66a401850f2e 314 }
gunpuen2 23:66a401850f2e 315 if(SetOrPlay==1){
gunpuen2 23:66a401850f2e 316 select_Position = select_Position + 1;
gunpuen2 23:66a401850f2e 317 }
gunpuen2 17:aeb7cbfb8640 318 }
gunpuen2 0:a8e057156263 319 break;
gunpuen2 0:a8e057156263 320 case 'w':
gunpuen2 17:aeb7cbfb8640 321 if(select_Position/10!=0){
gunpuen2 17:aeb7cbfb8640 322 select_Position = select_Position - 10;
gunpuen2 17:aeb7cbfb8640 323 }
gunpuen2 0:a8e057156263 324 break;
gunpuen2 0:a8e057156263 325 case 's':
gunpuen2 17:aeb7cbfb8640 326 if(select_Position/10!=7){
gunpuen2 17:aeb7cbfb8640 327 if(protect_ships==1 or protect_ships==2){
gunpuen2 17:aeb7cbfb8640 328 select_Position = select_Position + 10;
gunpuen2 23:66a401850f2e 329 }
gunpuen2 23:66a401850f2e 330 if(SetOrPlay==1){
gunpuen2 23:66a401850f2e 331 select_Position = select_Position + 10;
gunpuen2 23:66a401850f2e 332 }
gunpuen2 17:aeb7cbfb8640 333 }
gunpuen2 0:a8e057156263 334 break;
gunpuen2 0:a8e057156263 335 }
gunpuen2 0:a8e057156263 336 }
gunpuen2 15:5902cf545449 337 int protect_ship(int head_position,int ship_type){
gunpuen2 15:5902cf545449 338 int x,y = 0;
gunpuen2 15:5902cf545449 339 y = head_position/10;
gunpuen2 15:5902cf545449 340 x = head_position%10;
gunpuen2 17:aeb7cbfb8640 341 if(ship_type==4){if((y+4)>7){return 0;}else{return 1;}}
gunpuen2 17:aeb7cbfb8640 342 else if(ship_type==3){if((x+3)>7){return 2;}else{return 1;}}
gunpuen2 17:aeb7cbfb8640 343 else if(ship_type==2){if((y+2)>7){return 0;}else{return 1;}}
gunpuen2 15:5902cf545449 344 else{return 1;}
gunpuen2 15:5902cf545449 345 }
gunpuen2 15:5902cf545449 346 int get_ship_platform(int input_position,int ship_type){ //-----------------------Plot ship in ship area.
gunpuen2 0:a8e057156263 347 int i,x,y = 0;
gunpuen2 0:a8e057156263 348 int error = 0;
gunpuen2 0:a8e057156263 349
gunpuen2 0:a8e057156263 350 y = input_position/10;
gunpuen2 0:a8e057156263 351 x = input_position%10;
gunpuen2 0:a8e057156263 352
gunpuen2 0:a8e057156263 353 for(i=0;i<ship_type;i++){
gunpuen2 0:a8e057156263 354 if(check_correctPosition(y,x) == 1){
gunpuen2 0:a8e057156263 355 if(ship_type == 4){ship4[i] = (y*10)+x;}
gunpuen2 0:a8e057156263 356 else if(ship_type == 3){ship3[i] = (y*10)+x;}
gunpuen2 0:a8e057156263 357 else if(ship_type == 2){ship2[check_ship2][i] = (y*10)+x;}
gunpuen2 0:a8e057156263 358 else if(ship_type == 1){ship1[check_ship1] = (y*10)+x;check_ship1++;}
gunpuen2 16:3fac68a7fd7c 359 }else{error = 1;break;}
gunpuen2 16:3fac68a7fd7c 360 if(ship_type%2 == 0){y++;}else{x++;}
gunpuen2 0:a8e057156263 361 }
gunpuen2 16:3fac68a7fd7c 362 if(ship_type==2){check_ship2++;}
gunpuen2 16:3fac68a7fd7c 363 if(error == 1){return 0;}else{
gunpuen2 0:a8e057156263 364 y = input_position/10;
gunpuen2 0:a8e057156263 365 x = input_position%10;
gunpuen2 0:a8e057156263 366 for(i=0;i<ship_type;i++){
gunpuen2 1:6157c77da3d5 367 ship_platform[y][x] = ship_type;
gunpuen2 16:3fac68a7fd7c 368 if(ship_type%2 == 0){y++;}else{x++;}
gunpuen2 0:a8e057156263 369 }
gunpuen2 0:a8e057156263 370 return 1;
gunpuen2 0:a8e057156263 371 }
gunpuen2 0:a8e057156263 372 }
gunpuen2 0:a8e057156263 373 int check_correctPosition(int X,int Y){
gunpuen2 0:a8e057156263 374 if(X<=7){
gunpuen2 0:a8e057156263 375 if(Y<=7){
gunpuen2 16:3fac68a7fd7c 376 if(ship_platform[X][Y] == 0){return 1;}else{return 0;}
gunpuen2 16:3fac68a7fd7c 377 }else{return 0;}
gunpuen2 16:3fac68a7fd7c 378 }else{return 0;}
gunpuen2 0:a8e057156263 379 }
gunpuen2 6:7f99124272d9 380 void print_ship_platform(){
gunpuen2 0:a8e057156263 381 for(int i=0;i<8;i++){
gunpuen2 0:a8e057156263 382 for(int j=0;j<8;j++){
gunpuen2 1:6157c77da3d5 383 printf("| %d |",ship_platform[i][j]);
gunpuen2 0:a8e057156263 384 }
gunpuen2 0:a8e057156263 385 printf("\n");
gunpuen2 0:a8e057156263 386 }
gunpuen2 0:a8e057156263 387 }
gunpuen2 6:7f99124272d9 388 void print_enemy_platform(){
gunpuen2 6:7f99124272d9 389 for(int i=0;i<8;i++){
gunpuen2 6:7f99124272d9 390 for(int j=0;j<8;j++){
gunpuen2 6:7f99124272d9 391 printf("| %d |",enemy_platform[i][j]);
gunpuen2 6:7f99124272d9 392 }
gunpuen2 6:7f99124272d9 393 printf("\n");
gunpuen2 6:7f99124272d9 394 }
gunpuen2 6:7f99124272d9 395 }
gunpuen2 6:7f99124272d9 396 void print_atk_platform(){
gunpuen2 6:7f99124272d9 397 for(int i=0;i<8;i++){
gunpuen2 6:7f99124272d9 398 for(int j=0;j<8;j++){
gunpuen2 6:7f99124272d9 399 printf("| %d |",atk_platform[i][j]);
gunpuen2 6:7f99124272d9 400 }
gunpuen2 6:7f99124272d9 401 printf("\n");
gunpuen2 6:7f99124272d9 402 }
gunpuen2 6:7f99124272d9 403 }
gunpuen2 7:e35ba3ddb9af 404 void print_ship_destroyed(){
gunpuen2 8:a8d39b5d17ab 405 printf("{");
gunpuen2 7:e35ba3ddb9af 406 for(int i=0;i<8;i++){
gunpuen2 7:e35ba3ddb9af 407 printf("%d",ship_destroyed[i]);
gunpuen2 7:e35ba3ddb9af 408 if(i!=14){printf(",");}
gunpuen2 7:e35ba3ddb9af 409 }
gunpuen2 7:e35ba3ddb9af 410 printf("}\n");
gunpuen2 7:e35ba3ddb9af 411 }
gunpuen2 0:a8e057156263 412 void check_ready(){
gunpuen2 16:3fac68a7fd7c 413 if(bt.readable()){enemy_ready = 1;}
gunpuen2 1:6157c77da3d5 414 }
gunpuen2 1:6157c77da3d5 415 char posit2char(int posit){
gunpuen2 1:6157c77da3d5 416 int as = posit+48;
gunpuen2 1:6157c77da3d5 417 char ch = as;
gunpuen2 1:6157c77da3d5 418 return ch ;
gunpuen2 1:6157c77da3d5 419 }
gunpuen2 1:6157c77da3d5 420 int char2posit(char cha){
gunpuen2 1:6157c77da3d5 421 int as = cha;
gunpuen2 1:6157c77da3d5 422 as = as-48;
gunpuen2 1:6157c77da3d5 423 return as;
gunpuen2 1:6157c77da3d5 424 }
gunpuen2 15:5902cf545449 425 void get_atk_platform(int atkpos){
gunpuen2 4:8a86bacddcac 426 int i,j,x,y = 0;
gunpuen2 1:6157c77da3d5 427
gunpuen2 7:e35ba3ddb9af 428 x = atkpos/10;
gunpuen2 7:e35ba3ddb9af 429 y = atkpos%10;
gunpuen2 1:6157c77da3d5 430
gunpuen2 2:d93832fe8deb 431 if(ship_platform[x][y]!=0 and atk_platform[x][y]==0){
gunpuen2 1:6157c77da3d5 432 atk_platform[x][y] = ship_platform[x][y];
gunpuen2 6:7f99124272d9 433 bt.putc(posit2char(atk_platform[x][y]));
gunpuen2 9:102af5021c6c 434 ship_underATK[check_ship_underATK] = (x*10)+y;
gunpuen2 2:d93832fe8deb 435 if(atk_platform[x][y]==4){
gunpuen2 2:d93832fe8deb 436 for(i=0;i<4;i++){
gunpuen2 2:d93832fe8deb 437 for(j=0;j<15;j++){
gunpuen2 16:3fac68a7fd7c 438 if(ship4[i]==ship_underATK[j]){ship_destroyed[0]++;}
gunpuen2 2:d93832fe8deb 439 }
gunpuen2 2:d93832fe8deb 440 }
gunpuen2 2:d93832fe8deb 441 }else if(atk_platform[x][y]==3){
gunpuen2 2:d93832fe8deb 442 for(i=0;i<3;i++){
gunpuen2 2:d93832fe8deb 443 for(j=0;j<15;j++){
gunpuen2 16:3fac68a7fd7c 444 if(ship3[i]==ship_underATK[j]){ship_destroyed[1]++;}
gunpuen2 2:d93832fe8deb 445 }
gunpuen2 2:d93832fe8deb 446 }
gunpuen2 2:d93832fe8deb 447 }else if(atk_platform[x][y]==2){
gunpuen2 2:d93832fe8deb 448 for(i=0;i<4;i++){
gunpuen2 2:d93832fe8deb 449 for(j=0;j<15;j++){
gunpuen2 16:3fac68a7fd7c 450 if(ship2[0][i]==ship_underATK[j]){ship_destroyed[2]++;}
gunpuen2 16:3fac68a7fd7c 451 if(ship2[1][i]==ship_underATK[j]){ship_destroyed[3]++;}
gunpuen2 2:d93832fe8deb 452 }
gunpuen2 2:d93832fe8deb 453 }
gunpuen2 2:d93832fe8deb 454 }else if(atk_platform[x][y]==1){
gunpuen2 2:d93832fe8deb 455 for(i=0;i<4;i++){
gunpuen2 2:d93832fe8deb 456 for(j=0;j<15;j++){
gunpuen2 2:d93832fe8deb 457 if(ship3[i]==ship_underATK[j]){
gunpuen2 2:d93832fe8deb 458 ship_destroyed[4+i]++;
gunpuen2 4:8a86bacddcac 459 atk_platform[x][y] = 11;
gunpuen2 2:d93832fe8deb 460 }
gunpuen2 2:d93832fe8deb 461 }
gunpuen2 2:d93832fe8deb 462 }
gunpuen2 2:d93832fe8deb 463 }
gunpuen2 1:6157c77da3d5 464 }else{
gunpuen2 1:6157c77da3d5 465 atk_platform[x][y] = 8;
gunpuen2 6:7f99124272d9 466 bt.putc(posit2char(atk_platform[x][y]));
gunpuen2 0:a8e057156263 467 }
gunpuen2 0:a8e057156263 468 }
gunpuen2 4:8a86bacddcac 469 void mark_ship_destroyed(){
gunpuen2 4:8a86bacddcac 470 int i,j,k = 0;
gunpuen2 0:a8e057156263 471
gunpuen2 11:305164107874 472 if(ship_destroyed[0]==10){
gunpuen2 4:8a86bacddcac 473 for(i=0;i<8;i++){
gunpuen2 4:8a86bacddcac 474 for(j=0;j<8;j++){
gunpuen2 16:3fac68a7fd7c 475 if(atk_platform[i][j]==4){atk_platform[i][j] = 11;}
gunpuen2 4:8a86bacddcac 476 }
gunpuen2 4:8a86bacddcac 477 }
gunpuen2 13:eee9af3b4308 478 }
gunpuen2 13:eee9af3b4308 479 if(ship_destroyed[1]==6){
gunpuen2 4:8a86bacddcac 480 for(i=0;i<8;i++){
gunpuen2 4:8a86bacddcac 481 for(j=0;j<8;j++){
gunpuen2 16:3fac68a7fd7c 482 if(atk_platform[i][j]==3){atk_platform[i][j] = 11;}
gunpuen2 4:8a86bacddcac 483 }
gunpuen2 4:8a86bacddcac 484 }
gunpuen2 13:eee9af3b4308 485 }
gunpuen2 13:eee9af3b4308 486 if(ship_destroyed[2]==3){
gunpuen2 4:8a86bacddcac 487 for(k=0;k<2;k++){
gunpuen2 4:8a86bacddcac 488 i = ship2[0][k]/10;
gunpuen2 4:8a86bacddcac 489 j = ship2[0][k]%10;
gunpuen2 4:8a86bacddcac 490 atk_platform[i][j] = 11;
gunpuen2 4:8a86bacddcac 491 }
gunpuen2 13:eee9af3b4308 492 }
gunpuen2 13:eee9af3b4308 493 if(ship_destroyed[3]==3){
gunpuen2 4:8a86bacddcac 494 for(k=0;k<2;k++){
gunpuen2 4:8a86bacddcac 495 i = ship2[1][k]/10;
gunpuen2 4:8a86bacddcac 496 j = ship2[1][k]%10;
gunpuen2 4:8a86bacddcac 497 atk_platform[i][j] = 11;
gunpuen2 4:8a86bacddcac 498 }
gunpuen2 4:8a86bacddcac 499 }
gunpuen2 6:7f99124272d9 500 }
gunpuen2 6:7f99124272d9 501 void atk_enemy(){
gunpuen2 6:7f99124272d9 502 float Vx;
gunpuen2 6:7f99124272d9 503 float Vy;
gunpuen2 7:e35ba3ddb9af 504 int SW,iVxVy,iSW,n = 0;
gunpuen2 7:e35ba3ddb9af 505 int iPrintUturn = 0;
gunpuen2 6:7f99124272d9 506 char m;
gunpuen2 6:7f99124272d9 507
gunpuen2 14:8abed4026326 508 select_Position = 0;
gunpuen2 6:7f99124272d9 509 while(1){
gunpuen2 6:7f99124272d9 510 if(iPrintUturn==0){
gunpuen2 6:7f99124272d9 511 printf("Your turn.\n");
gunpuen2 6:7f99124272d9 512 iPrintUturn = 1;
gunpuen2 6:7f99124272d9 513 }
gunpuen2 6:7f99124272d9 514 Vx = VRx.read() * 1024;
gunpuen2 6:7f99124272d9 515 Vy = VRy.read() * 1024;
gunpuen2 6:7f99124272d9 516 SW = Button.read();
gunpuen2 6:7f99124272d9 517 m = check_joys(Vx,Vy);
gunpuen2 6:7f99124272d9 518 n = check_joys_int(Vx,Vy);
gunpuen2 16:3fac68a7fd7c 519 if(n == 1){ iVxVy = 0;}
gunpuen2 6:7f99124272d9 520 if(SW == 1){
gunpuen2 6:7f99124272d9 521 iSW = 0;
gunpuen2 6:7f99124272d9 522 if(bt.readable()){
gunpuen2 6:7f99124272d9 523 enemy_platform[select_Position/10][select_Position%10] = char2posit(bt.getc());
gunpuen2 6:7f99124272d9 524 break;
gunpuen2 6:7f99124272d9 525 }
gunpuen2 6:7f99124272d9 526 }
gunpuen2 6:7f99124272d9 527 if(m!=NULL && iVxVy==0){
gunpuen2 23:66a401850f2e 528 Select_Position(m,1);
gunpuen2 6:7f99124272d9 529 printf("select_Position = %d\n",select_Position);
gunpuen2 6:7f99124272d9 530 bt.putc(posit2char(select_Position));
gunpuen2 6:7f99124272d9 531 iVxVy = 1;
gunpuen2 6:7f99124272d9 532 }
gunpuen2 6:7f99124272d9 533 if(SW==0 && iSW==0){
gunpuen2 6:7f99124272d9 534 bt.putc('B');
gunpuen2 6:7f99124272d9 535 printf("You attacking at position %d\n",select_Position);
gunpuen2 6:7f99124272d9 536 iSW = 1;
gunpuen2 6:7f99124272d9 537 }
gunpuen2 6:7f99124272d9 538 }
gunpuen2 6:7f99124272d9 539 }
gunpuen2 6:7f99124272d9 540 void enemy_atk(){
gunpuen2 6:7f99124272d9 541 int data_fromEnemy;
gunpuen2 19:d78586719868 542 char replica_data_fromEnemy;
gunpuen2 6:7f99124272d9 543 printf("Wait for enemy attack.\n");
gunpuen2 13:eee9af3b4308 544 select_Position = 0;
gunpuen2 6:7f99124272d9 545 while(1){
gunpuen2 6:7f99124272d9 546 if(bt.readable()){
gunpuen2 21:d76aa19984be 547 replica_data_fromEnemy = bt.getc();
gunpuen2 20:4b9be9a423a8 548 if(replica_data_fromEnemy!='q' and replica_data_fromEnemy!=8){
gunpuen2 19:d78586719868 549 data_fromEnemy = char2posit(replica_data_fromEnemy);
gunpuen2 19:d78586719868 550 if(data_fromEnemy!=18){
gunpuen2 19:d78586719868 551 select_Position = data_fromEnemy;
gunpuen2 19:d78586719868 552 printf("enemy select_Position = %d\n",select_Position);
gunpuen2 19:d78586719868 553 }else{
gunpuen2 19:d78586719868 554 ATKposition = select_Position;
gunpuen2 19:d78586719868 555 break;
gunpuen2 19:d78586719868 556 }
gunpuen2 21:d76aa19984be 557 }
gunpuen2 21:d76aa19984be 558 if(replica_data_fromEnemy=='q'){
gunpuen2 19:d78586719868 559 check_win = 1;
gunpuen2 6:7f99124272d9 560 break;
gunpuen2 6:7f99124272d9 561 }
gunpuen2 6:7f99124272d9 562 }
gunpuen2 6:7f99124272d9 563 }
gunpuen2 19:d78586719868 564 if(check_win!=1){
gunpuen2 19:d78586719868 565 printf("Enemy attack at your area %d\n",ATKposition);
gunpuen2 19:d78586719868 566 get_atk_platform(ATKposition);
gunpuen2 19:d78586719868 567 check_ship_underATK++;
gunpuen2 19:d78586719868 568 mark_ship_destroyed();
gunpuen2 19:d78586719868 569 }
gunpuen2 7:e35ba3ddb9af 570 }
gunpuen2 7:e35ba3ddb9af 571 int TellUrEnemy_uWin(){
gunpuen2 7:e35ba3ddb9af 572 int sub_end = 0;
gunpuen2 7:e35ba3ddb9af 573
gunpuen2 7:e35ba3ddb9af 574 for(int i=0;i<15;i++){
gunpuen2 11:305164107874 575 if(ship_underATK[i]!=9){sub_end++;}
gunpuen2 7:e35ba3ddb9af 576 }
gunpuen2 8:a8d39b5d17ab 577 if(sub_end==15){return 1;}else{return 0;}
gunpuen2 7:e35ba3ddb9af 578 }
gunpuen2 7:e35ba3ddb9af 579 int IamWin(){
gunpuen2 17:aeb7cbfb8640 580 char chare;
gunpuen2 17:aeb7cbfb8640 581 if(bt.readable()){
gunpuen2 18:ecef8382d41e 582 chare = bt.getc();
gunpuen2 17:aeb7cbfb8640 583 if(chare=='q'){return 1;}else{return 0;}
gunpuen2 17:aeb7cbfb8640 584 }else{return 0;}
gunpuen2 23:66a401850f2e 585 }
gunpuen2 23:66a401850f2e 586
gunpuen2 23:66a401850f2e 587 // ______________________________________________________________________________Nasarun's function.
gunpuen2 23:66a401850f2e 588
gunpuen2 23:66a401850f2e 589 void hex_to_array(int* ar){
gunpuen2 23:66a401850f2e 590 int i;
gunpuen2 23:66a401850f2e 591 int j;
gunpuen2 23:66a401850f2e 592 int temp;
gunpuen2 23:66a401850f2e 593 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 594 temp = ar[i];
gunpuen2 23:66a401850f2e 595 for(j = 0;j<8;j++){
gunpuen2 23:66a401850f2e 596 if(0x80 & temp){
gunpuen2 23:66a401850f2e 597 return_position[i][j] = 1;
gunpuen2 23:66a401850f2e 598 }
gunpuen2 23:66a401850f2e 599 else{
gunpuen2 23:66a401850f2e 600 return_position[i][j] = 0;
gunpuen2 23:66a401850f2e 601 }
gunpuen2 23:66a401850f2e 602 temp = temp << 1;
gunpuen2 23:66a401850f2e 603 }
gunpuen2 23:66a401850f2e 604 }
gunpuen2 23:66a401850f2e 605 }
gunpuen2 23:66a401850f2e 606
gunpuen2 23:66a401850f2e 607 void ch_same_position(int ar1[8][8],int ar2[8][8]){
gunpuen2 23:66a401850f2e 608 int i;
gunpuen2 23:66a401850f2e 609 int j;
gunpuen2 23:66a401850f2e 610 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 611 for(j = 0;j<8;j++){
gunpuen2 23:66a401850f2e 612 if(ar1[i][j] == 1 && ar2[i][j] == 1){
gunpuen2 23:66a401850f2e 613 ch_post[i][j] = 1;
gunpuen2 23:66a401850f2e 614 }
gunpuen2 23:66a401850f2e 615 else{
gunpuen2 23:66a401850f2e 616 ch_post[i][j] = 0;
gunpuen2 23:66a401850f2e 617 }
gunpuen2 23:66a401850f2e 618 }
gunpuen2 23:66a401850f2e 619 }
gunpuen2 23:66a401850f2e 620
gunpuen2 23:66a401850f2e 621 }
gunpuen2 23:66a401850f2e 622
gunpuen2 23:66a401850f2e 623 void discard_same_position(int ar1[8][8],int ar2[8][8]){
gunpuen2 23:66a401850f2e 624 int i;
gunpuen2 23:66a401850f2e 625 int j;
gunpuen2 23:66a401850f2e 626 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 627 for(j = 0;j<8;j++){
gunpuen2 23:66a401850f2e 628 if(ar1[i][j] == ch_post[i][j] && ar2[i][j] == ch_post[i][j] ){
gunpuen2 23:66a401850f2e 629 ar1[i][j] = 0;
gunpuen2 23:66a401850f2e 630 ar2[i][j] = 0;
gunpuen2 23:66a401850f2e 631 }
gunpuen2 23:66a401850f2e 632 }
gunpuen2 23:66a401850f2e 633 }
gunpuen2 23:66a401850f2e 634 }
gunpuen2 23:66a401850f2e 635
gunpuen2 23:66a401850f2e 636
gunpuen2 23:66a401850f2e 637 int _power(int number , int power){
gunpuen2 23:66a401850f2e 638 int i = 0;
gunpuen2 23:66a401850f2e 639 int number1 = number;
gunpuen2 23:66a401850f2e 640 if(power == 0){return 1;}
gunpuen2 23:66a401850f2e 641 for(i = 1 ; i <= power ; i++ ){
gunpuen2 23:66a401850f2e 642 if(power == 1){return number;}
gunpuen2 23:66a401850f2e 643 if(i == 1){number = number * 1;}
gunpuen2 23:66a401850f2e 644 else{number1 = number1 * number;}
gunpuen2 23:66a401850f2e 645 }
gunpuen2 23:66a401850f2e 646 return number1;
gunpuen2 23:66a401850f2e 647 }
gunpuen2 23:66a401850f2e 648
gunpuen2 23:66a401850f2e 649
gunpuen2 23:66a401850f2e 650 void array_to_hex(int ar1[8][8]){
gunpuen2 23:66a401850f2e 651 int prompt;
gunpuen2 23:66a401850f2e 652 int i;
gunpuen2 23:66a401850f2e 653 int j;
gunpuen2 23:66a401850f2e 654 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 655 for(j = 0;j<8;j++){
gunpuen2 23:66a401850f2e 656 prompt = _power(2,7-j);
gunpuen2 23:66a401850f2e 657 if(ar1[i][j] == 1){
gunpuen2 23:66a401850f2e 658 for_hex = for_hex + prompt;
gunpuen2 23:66a401850f2e 659 }
gunpuen2 23:66a401850f2e 660 else{
gunpuen2 23:66a401850f2e 661 for_hex = for_hex + 0;
gunpuen2 23:66a401850f2e 662 }
gunpuen2 23:66a401850f2e 663 }
gunpuen2 23:66a401850f2e 664 return_hex[i] = for_hex;
gunpuen2 23:66a401850f2e 665 prompt = 0;
gunpuen2 23:66a401850f2e 666 for_hex = 0;
gunpuen2 23:66a401850f2e 667 }
gunpuen2 23:66a401850f2e 668 }
gunpuen2 23:66a401850f2e 669
gunpuen2 23:66a401850f2e 670 void place_ship3(char dir){
gunpuen2 23:66a401850f2e 671 int post1[8][8] = {0};
gunpuen2 23:66a401850f2e 672 int post2[8][8] = {0};
gunpuen2 23:66a401850f2e 673 int hex_post1[8] = {0};
gunpuen2 23:66a401850f2e 674 int hex_post2[8] = {0};
gunpuen2 23:66a401850f2e 675 int hex_post_cut[8] = {0};
gunpuen2 23:66a401850f2e 676 int get_same_position[8][8];
gunpuen2 23:66a401850f2e 677 int wow=0;
gunpuen2 23:66a401850f2e 678
gunpuen2 23:66a401850f2e 679 if(dir == 'w'&& temppic2[0] == 0){
gunpuen2 23:66a401850f2e 680 printf("w\n");
gunpuen2 23:66a401850f2e 681 for(j=0;j<8;j++){
gunpuen2 23:66a401850f2e 682 if(j == 7){
gunpuen2 23:66a401850f2e 683 forshift[7] = 0;
gunpuen2 23:66a401850f2e 684 }
gunpuen2 23:66a401850f2e 685 else{
gunpuen2 23:66a401850f2e 686 forshift[j] = temppic2[j+1];
gunpuen2 23:66a401850f2e 687 }
gunpuen2 23:66a401850f2e 688 }
gunpuen2 23:66a401850f2e 689 for(j=0;j<8;j++){
gunpuen2 23:66a401850f2e 690 temppic2[j] = forshift[j];
gunpuen2 23:66a401850f2e 691 _temppic[j] = temppic2[j];
gunpuen2 23:66a401850f2e 692 }
gunpuen2 23:66a401850f2e 693 // begin to compare and combine two frame
gunpuen2 23:66a401850f2e 694 hex_to_array(_temppic);
gunpuen2 23:66a401850f2e 695 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 696 for(j = 0;j<8;j++){
gunpuen2 23:66a401850f2e 697 post1[i][j] = return_position[i][j];
gunpuen2 23:66a401850f2e 698 }
gunpuen2 23:66a401850f2e 699 }
gunpuen2 23:66a401850f2e 700 hex_to_array(pic);
gunpuen2 23:66a401850f2e 701 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 702 for(j = 0;j<8;j++){
gunpuen2 23:66a401850f2e 703 post2[i][j] = return_position[i][j];
gunpuen2 23:66a401850f2e 704 }
gunpuen2 23:66a401850f2e 705 }
gunpuen2 23:66a401850f2e 706
gunpuen2 23:66a401850f2e 707 // begin to check boypeacemaker
gunpuen2 23:66a401850f2e 708 ch_same_position(post1,post2);
gunpuen2 23:66a401850f2e 709 for(i=0;i<8;i++){
gunpuen2 23:66a401850f2e 710 for(j=0;j<8;j++){
gunpuen2 23:66a401850f2e 711 get_same_position[i][j] = ch_post[i][j];
gunpuen2 23:66a401850f2e 712 if(get_same_position[i][j] == 1){
gunpuen2 23:66a401850f2e 713 wow = 1;
gunpuen2 23:66a401850f2e 714 }
gunpuen2 23:66a401850f2e 715 }
gunpuen2 23:66a401850f2e 716 }
gunpuen2 23:66a401850f2e 717 if(wow == 0){
gunpuen2 23:66a401850f2e 718 for(i=0;i<8;i++){_temppic[i] = temppic2[i]+pic[i];}
gunpuen2 23:66a401850f2e 719 }
gunpuen2 23:66a401850f2e 720 else{
gunpuen2 23:66a401850f2e 721 discard_same_position(post1,post2);
gunpuen2 23:66a401850f2e 722 array_to_hex(post1);
gunpuen2 23:66a401850f2e 723 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 724 hex_post1[i] = return_hex[i];
gunpuen2 23:66a401850f2e 725 }
gunpuen2 23:66a401850f2e 726 array_to_hex(post2);
gunpuen2 23:66a401850f2e 727 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 728 hex_post2[i] = return_hex[i];
gunpuen2 23:66a401850f2e 729 }
gunpuen2 23:66a401850f2e 730 array_to_hex(get_same_position);
gunpuen2 23:66a401850f2e 731 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 732 hex_post_cut[i] = return_hex[i];
gunpuen2 23:66a401850f2e 733 }
gunpuen2 23:66a401850f2e 734 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 735 _temppic[i] = hex_post1[i] + hex_post2[i] + hex_post_cut[i];
gunpuen2 23:66a401850f2e 736 }
gunpuen2 23:66a401850f2e 737 }
gunpuen2 23:66a401850f2e 738 }
gunpuen2 23:66a401850f2e 739 if(dir == 'd'){
gunpuen2 23:66a401850f2e 740 printf("d\n");
gunpuen2 23:66a401850f2e 741
gunpuen2 23:66a401850f2e 742 for(i=0;i<8;i++){
gunpuen2 23:66a401850f2e 743 if(temppic2[i] == 0xe0){
gunpuen2 23:66a401850f2e 744 check_boat3 = 1;
gunpuen2 23:66a401850f2e 745 }
gunpuen2 23:66a401850f2e 746 }
gunpuen2 23:66a401850f2e 747 if(check_boat3 == 0){
gunpuen2 23:66a401850f2e 748 for(j=0;j<8;j++){
gunpuen2 23:66a401850f2e 749 if(temppic2[j] != 0){
gunpuen2 23:66a401850f2e 750 temppic2[j] = temppic2[j]*2;
gunpuen2 23:66a401850f2e 751 }
gunpuen2 23:66a401850f2e 752 else{
gunpuen2 23:66a401850f2e 753 temppic2[j] = 0;
gunpuen2 23:66a401850f2e 754 }
gunpuen2 23:66a401850f2e 755 _temppic[j] = temppic2[j];
gunpuen2 23:66a401850f2e 756 }
gunpuen2 23:66a401850f2e 757 // begin to compare and combine two frame
gunpuen2 23:66a401850f2e 758 hex_to_array(_temppic);
gunpuen2 23:66a401850f2e 759 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 760 for(j = 0;j<8;j++){
gunpuen2 23:66a401850f2e 761 post1[i][j] = return_position[i][j];
gunpuen2 23:66a401850f2e 762 }
gunpuen2 23:66a401850f2e 763 }
gunpuen2 23:66a401850f2e 764 hex_to_array(pic);
gunpuen2 23:66a401850f2e 765 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 766 for(j = 0;j<8;j++){
gunpuen2 23:66a401850f2e 767 post2[i][j] = return_position[i][j];
gunpuen2 23:66a401850f2e 768 }
gunpuen2 23:66a401850f2e 769 }
gunpuen2 23:66a401850f2e 770
gunpuen2 23:66a401850f2e 771 // begin to check boypeacemaker
gunpuen2 23:66a401850f2e 772 ch_same_position(post1,post2);
gunpuen2 23:66a401850f2e 773 for(i=0;i<8;i++){
gunpuen2 23:66a401850f2e 774 for(j=0;j<8;j++){
gunpuen2 23:66a401850f2e 775 get_same_position[i][j] = ch_post[i][j];
gunpuen2 23:66a401850f2e 776 if(get_same_position[i][j] == 1){
gunpuen2 23:66a401850f2e 777 wow = 1;
gunpuen2 23:66a401850f2e 778 }
gunpuen2 23:66a401850f2e 779 }
gunpuen2 23:66a401850f2e 780 }
gunpuen2 23:66a401850f2e 781 if(wow == 0){
gunpuen2 23:66a401850f2e 782 for(i=0;i<8;i++){_temppic[i] = temppic2[i]+pic[i];}
gunpuen2 23:66a401850f2e 783 }
gunpuen2 23:66a401850f2e 784 else{
gunpuen2 23:66a401850f2e 785 discard_same_position(post1,post2);
gunpuen2 23:66a401850f2e 786 array_to_hex(post1);
gunpuen2 23:66a401850f2e 787 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 788 hex_post1[i] = return_hex[i];
gunpuen2 23:66a401850f2e 789 }
gunpuen2 23:66a401850f2e 790 array_to_hex(post2);
gunpuen2 23:66a401850f2e 791 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 792 hex_post2[i] = return_hex[i];
gunpuen2 23:66a401850f2e 793 }
gunpuen2 23:66a401850f2e 794 array_to_hex(get_same_position);
gunpuen2 23:66a401850f2e 795 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 796 hex_post_cut[i] = return_hex[i];
gunpuen2 23:66a401850f2e 797 }
gunpuen2 23:66a401850f2e 798 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 799 _temppic[i] = hex_post1[i] + hex_post2[i] + hex_post_cut[i];
gunpuen2 23:66a401850f2e 800 }
gunpuen2 23:66a401850f2e 801 }
gunpuen2 23:66a401850f2e 802 }
gunpuen2 23:66a401850f2e 803 check_boat3 = 0;
gunpuen2 23:66a401850f2e 804 }
gunpuen2 23:66a401850f2e 805 if(dir == 'a'){
gunpuen2 23:66a401850f2e 806 printf("a\n");
gunpuen2 23:66a401850f2e 807 for(i=0;i<8;i++){
gunpuen2 23:66a401850f2e 808 if(temppic2[i] == 0x07){
gunpuen2 23:66a401850f2e 809 check_boat3 = 1;
gunpuen2 23:66a401850f2e 810 }
gunpuen2 23:66a401850f2e 811 }
gunpuen2 23:66a401850f2e 812 if(check_boat3 == 0){
gunpuen2 23:66a401850f2e 813 for(j=0;j<8;j++){
gunpuen2 23:66a401850f2e 814 if(temppic2[j] != 0){
gunpuen2 23:66a401850f2e 815 temppic2[j] = temppic2[j]/2;
gunpuen2 23:66a401850f2e 816 }
gunpuen2 23:66a401850f2e 817 else{
gunpuen2 23:66a401850f2e 818 temppic2[j] = 0;
gunpuen2 23:66a401850f2e 819 }
gunpuen2 23:66a401850f2e 820 _temppic[j] = temppic2[j];
gunpuen2 23:66a401850f2e 821 }
gunpuen2 23:66a401850f2e 822 // begin to compare and combine two frame
gunpuen2 23:66a401850f2e 823 hex_to_array(_temppic);
gunpuen2 23:66a401850f2e 824 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 825 for(j = 0;j<8;j++){
gunpuen2 23:66a401850f2e 826 post1[i][j] = return_position[i][j];
gunpuen2 23:66a401850f2e 827 }
gunpuen2 23:66a401850f2e 828 }
gunpuen2 23:66a401850f2e 829 hex_to_array(pic);
gunpuen2 23:66a401850f2e 830 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 831 for(j = 0;j<8;j++){
gunpuen2 23:66a401850f2e 832 post2[i][j] = return_position[i][j];
gunpuen2 23:66a401850f2e 833 }
gunpuen2 23:66a401850f2e 834 }
gunpuen2 23:66a401850f2e 835
gunpuen2 23:66a401850f2e 836 // begin to check boypeacemaker
gunpuen2 23:66a401850f2e 837 ch_same_position(post1,post2);
gunpuen2 23:66a401850f2e 838 for(i=0;i<8;i++){
gunpuen2 23:66a401850f2e 839 for(j=0;j<8;j++){
gunpuen2 23:66a401850f2e 840 get_same_position[i][j] = ch_post[i][j];
gunpuen2 23:66a401850f2e 841 if(get_same_position[i][j] == 1){
gunpuen2 23:66a401850f2e 842 wow = 1;
gunpuen2 23:66a401850f2e 843 }
gunpuen2 23:66a401850f2e 844 }
gunpuen2 23:66a401850f2e 845 }
gunpuen2 23:66a401850f2e 846 if(wow == 0){
gunpuen2 23:66a401850f2e 847 for(i=0;i<8;i++){_temppic[i] = temppic2[i]+pic[i];}
gunpuen2 23:66a401850f2e 848 }
gunpuen2 23:66a401850f2e 849 else{
gunpuen2 23:66a401850f2e 850 discard_same_position(post1,post2);
gunpuen2 23:66a401850f2e 851 array_to_hex(post1);
gunpuen2 23:66a401850f2e 852 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 853 hex_post1[i] = return_hex[i];
gunpuen2 23:66a401850f2e 854 }
gunpuen2 23:66a401850f2e 855 array_to_hex(post2);
gunpuen2 23:66a401850f2e 856 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 857 hex_post2[i] = return_hex[i];
gunpuen2 23:66a401850f2e 858 }
gunpuen2 23:66a401850f2e 859 array_to_hex(get_same_position);
gunpuen2 23:66a401850f2e 860 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 861 hex_post_cut[i] = return_hex[i];
gunpuen2 23:66a401850f2e 862 }
gunpuen2 23:66a401850f2e 863 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 864 _temppic[i] = hex_post1[i] + hex_post2[i] + hex_post_cut[i];
gunpuen2 23:66a401850f2e 865 }
gunpuen2 23:66a401850f2e 866 }
gunpuen2 23:66a401850f2e 867 }
gunpuen2 23:66a401850f2e 868 check_boat3 = 0;
gunpuen2 23:66a401850f2e 869 }
gunpuen2 23:66a401850f2e 870 if(dir == 's' && temppic2[7] == 0){
gunpuen2 23:66a401850f2e 871 printf("s\n");
gunpuen2 23:66a401850f2e 872 for(j=0;j<8;j++){
gunpuen2 23:66a401850f2e 873 if(j == 0){
gunpuen2 23:66a401850f2e 874 forshift[0] = 0;
gunpuen2 23:66a401850f2e 875 }
gunpuen2 23:66a401850f2e 876 else{
gunpuen2 23:66a401850f2e 877 forshift[j] = temppic2[j-1];
gunpuen2 23:66a401850f2e 878 }
gunpuen2 23:66a401850f2e 879 }
gunpuen2 23:66a401850f2e 880 for(j=0;j<8;j++){
gunpuen2 23:66a401850f2e 881 temppic2[j] = forshift[j];
gunpuen2 23:66a401850f2e 882 _temppic[j] = temppic2[j];
gunpuen2 23:66a401850f2e 883 }
gunpuen2 23:66a401850f2e 884 // begin to compare and combine two frame
gunpuen2 23:66a401850f2e 885 hex_to_array(_temppic);
gunpuen2 23:66a401850f2e 886 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 887 for(j = 0;j<8;j++){
gunpuen2 23:66a401850f2e 888 post1[i][j] = return_position[i][j];
gunpuen2 23:66a401850f2e 889 }
gunpuen2 23:66a401850f2e 890 }
gunpuen2 23:66a401850f2e 891 hex_to_array(pic);
gunpuen2 23:66a401850f2e 892 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 893 for(j = 0;j<8;j++){
gunpuen2 23:66a401850f2e 894 post2[i][j] = return_position[i][j];
gunpuen2 23:66a401850f2e 895 }
gunpuen2 23:66a401850f2e 896 }
gunpuen2 23:66a401850f2e 897
gunpuen2 23:66a401850f2e 898 // begin to check boypeacemaker
gunpuen2 23:66a401850f2e 899 ch_same_position(post1,post2);
gunpuen2 23:66a401850f2e 900 for(i=0;i<8;i++){
gunpuen2 23:66a401850f2e 901 for(j=0;j<8;j++){
gunpuen2 23:66a401850f2e 902 get_same_position[i][j] = ch_post[i][j];
gunpuen2 23:66a401850f2e 903 if(get_same_position[i][j] == 1){
gunpuen2 23:66a401850f2e 904 wow = 1;
gunpuen2 23:66a401850f2e 905 }
gunpuen2 23:66a401850f2e 906 }
gunpuen2 23:66a401850f2e 907 }
gunpuen2 23:66a401850f2e 908 if(wow == 0){
gunpuen2 23:66a401850f2e 909 for(i=0;i<8;i++){_temppic[i] = temppic2[i]+pic[i];}
gunpuen2 23:66a401850f2e 910 }
gunpuen2 23:66a401850f2e 911 else{
gunpuen2 23:66a401850f2e 912 discard_same_position(post1,post2);
gunpuen2 23:66a401850f2e 913 array_to_hex(post1);
gunpuen2 23:66a401850f2e 914 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 915 hex_post1[i] = return_hex[i];
gunpuen2 23:66a401850f2e 916 }
gunpuen2 23:66a401850f2e 917 array_to_hex(post2);
gunpuen2 23:66a401850f2e 918 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 919 hex_post2[i] = return_hex[i];
gunpuen2 23:66a401850f2e 920 }
gunpuen2 23:66a401850f2e 921 array_to_hex(get_same_position);
gunpuen2 23:66a401850f2e 922 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 923 hex_post_cut[i] = return_hex[i];
gunpuen2 23:66a401850f2e 924 }
gunpuen2 23:66a401850f2e 925 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 926 _temppic[i] = hex_post1[i] + hex_post2[i] + hex_post_cut[i];
gunpuen2 23:66a401850f2e 927 }
gunpuen2 23:66a401850f2e 928 }
gunpuen2 23:66a401850f2e 929
gunpuen2 23:66a401850f2e 930 }
gunpuen2 23:66a401850f2e 931 }
gunpuen2 23:66a401850f2e 932 // ******************************************************************** ship 2 channal ******************************************************************
gunpuen2 23:66a401850f2e 933
gunpuen2 23:66a401850f2e 934 void place_ship2_4(int ship,char dir){
gunpuen2 23:66a401850f2e 935
gunpuen2 23:66a401850f2e 936 int post1[8][8] = {0};
gunpuen2 23:66a401850f2e 937 int post2[8][8] = {0};
gunpuen2 23:66a401850f2e 938 int hex_post1[8] = {0};
gunpuen2 23:66a401850f2e 939 int hex_post2[8] = {0};
gunpuen2 23:66a401850f2e 940 int hex_post_cut[8] = {0};
gunpuen2 23:66a401850f2e 941 int get_same_position[8][8];
gunpuen2 23:66a401850f2e 942 int wow=0;
gunpuen2 23:66a401850f2e 943
gunpuen2 23:66a401850f2e 944 if(dir == 'w'&& temppic3[ship][0] == 0){
gunpuen2 23:66a401850f2e 945 printf("w\n");
gunpuen2 23:66a401850f2e 946 for(j=0;j<8;j++){
gunpuen2 23:66a401850f2e 947 if(j == 7){
gunpuen2 23:66a401850f2e 948 forshift[7] = 0;
gunpuen2 23:66a401850f2e 949 }
gunpuen2 23:66a401850f2e 950 else{
gunpuen2 23:66a401850f2e 951 forshift[j] = temppic3[ship][j+1];
gunpuen2 23:66a401850f2e 952 }
gunpuen2 23:66a401850f2e 953 }
gunpuen2 23:66a401850f2e 954 for(j=0;j<8;j++){
gunpuen2 23:66a401850f2e 955 temppic3[ship][j] = forshift[j];
gunpuen2 23:66a401850f2e 956 _temppic[j] = temppic3[ship][j];
gunpuen2 23:66a401850f2e 957 }
gunpuen2 23:66a401850f2e 958 // begin to compare and combine two frame
gunpuen2 23:66a401850f2e 959 hex_to_array(_temppic);
gunpuen2 23:66a401850f2e 960 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 961 for(j = 0;j<8;j++){
gunpuen2 23:66a401850f2e 962 post1[i][j] = return_position[i][j];
gunpuen2 23:66a401850f2e 963 }
gunpuen2 23:66a401850f2e 964 }
gunpuen2 23:66a401850f2e 965 hex_to_array(pic);
gunpuen2 23:66a401850f2e 966 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 967 for(j = 0;j<8;j++){
gunpuen2 23:66a401850f2e 968 post2[i][j] = return_position[i][j];
gunpuen2 23:66a401850f2e 969 }
gunpuen2 23:66a401850f2e 970 }
gunpuen2 23:66a401850f2e 971
gunpuen2 23:66a401850f2e 972 // begin to check boypeacemaker
gunpuen2 23:66a401850f2e 973 ch_same_position(post1,post2);
gunpuen2 23:66a401850f2e 974 for(i=0;i<8;i++){
gunpuen2 23:66a401850f2e 975 for(j=0;j<8;j++){
gunpuen2 23:66a401850f2e 976 get_same_position[i][j] = ch_post[i][j];
gunpuen2 23:66a401850f2e 977 if(get_same_position[i][j] == 1){
gunpuen2 23:66a401850f2e 978 wow = 1;
gunpuen2 23:66a401850f2e 979 }
gunpuen2 23:66a401850f2e 980 }
gunpuen2 23:66a401850f2e 981 }
gunpuen2 23:66a401850f2e 982 if(wow == 0){
gunpuen2 23:66a401850f2e 983 for(i=0;i<8;i++){_temppic[i] = temppic3[ship][i]+pic[i];}
gunpuen2 23:66a401850f2e 984 }
gunpuen2 23:66a401850f2e 985 else{
gunpuen2 23:66a401850f2e 986 discard_same_position(post1,post2);
gunpuen2 23:66a401850f2e 987 array_to_hex(post1);
gunpuen2 23:66a401850f2e 988 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 989 hex_post1[i] = return_hex[i];
gunpuen2 23:66a401850f2e 990 }
gunpuen2 23:66a401850f2e 991 array_to_hex(post2);
gunpuen2 23:66a401850f2e 992 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 993 hex_post2[i] = return_hex[i];
gunpuen2 23:66a401850f2e 994 }
gunpuen2 23:66a401850f2e 995 array_to_hex(get_same_position);
gunpuen2 23:66a401850f2e 996 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 997 hex_post_cut[i] = return_hex[i];
gunpuen2 23:66a401850f2e 998 }
gunpuen2 23:66a401850f2e 999 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 1000 _temppic[i] = hex_post1[i] + hex_post2[i] + hex_post_cut[i];
gunpuen2 23:66a401850f2e 1001 }
gunpuen2 23:66a401850f2e 1002 }
gunpuen2 23:66a401850f2e 1003
gunpuen2 23:66a401850f2e 1004 }
gunpuen2 23:66a401850f2e 1005 if(dir == 'd' && temppic3[ship][3] != 0x80 && temppic3[ship][4] != 0x80 ){
gunpuen2 23:66a401850f2e 1006 printf("d\n");
gunpuen2 23:66a401850f2e 1007 for(j=0;j<8;j++){
gunpuen2 23:66a401850f2e 1008 if(temppic3[j] != 0){
gunpuen2 23:66a401850f2e 1009 temppic3[ship][j] = temppic3[ship][j]*2;
gunpuen2 23:66a401850f2e 1010 }
gunpuen2 23:66a401850f2e 1011 else{
gunpuen2 23:66a401850f2e 1012 temppic3[ship][j] = 0;
gunpuen2 23:66a401850f2e 1013 }
gunpuen2 23:66a401850f2e 1014 _temppic[j] = temppic3[ship][j];
gunpuen2 23:66a401850f2e 1015 }
gunpuen2 23:66a401850f2e 1016 // begin to compare and combine two frame
gunpuen2 23:66a401850f2e 1017 hex_to_array(_temppic);
gunpuen2 23:66a401850f2e 1018 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 1019 for(j = 0;j<8;j++){
gunpuen2 23:66a401850f2e 1020 post1[i][j] = return_position[i][j];
gunpuen2 23:66a401850f2e 1021 }
gunpuen2 23:66a401850f2e 1022 }
gunpuen2 23:66a401850f2e 1023 hex_to_array(pic);
gunpuen2 23:66a401850f2e 1024 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 1025 for(j = 0;j<8;j++){
gunpuen2 23:66a401850f2e 1026 post2[i][j] = return_position[i][j];
gunpuen2 23:66a401850f2e 1027 }
gunpuen2 23:66a401850f2e 1028 }
gunpuen2 23:66a401850f2e 1029
gunpuen2 23:66a401850f2e 1030 // begin to check boypeacemaker
gunpuen2 23:66a401850f2e 1031 ch_same_position(post1,post2);
gunpuen2 23:66a401850f2e 1032 for(i=0;i<8;i++){
gunpuen2 23:66a401850f2e 1033 for(j=0;j<8;j++){
gunpuen2 23:66a401850f2e 1034 get_same_position[i][j] = ch_post[i][j];
gunpuen2 23:66a401850f2e 1035 if(get_same_position[i][j] == 1){
gunpuen2 23:66a401850f2e 1036 wow = 1;
gunpuen2 23:66a401850f2e 1037 }
gunpuen2 23:66a401850f2e 1038 }
gunpuen2 23:66a401850f2e 1039 }
gunpuen2 23:66a401850f2e 1040 if(wow == 0){
gunpuen2 23:66a401850f2e 1041 for(i=0;i<8;i++){_temppic[i] = temppic3[ship][i]+pic[i];}
gunpuen2 23:66a401850f2e 1042 }
gunpuen2 23:66a401850f2e 1043 else{
gunpuen2 23:66a401850f2e 1044 discard_same_position(post1,post2);
gunpuen2 23:66a401850f2e 1045 array_to_hex(post1);
gunpuen2 23:66a401850f2e 1046 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 1047 hex_post1[i] = return_hex[i];
gunpuen2 23:66a401850f2e 1048 }
gunpuen2 23:66a401850f2e 1049 array_to_hex(post2);
gunpuen2 23:66a401850f2e 1050 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 1051 hex_post2[i] = return_hex[i];
gunpuen2 23:66a401850f2e 1052 }
gunpuen2 23:66a401850f2e 1053 array_to_hex(get_same_position);
gunpuen2 23:66a401850f2e 1054 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 1055 hex_post_cut[i] = return_hex[i];
gunpuen2 23:66a401850f2e 1056 }
gunpuen2 23:66a401850f2e 1057 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 1058 _temppic[i] = hex_post1[i] + hex_post2[i] + hex_post_cut[i];
gunpuen2 23:66a401850f2e 1059 }
gunpuen2 23:66a401850f2e 1060 }
gunpuen2 23:66a401850f2e 1061
gunpuen2 23:66a401850f2e 1062 }
gunpuen2 23:66a401850f2e 1063 if(dir == 'a' && temppic3[ship][3] != 0x01 && temppic3[ship][4] != 0x01 ){
gunpuen2 23:66a401850f2e 1064 printf("a\n");
gunpuen2 23:66a401850f2e 1065 for(j=0;j<8;j++){
gunpuen2 23:66a401850f2e 1066 if(temppic3[ship][j] != 0){
gunpuen2 23:66a401850f2e 1067 temppic3[ship][j] = temppic3[ship][j]/2;
gunpuen2 23:66a401850f2e 1068 }
gunpuen2 23:66a401850f2e 1069 else{
gunpuen2 23:66a401850f2e 1070 temppic3[ship][j] = 0;
gunpuen2 23:66a401850f2e 1071 }
gunpuen2 23:66a401850f2e 1072 _temppic[j] = temppic3[ship][j];
gunpuen2 23:66a401850f2e 1073 }
gunpuen2 23:66a401850f2e 1074 // begin to compare and combine two frame
gunpuen2 23:66a401850f2e 1075 hex_to_array(_temppic);
gunpuen2 23:66a401850f2e 1076 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 1077 for(j = 0;j<8;j++){
gunpuen2 23:66a401850f2e 1078 post1[i][j] = return_position[i][j];
gunpuen2 23:66a401850f2e 1079 }
gunpuen2 23:66a401850f2e 1080 }
gunpuen2 23:66a401850f2e 1081 hex_to_array(pic);
gunpuen2 23:66a401850f2e 1082 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 1083 for(j = 0;j<8;j++){
gunpuen2 23:66a401850f2e 1084 post2[i][j] = return_position[i][j];
gunpuen2 23:66a401850f2e 1085 }
gunpuen2 23:66a401850f2e 1086 }
gunpuen2 23:66a401850f2e 1087
gunpuen2 23:66a401850f2e 1088 // begin to check boypeacemaker
gunpuen2 23:66a401850f2e 1089 ch_same_position(post1,post2);
gunpuen2 23:66a401850f2e 1090 for(i=0;i<8;i++){
gunpuen2 23:66a401850f2e 1091 for(j=0;j<8;j++){
gunpuen2 23:66a401850f2e 1092 get_same_position[i][j] = ch_post[i][j];
gunpuen2 23:66a401850f2e 1093 if(get_same_position[i][j] == 1){
gunpuen2 23:66a401850f2e 1094 wow = 1;
gunpuen2 23:66a401850f2e 1095 }
gunpuen2 23:66a401850f2e 1096 }
gunpuen2 23:66a401850f2e 1097 }
gunpuen2 23:66a401850f2e 1098 if(wow == 0){
gunpuen2 23:66a401850f2e 1099 for(i=0;i<8;i++){_temppic[i] = temppic3[ship][i]+pic[i];}
gunpuen2 23:66a401850f2e 1100 }
gunpuen2 23:66a401850f2e 1101 else{
gunpuen2 23:66a401850f2e 1102 discard_same_position(post1,post2);
gunpuen2 23:66a401850f2e 1103 array_to_hex(post1);
gunpuen2 23:66a401850f2e 1104 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 1105 hex_post1[i] = return_hex[i];
gunpuen2 23:66a401850f2e 1106 }
gunpuen2 23:66a401850f2e 1107 array_to_hex(post2);
gunpuen2 23:66a401850f2e 1108 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 1109 hex_post2[i] = return_hex[i];
gunpuen2 23:66a401850f2e 1110 }
gunpuen2 23:66a401850f2e 1111 array_to_hex(get_same_position);
gunpuen2 23:66a401850f2e 1112 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 1113 hex_post_cut[i] = return_hex[i];
gunpuen2 23:66a401850f2e 1114 }
gunpuen2 23:66a401850f2e 1115 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 1116 _temppic[i] = hex_post1[i] + hex_post2[i] + hex_post_cut[i];
gunpuen2 23:66a401850f2e 1117 }
gunpuen2 23:66a401850f2e 1118 }
gunpuen2 23:66a401850f2e 1119
gunpuen2 23:66a401850f2e 1120 }
gunpuen2 23:66a401850f2e 1121 if(dir == 's' && temppic3[ship][7] == 0){
gunpuen2 23:66a401850f2e 1122 printf("s\n");
gunpuen2 23:66a401850f2e 1123 for(j=0;j<8;j++){
gunpuen2 23:66a401850f2e 1124 if(j == 0){
gunpuen2 23:66a401850f2e 1125 forshift[0] = 0;
gunpuen2 23:66a401850f2e 1126 }
gunpuen2 23:66a401850f2e 1127 else{
gunpuen2 23:66a401850f2e 1128 forshift[j] = temppic3[ship][j-1];
gunpuen2 23:66a401850f2e 1129 }
gunpuen2 23:66a401850f2e 1130 }
gunpuen2 23:66a401850f2e 1131 for(j=0;j<8;j++){
gunpuen2 23:66a401850f2e 1132 temppic3[ship][j] = forshift[j];
gunpuen2 23:66a401850f2e 1133 _temppic[j] = temppic3[ship][j];
gunpuen2 23:66a401850f2e 1134 }
gunpuen2 23:66a401850f2e 1135 // begin to compare and combine two frame
gunpuen2 23:66a401850f2e 1136 hex_to_array(_temppic);
gunpuen2 23:66a401850f2e 1137 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 1138 for(j = 0;j<8;j++){
gunpuen2 23:66a401850f2e 1139 post1[i][j] = return_position[i][j];
gunpuen2 23:66a401850f2e 1140 }
gunpuen2 23:66a401850f2e 1141 }
gunpuen2 23:66a401850f2e 1142 hex_to_array(pic);
gunpuen2 23:66a401850f2e 1143 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 1144 for(j = 0;j<8;j++){
gunpuen2 23:66a401850f2e 1145 post2[i][j] = return_position[i][j];
gunpuen2 23:66a401850f2e 1146 }
gunpuen2 23:66a401850f2e 1147 }
gunpuen2 23:66a401850f2e 1148
gunpuen2 23:66a401850f2e 1149 // begin to check boypeacemaker
gunpuen2 23:66a401850f2e 1150 ch_same_position(post1,post2);
gunpuen2 23:66a401850f2e 1151 for(i=0;i<8;i++){
gunpuen2 23:66a401850f2e 1152 for(j=0;j<8;j++){
gunpuen2 23:66a401850f2e 1153 get_same_position[i][j] = ch_post[i][j];
gunpuen2 23:66a401850f2e 1154 if(get_same_position[i][j] == 1){
gunpuen2 23:66a401850f2e 1155 wow = 1;
gunpuen2 23:66a401850f2e 1156 }
gunpuen2 23:66a401850f2e 1157 }
gunpuen2 23:66a401850f2e 1158 }
gunpuen2 23:66a401850f2e 1159 if(wow == 0){
gunpuen2 23:66a401850f2e 1160 for(i=0;i<8;i++){_temppic[i] = temppic3[ship][i]+pic[i];}
gunpuen2 23:66a401850f2e 1161 }
gunpuen2 23:66a401850f2e 1162 else{
gunpuen2 23:66a401850f2e 1163 discard_same_position(post1,post2);
gunpuen2 23:66a401850f2e 1164 array_to_hex(post1);
gunpuen2 23:66a401850f2e 1165 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 1166 hex_post1[i] = return_hex[i];
gunpuen2 23:66a401850f2e 1167 }
gunpuen2 23:66a401850f2e 1168 array_to_hex(post2);
gunpuen2 23:66a401850f2e 1169 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 1170 hex_post2[i] = return_hex[i];
gunpuen2 23:66a401850f2e 1171 }
gunpuen2 23:66a401850f2e 1172 array_to_hex(get_same_position);
gunpuen2 23:66a401850f2e 1173 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 1174 hex_post_cut[i] = return_hex[i];
gunpuen2 23:66a401850f2e 1175 }
gunpuen2 23:66a401850f2e 1176 for(i = 0;i<8;i++){
gunpuen2 23:66a401850f2e 1177 _temppic[i] = hex_post1[i] + hex_post2[i] + hex_post_cut[i];
gunpuen2 23:66a401850f2e 1178 }
gunpuen2 23:66a401850f2e 1179 }
gunpuen2 23:66a401850f2e 1180
gunpuen2 23:66a401850f2e 1181 }
gunpuen2 4:8a86bacddcac 1182 }