Advertisement
Essam_khames

Untitled

Dec 23rd, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 35.30 KB | None | 0 0
  1. void move_piece(int i1, int j1,int i2, int j2,int turn){
  2.  
  3.  
  4. /* for player 1*/
  5. if(turn==1){
  6. /*moving pawn*/
  7. if(domain[i1][j1]=='p')
  8. {
  9. if(i1==1){
  10. /*if next square is correct and empty*/
  11. if((i2-i1==1||i2-i1==2)&&j1==j2&& occupied[i2][j2]==0&&occupied[i1+1][j2]==0){
  12. save_step(i1,j1,i2,j2,domain[i2][j2],domain[i1][j1]);
  13. domain[i2][j2]=domain[i1][j1];
  14. occupied[i1][j1]=0;
  15. occupied[i2][j2]=1;
  16.  
  17. } else if(i2==i1+1&&(j2==j1-1||j2==j1+1)&&occupied[i2][j2]==2)
  18. {
  19. save_step(i1,j1,i2,j2,domain[i2][j2],domain[i1][j1]);
  20. killed2[number_killed2]=domain[i2][j2];
  21. domain[i2][j2]=domain[i1][j1];
  22. number_killed2++;
  23. occupied[i1][j1]=0;
  24. occupied[i2][j2]=1;
  25.  
  26.  
  27.  
  28. }
  29. else
  30. {
  31. printf("Incorrect move.\nPlease re-enter your move.");
  32. movement();
  33. }
  34. }
  35. else if((i2-i1==1)&&j1==j2&& occupied[i2][j2]==0){
  36. save_step(i1,j1,i2,j2,domain[i2][j2],domain[i1][j1]);
  37. if(i2==7)
  38. {
  39. premote(&domain[i1][j1]);
  40. }
  41.  
  42. domain[i2][j2]=domain[i1][j1];
  43. occupied[i1][j1]=0;
  44. occupied[i2][j2]=1;
  45. return;
  46.  
  47.  
  48.  
  49. }
  50.  
  51. /*eaten player 2 piece*/
  52. else if(i2==i1+1&&(j2==j1-1||j2==j1+1)&&occupied[i2][j2]==2)
  53. { save_step(i1,j1,i2,j2,domain[i2][j2],domain[i1][j1]);
  54.  
  55. if(i2==7)
  56. {
  57. premote(&domain[i1][j1]);
  58.  
  59. }
  60.  
  61. killed2[number_killed2]=domain[i2][j2];
  62. domain[i2][j2]=domain[i1][j1];
  63. number_killed2++;
  64. occupied[i1][j1]=0;
  65. occupied[i2][j2]=1;
  66.  
  67.  
  68.  
  69. }
  70.  
  71. else
  72. {
  73. printf("Incorrect move.\nPlease re-enter your move.");
  74. movement();
  75. }
  76. return;
  77.  
  78. }
  79. /*moving tabya*/
  80. if(domain[i1][j1]=='r')
  81. {
  82. /*moving through the row*/
  83. if(i2==i1)
  84. {
  85. int n;
  86. if(j2>j1){
  87. for(n=j1+1;n<j2;n++)
  88. {
  89. if(occupied[i1][n])
  90. {
  91. printf("Incorrect move(a piece inside the path).\nPlease re-enter your move.");
  92. movement();
  93. goto OUT;
  94. }}}
  95. if(j1>j2)
  96. {
  97. for(n=j1-1;n>j2;n--)
  98. {
  99. if(occupied[i1][n])
  100. {
  101. printf("Incorrect move(a piece inside the path).\nPlease re-enter your move.");
  102. movement();
  103. goto OUT;
  104. }}
  105. }
  106. if(occupied[i1][j2]==1)
  107. {
  108. printf("Incorrect move(moving over your own piece).\nPlease re-enter your move.");
  109. movement();
  110. return;
  111. }save_step(i1,j1,i2,j2,domain[i2][j2],domain[i1][j1]);
  112. if(occupied[i2][j2]==2)
  113. {
  114. occupied[i2][j2]=1;
  115. occupied[i1][j1]=0;
  116. killed2[number_killed2]=domain[i2][j2];
  117. domain[i2][j2]=domain[i1][j1];
  118. number_killed2++;
  119. }
  120. if(occupied[i2][j2]==0)
  121. {
  122. domain[i2][j2]=domain[i1][j1];
  123. occupied[i1][j1]=0;
  124. occupied[i2][j2]=1;
  125.  
  126. }
  127. }
  128. else if(j2==j1)
  129. {
  130. int n;
  131. if(i2>i1)
  132. {
  133. for(n=i1+1;n<i2;n++)
  134. {
  135. if(occupied[n][j1])
  136. {
  137. printf("Incorrect move(a piece inside the path).\nPlease re-enter your move.");
  138. movement();
  139. return;
  140.  
  141. }}}
  142. if(i1>i2)
  143. {
  144. for(n=i1-1;n>i2;n--)
  145. {
  146. if(occupied[n][j1])
  147. {
  148. printf("Incorrect move(a piece inside the path).\nPlease re-enter your move.");
  149. movement();
  150. return;
  151.  
  152. }}
  153. }
  154. if(occupied[i2][j2]==1)
  155. {
  156. printf("Incorrect move(moving over your own piece).\nPlease re-enter your move.");
  157. movement();
  158. return;
  159. }save_step(i1,j1,i2,j2,domain[i2][j2],domain[i1][j1]);
  160. if(occupied[i2][j2]==2)
  161. {
  162. occupied[i1][j1]=0;
  163. occupied[i2][j2]=1;
  164. killed2[number_killed2]=domain[i2][j2];
  165. domain[i2][j2]=domain[i1][j1];
  166. number_killed2++;
  167. }
  168. if(occupied[i2][j2]==0)
  169. {
  170. occupied[i1][j1]=0;
  171. occupied[i2][j2]=1;
  172. domain[i2][j2]=domain[i1][j1];
  173. }
  174.  
  175. }else
  176. {
  177. printf("Incorrect move.\nPlease re-enter your move.");
  178. movement();
  179. }
  180.  
  181. }
  182. /*moving the knight*/
  183. if(domain[i1][j1]=='n')
  184. {
  185. if((i2==i1+2&&(j2==j1-1||j2==j1+1))||(i2==i1-2&&(j2==j1-1||j2==j1+1))||(j2==j1+2&&(i2==i1-1||i2==i1+1))||(j2==j1-2&&(i2==i1-1||i2==i1+1)))
  186. {
  187. if(occupied[i2][j2]==1)
  188. {
  189. printf("Incorrect move(moving over your own piece).\nPlease re-enter your move.");
  190. movement();
  191. return;
  192. }save_step(i1,j1,i2,j2,domain[i2][j2],domain[i1][j1]);
  193. if(occupied[i2][j2]==2)
  194. {
  195. occupied[i1][j1]=0;
  196. occupied[i2][j2]=1;
  197. killed2[number_killed2]=domain[i2][j2];
  198. domain[i2][j2]=domain[i1][j1];
  199. number_killed2++;
  200. }
  201. if(occupied[i2][j2]==0)
  202. {
  203. domain[i2][j2]=domain[i1][j1];
  204. occupied[i1][j1]=0;
  205. occupied[i2][j2]=1;
  206. }
  207. }else
  208. {
  209. printf("Incorrect move.\nPlease re-enter your move.");
  210. movement();
  211. }
  212. }
  213. if(domain[i1][j1]=='b')
  214. {
  215. int n,m;
  216. if(j2-j1==i2-i1 || j2-j1==i1-i2)
  217. {
  218. if(j2>j1&&i2>i1)
  219. {
  220. m=j1+1;
  221. for(n=i1+1;n<i2;n++)
  222. {
  223. if(occupied[n][m++])
  224. {
  225. printf("Incorrect move(a piece inside the path).\nPlease re-enter your move.");
  226. movement();
  227. return;
  228. }
  229.  
  230. }
  231. }
  232.  
  233.  
  234.  
  235.  
  236. else if(j1>j2 && i2>i1)
  237. {
  238. m=j1-1;
  239. for(n=i1+1;n<i2;n++)
  240. {
  241. if(occupied[n][m--])
  242. {
  243. printf("Incorrect move(a piece inside the path).\nPlease re-enter your move.");
  244. movement();
  245. return;
  246. }
  247.  
  248. }
  249. }
  250. else if (i1>i2 && j2>j1)
  251. {
  252. m=j1+1;
  253. for(n=i1-1;n>i2;n--)
  254. {
  255. if(occupied[n][m++])
  256. {
  257. printf("Incorrect move(a piece inside the path).\nPlease re-enter your move.");
  258. movement();
  259. return;
  260. }
  261.  
  262. }
  263.  
  264. }
  265. else if(i2<i1 && j2<j1)
  266. {
  267. m=j1-1;
  268. for(n=i1-1;n>i2;n--)
  269. {
  270. if(occupied[n][m--])
  271. {
  272. printf("Incorrect move(a piece inside the path).\nPlease re-enter your move.");
  273. movement();
  274. return;
  275. }
  276.  
  277. }
  278. }}
  279. else{
  280. printf("Incorrect move.\nPlease re-enter your move.");
  281. movement();
  282. return;
  283. }
  284. if(occupied[i2][j2]==1)
  285. {
  286. printf("Incorrect move(moving over your own piece).\nPlease re-enter your move.");
  287. movement();
  288. return;
  289. }
  290. if(occupied[i2][j2]==2)
  291. {
  292. save_step(i1,j1,i2,j2,domain[i2][j2],domain[i1][j1]);
  293. occupied[i1][j1]=0;
  294. occupied[i2][j2]=1;
  295. killed2[number_killed2]=domain[i2][j2];
  296. domain[i2][j2]=domain[i1][j1];
  297. number_killed2++;
  298. }
  299. if(occupied[i2][j2]==0)
  300. {
  301. save_step(i1,j1,i2,j2,domain[i2][j2],domain[i1][j1]);
  302. domain[i2][j2]=domain[i1][j1];
  303. occupied[i1][j1]=0;
  304. occupied[i2][j2]=1;
  305. }
  306.  
  307. }
  308.  
  309.  
  310.  
  311. }
  312. if(domain[i1][j1]=='q')
  313. {
  314. int n,m;
  315. if(j2-j1==i2-i1 || j2-j1==i1-i2)
  316. {
  317. if(j2>j1&&i2>i1)
  318. {
  319. m=j1+1;
  320. for(n=i1+1;n<i2;n++)
  321. {
  322. if(occupied[n][m++])
  323. {
  324. printf("Incorrect move(a piece inside the path).\nPlease re-enter your move.");
  325. movement();
  326. goto OUT;
  327. }
  328.  
  329. }
  330. }
  331.  
  332.  
  333.  
  334.  
  335. else if(j1>j2 && i2>i1)
  336. {
  337. m=j1-1;
  338. for(n=i1+1;n<i2;n++)
  339. {
  340. if(occupied[n][m--])
  341. {
  342. printf("Incorrect move(a piece inside the path).\nPlease re-enter your move.");
  343. movement();
  344. return;
  345. }
  346.  
  347. }
  348. }
  349. else if (i1>i2 && j2>j1)
  350. {
  351. m=j1+1;
  352. for(n=i1-1;n>i2;n--)
  353. {
  354. if(occupied[n][m++])
  355. {
  356. printf("Incorrect move(a piece inside the path).\nPlease re-enter your move.");
  357. movement();
  358. return;
  359. }
  360.  
  361. }
  362.  
  363. }
  364. else if(i2<i1 && j2<j1)
  365. {
  366. for(n=i1-1;n>i2;n--)
  367. {
  368. m=j1-1;
  369.  
  370. if(occupied[n][m--])
  371. {
  372. printf("Incorrect move(a piece inside the path).\nPlease re-enter your move.");
  373. movement();
  374. return;
  375. }
  376.  
  377. }
  378. }
  379. if(occupied[i2][j2]==1)
  380. {
  381. printf("Incorrect move(moving over your own piece).\nPlease re-enter your move.");
  382. movement();
  383. return;
  384. }
  385. if(occupied[i2][j2]==2)
  386. { save_step(i1,j1,i2,j2,domain[i2][j2],domain[i1][j1]);
  387. occupied[i1][j1]=0;
  388. occupied[i2][j2]=1;
  389. killed2[number_killed2]=domain[i2][j2];
  390. domain[i2][j2]=domain[i1][j1];
  391. number_killed2++;
  392. }
  393. if(occupied[i2][j2]==0)
  394. { save_step(i1,j1,i2,j2,domain[i2][j2],domain[i1][j1]);
  395. domain[i2][j2]=domain[i1][j1];
  396. occupied[i1][j1]=0;
  397. occupied[i2][j2]=1;
  398. }
  399. }
  400. else if(i2==i1)
  401. {
  402. int n;
  403. if(j2>j1){
  404. for(n=j1+1;n<j2;n++)
  405. {
  406. if(occupied[i1][n])
  407. {
  408. printf("Incorrect move(a piece inside the path).\nPlease re-enter your move.");
  409. movement();
  410. return;
  411. }}}
  412. if(j1>j2)
  413. {
  414. for(n=j1-1;n>j2;n--)
  415. {
  416. if(occupied[i1][n])
  417. {
  418. printf("Incorrect move(a piece inside the path).\nPlease re-enter your move.");
  419. movement();
  420. return;
  421. }}
  422. }
  423. if(occupied[i1][j2]==1)
  424. {
  425. printf("Incorrect move(moving over your own piece).\nPlease re-enter your move.");
  426. movement();
  427. return;
  428. }
  429. if(occupied[i2][j2]==2)
  430. {save_step(i1,j1,i2,j2,domain[i2][j2],domain[i1][j1]);
  431. occupied[i2][j2]=1;
  432. occupied[i1][j1]=0;
  433. killed2[number_killed2]=domain[i2][j2];
  434. domain[i2][j2]=domain[i1][j1];
  435. number_killed2++;
  436. }
  437. if(occupied[i2][j2]==0)
  438. {save_step(i1,j1,i2,j2,domain[i2][j2],domain[i1][j1]);
  439. domain[i2][j2]=domain[i1][j1];
  440. occupied[i1][j1]=0;
  441. occupied[i2][j2]=1;
  442.  
  443. }
  444. }
  445. else if(j2==j1)
  446. {
  447. int n;
  448. if(i2>i1)
  449. {
  450. for(n=i1+1;n<i2;n++)
  451. {
  452. if(occupied[n][j1])
  453. {
  454. printf("Incorrect move(a piece inside the path).\nPlease re-enter your move.");
  455. movement();
  456. return;
  457.  
  458. }}}
  459. if(i1>i2)
  460. {
  461. for(n=i1-1;n>i2;n--)
  462. {
  463. if(occupied[n][j1])
  464. {
  465. printf("Incorrect move(a piece inside the path).\nPlease re-enter your move.");
  466. movement();
  467. return;
  468.  
  469. }}
  470. }
  471. if(occupied[i2][j2]==1)
  472. {
  473. printf("Incorrect move(moving over your own piece).\nPlease re-enter your move.");
  474. movement();
  475. }
  476. if(occupied[i2][j2]==2)
  477. { save_step(i1,j1,i2,j2,domain[i2][j2],domain[i1][j1]);
  478. occupied[i1][j1]=0;
  479. occupied[i2][j2]=1;
  480. killed2[number_killed2]=domain[i2][j2];
  481. domain[i2][j2]=domain[i1][j1];
  482. number_killed2++;
  483. }
  484. if(occupied[i2][j2]==0)
  485. { save_step(i1,j1,i2,j2,domain[i2][j2],domain[i1][j1]);
  486. occupied[i1][j1]=0;
  487. occupied[i2][j2]=1;
  488. domain[i2][j2]=domain[i1][j1];
  489. }
  490.  
  491. }
  492. else
  493. {
  494. printf("Incorrect move.\nPlease re-enter your move.");
  495. movement();
  496. }
  497.  
  498. }
  499.  
  500. if(domain[i1][j1]=='k')
  501. {
  502. move_king(i1,j1,i2,j2);
  503. }
  504.  
  505. /******* PLAYER 2**********/
  506. if(turn==2)
  507. {
  508. if(domain[i1][j1]=='P')
  509. {
  510.  
  511.  
  512. if(i1==6){
  513. /*if next square is correct and empty*/
  514. if((i1-i2==1||i1-i2==2)&&j1==j2&& occupied[i2][j2]==0&&occupied[i1-1][j2]==0){
  515. save_step(i1,j1,i2,j2,domain[i2][j2],domain[i1][j1]);
  516. domain[i2][j2]=domain[i1][j1];
  517. occupied[i1][j1]=0;
  518. occupied[i2][j2]=2;
  519.  
  520. }else if((i1-i2==1)&&j1==j2&& occupied[i2][j2]==0){
  521. save_step(i1,j1,i2,j2,domain[i2][j2],domain[i1][j1]);
  522. domain[i2][j2]=domain[i1][j1];
  523. occupied[i1][j1]=0;
  524. occupied[i2][j2]=2;
  525.  
  526.  
  527.  
  528.  
  529. }
  530. else
  531. {
  532. printf("Incorrect move.\nPlease re-enter your move.");
  533. movement();
  534. }
  535. }
  536. else if((i1-i2==1)&&j1==j2&& occupied[i2][j2]==0){
  537. save_step(i1,j1,i2,j2,domain[i2][j2],domain[i1][j1]);
  538. if(i2==0)
  539. {
  540. premote(&domain[i1][j1]);
  541. }
  542.  
  543. domain[i2][j2]=domain[i1][j1];
  544. occupied[i1][j1]=0;
  545. occupied[i2][j2]=2;
  546.  
  547.  
  548.  
  549.  
  550. }
  551.  
  552. /*eaten player 1 piece*/
  553. else if(i2==i1-1&&(j2==j1-1||j2==j1+1)&&occupied[i2][j2]==1)
  554. {
  555. save_step(i1,j1,i2,j2,domain[i2][j2],domain[i1][j1]);
  556. if(i2==0)
  557. {
  558. premote(&domain[i1][j1]);
  559.  
  560. }
  561.  
  562. killed1[number_killed1]=domain[i2][j2];
  563. domain[i2][j2]=domain[i1][j1];
  564. number_killed1++;
  565. occupied[i1][j1]=0;
  566. occupied[i2][j2]=2;
  567.  
  568.  
  569.  
  570. }
  571.  
  572. else
  573. {
  574. printf("Incorrect move.\nPlease re-enter your move.");
  575. movement();
  576. return;
  577. }
  578. return;
  579.  
  580. }
  581. if(domain[i1][j1]=='R')
  582. {
  583. if(i2==i1)
  584. {
  585. int n;
  586. if(j2>j1){
  587. for(n=j1+1;n<j2;n++)
  588. {
  589. if(occupied[i1][n])
  590. {
  591. printf("Incorrect move(a piece inside the path).\nPlease re-enter your move.");
  592. movement();
  593. return;
  594. }}}
  595. if(j1>j2)
  596. {
  597. for(n=j1-1;n>j2;n--)
  598. {
  599. if(occupied[i1][n])
  600. {
  601. printf("Incorrect move(a piece inside the path).\nPlease re-enter your move.");
  602. movement();
  603. return;
  604. }}
  605. }
  606. if(occupied[i1][j2]==2)
  607. {
  608. printf("Incorrect move(moving over your own piece).\nPlease re-enter your move.");
  609. movement();
  610. return;
  611. }
  612. if(occupied[i2][j2]==1)
  613. { save_step(i1,j1,i2,j2,domain[i2][j2],domain[i1][j1]);
  614. occupied[i2][j2]=2;
  615. occupied[i1][j1]=0;
  616. killed1[number_killed1]=domain[i2][j2];
  617. domain[i2][j2]=domain[i1][j1];
  618. number_killed1++;
  619. }
  620. if(occupied[i2][j2]==0)
  621. { save_step(i1,j1,i2,j2,domain[i2][j2],domain[i1][j1]);
  622. domain[i2][j2]=domain[i1][j1];
  623. occupied[i1][j1]=0;
  624. occupied[i2][j2]=2;
  625.  
  626. }
  627. }
  628. else if(j2==j1)
  629. {
  630. int n;
  631. if(i2>i1)
  632. {
  633. for(n=i1+1;n<i2;n++)
  634. {
  635. if(occupied[n][j1])
  636. {
  637. printf("Incorrect move(a piece inside the path).\nPlease re-enter your move.");
  638. movement();
  639. return;
  640.  
  641. }}}
  642. if(i1>i2)
  643. {
  644. for(n=i1-1;n>i2;n--)
  645. {
  646. if(occupied[n][j1])
  647. {
  648. printf("Incorrect move(a piece inside the path).\nPlease re-enter your move.");
  649. movement();
  650. return;
  651.  
  652. }}
  653. }
  654. if(occupied[i2][j2]==2)
  655. {
  656. printf("Incorrect move(moving over your own piece).\nPlease re-enter your move.");
  657. movement();
  658. return;
  659. }
  660. if(occupied[i2][j2]==1)
  661. { save_step(i1,j1,i2,j2,domain[i2][j2],domain[i1][j1]);
  662. occupied[i1][j1]=0;
  663. occupied[i2][j2]=2;
  664. killed1[number_killed1]=domain[i2][j2];
  665. domain[i2][j2]=domain[i1][j1];
  666. number_killed1++;
  667. }
  668. if(occupied[i2][j2]==0)
  669. { save_step(i1,j1,i2,j2,domain[i2][j2],domain[i1][j1]);
  670. occupied[i1][j1]=0;
  671. occupied[i2][j2]=2;
  672. domain[i2][j2]=domain[i1][j1];
  673. }
  674.  
  675. }else
  676. {
  677. printf("Incorrect move.\nPlease re-enter your move.");
  678. movement();
  679. return;
  680. }
  681.  
  682. }
  683. if(domain[i1][j1]=='N')
  684. {
  685. if((i2==i1+2&&(j2==j1-1||j2==j1+1))||(i2==i1-2&&(j2==j1-1||j2==j1+1))||(j2==j1+2&&(i2==i1-1||i2==i1+1))||(j2==j1-2&&(i2==i1-1||i2==i1+1)))
  686. {
  687. if(occupied[i2][j2]==2)
  688. {
  689. printf("Incorrect move(moving over your own piece).\nPlease re-enter your move.");
  690. movement();
  691. return;
  692. }
  693. if(occupied[i2][j2]==1)
  694. { save_step(i1,j1,i2,j2,domain[i2][j2],domain[i1][j1]);
  695. occupied[i1][j1]=0;
  696. occupied[i2][j2]=2;
  697. killed1[number_killed1]=domain[i2][j2];
  698. domain[i2][j2]=domain[i1][j1];
  699. number_killed1++;
  700. }
  701. if(occupied[i2][j2]==0)
  702. { save_step(i1,j1,i2,j2,domain[i2][j2],domain[i1][j1]);
  703. domain[i2][j2]=domain[i1][j1];
  704. occupied[i1][j1]=0;
  705. occupied[i2][j2]=2;
  706. }
  707. }else
  708. {
  709. printf("Incorrect move.\nPlease re-enter your move.");
  710. movement();
  711. }
  712. }
  713. if(domain[i1][j1]=='B')
  714. {
  715.  
  716. int n,m;
  717. if(j2-j1==i2-i1 || j2-j1==i1-i2)
  718. {
  719. m=j1+1;
  720. if(j2>j1&&i2>i1)
  721. {
  722. for(n=i1+1;n<i2;n++)
  723. {
  724. if(occupied[n][m++])
  725. {
  726. printf("Incorrect move(a piece inside the path).\nPlease re-enter your move.");
  727. movement();
  728. goto OUT;
  729. }
  730.  
  731. }
  732. }
  733.  
  734.  
  735.  
  736.  
  737. else if(j1>j2 && i2>i1)
  738. {
  739. m=j1-1;
  740. for(n=i1+1;n<i2;n++)
  741. {
  742. if(occupied[n][m--])
  743. {
  744. printf("Incorrect move(a piece inside the path).\nPlease re-enter your move.");
  745. movement();
  746. goto OUT;
  747. }
  748.  
  749. }
  750. }
  751. else if (i1>i2 && j2>j1)
  752. {
  753. m=j1+1;
  754. for(n=i1-1;n>i2;n--)
  755. {
  756. if(occupied[n][m++])
  757. {
  758. printf("Incorrect move(a piece inside the path).\nPlease re-enter your move.");
  759. movement();
  760. return;
  761. }
  762.  
  763. }
  764.  
  765. }
  766. else if(i2<i1 && j2<j1)
  767. {
  768. m=j1-1;
  769. for(n=i1-1;n>i2;n--)
  770. {
  771. if(occupied[n][m--])
  772. {
  773. printf("Incorrect move(a piece inside the path).\nPlease re-enter your move.");
  774. movement();
  775. return;
  776. }
  777.  
  778. }
  779. }}
  780. else{
  781. printf("Incorrect move.\nPlease re-enter your move.");
  782. movement();
  783. return;
  784. }
  785. if(occupied[i2][j2]==2)
  786. {
  787. printf("Incorrect move(moving over your own piece).\nPlease re-enter your move.");
  788. movement();
  789. return;
  790. }
  791. if(occupied[i2][j2]==1)
  792. {save_step(i1,j1,i2,j2,domain[i2][j2],domain[i1][j1]);
  793. occupied[i1][j1]=0;
  794. occupied[i2][j2]=2;
  795. killed1[number_killed1]=domain[i2][j2];
  796. domain[i2][j2]=domain[i1][j1];
  797. number_killed1++;
  798. }
  799. if(occupied[i2][j2]==0)
  800. {save_step(i1,j1,i2,j2,domain[i2][j2],domain[i1][j1]);
  801. domain[i2][j2]=domain[i1][j1];
  802. occupied[i1][j1]=0;
  803. occupied[i2][j2]=2;
  804. }
  805.  
  806.  
  807.  
  808.  
  809. }
  810. if(domain[i1][j1]=='Q')
  811. {
  812. int n,m;
  813. if(j2-j1==i2-i1 || j2-j1==i1-i2)
  814. {
  815. m=j1+1;
  816. if(j2>j1&&i2>i1)
  817. {
  818. for(n=i1+1;n<i2;n++)
  819. {
  820. if(occupied[n][m++])
  821. {
  822. printf("Incorrect move(a piece inside the path).\nPlease re-enter your move.");
  823. movement();
  824. return;
  825. }
  826.  
  827. }
  828. }
  829.  
  830. else if(j1>j2 && i2>i1)
  831. {
  832. m=j1-1;
  833. for(n=i1+1;n<i2;n++)
  834. {
  835. if(occupied[n][m--])
  836. {
  837. printf("Incorrect move(a piece inside the path).\nPlease re-enter your move.");
  838. movement();
  839. return;
  840. }
  841.  
  842. }
  843. }
  844. else if (i1>i2 && j2>j1)
  845. {
  846. m=j1+1;
  847. for(n=i1-1;n>i2;n--)
  848. {
  849. if(occupied[n][m++])
  850. {
  851. printf("Incorrect move(a piece inside the path).\nPlease re-enter your move.");
  852. movement();
  853. return;
  854. }
  855.  
  856. }
  857.  
  858. }
  859. else if(i2<i1 && j2<j1)
  860. {
  861. m=j1-1;
  862.  
  863. for(n=i1-1;n>i2;n--)
  864. {
  865. if(occupied[n][m--])
  866. {
  867. printf("Incorrect move(a piece inside the path).\nPlease re-enter your move.");
  868. movement();
  869. return;
  870. }
  871.  
  872. }
  873. }
  874. if(occupied[i2][j2]==2)
  875. {
  876. printf("Incorrect move(moving over your own piece).\nPlease re-enter your move.");
  877. movement();
  878. }
  879. if(occupied[i2][j2]==1)
  880. { save_step(i1,j1,i2,j2,domain[i2][j2],domain[i1][j1]);
  881. occupied[i1][j1]=0;
  882. occupied[i2][j2]=2;
  883. killed1[number_killed1]=domain[i2][j2];
  884. domain[i2][j2]=domain[i1][j1];
  885. number_killed1++;
  886. }
  887. if(occupied[i2][j2]==0)
  888. { save_step(i1,j1,i2,j2,domain[i2][j2],domain[i1][j1]);
  889. domain[i2][j2]=domain[i1][j1];
  890. occupied[i1][j1]=0;
  891. occupied[i2][j2]=2;
  892. }
  893. }
  894. else if(i2==i1)
  895. {
  896. int n;
  897. if(j2>j1){
  898. for(n=j1+1;n<j2;n++)
  899. {
  900. if(occupied[i1][n])
  901. {
  902. printf("Incorrect move(a piece inside the path).\nPlease re-enter your move.");
  903. movement();
  904. return;
  905. }}}
  906. if(j1>j2)
  907. {
  908. for(n=j1-1;n>j2;n--)
  909. {
  910. if(occupied[i1][n])
  911. {
  912. printf("Incorrect move(a piece inside the path).\nPlease re-enter your move.");
  913. movement();
  914. return;
  915. }}
  916. }
  917. if(occupied[i1][j2]==2)
  918. {
  919. printf("Incorrect move(moving over your own piece).\nPlease re-enter your move.");
  920. movement();
  921. return;
  922. }
  923. if(occupied[i2][j2]==1)
  924. { save_step(i1,j1,i2,j2,domain[i2][j2],domain[i1][j1]);
  925. occupied[i2][j2]=2;
  926. occupied[i1][j1]=0;
  927. killed1[number_killed1]=domain[i2][j2];
  928. domain[i2][j2]=domain[i1][j1];
  929. number_killed1++;
  930. }
  931. if(occupied[i2][j2]==0)
  932. { save_step(i1,j1,i2,j2,domain[i2][j2],domain[i1][j1]);
  933. domain[i2][j2]=domain[i1][j1];
  934. occupied[i1][j1]=0;
  935. occupied[i2][j2]=2;
  936.  
  937. }
  938. }
  939. else if(j2==j1)
  940. {
  941. int n;
  942. if(i2>i1)
  943. {
  944. for(n=i1+1;n<i2;n++)
  945. {
  946. if(occupied[n][j1])
  947. {
  948. printf("Incorrect move(a piece inside the path).\nPlease re-enter your move.");
  949. movement();
  950. return;
  951.  
  952. }}}
  953. if(i1>i2)
  954. {
  955. for(n=i1-1;n>i2;n--)
  956. {
  957. if(occupied[n][j1])
  958. {
  959. printf("Incorrect move(a piece inside the path).\nPlease re-enter your move.");
  960. movement();
  961. return;
  962.  
  963. }}
  964. }
  965. if(occupied[i2][j2]==2)
  966. {
  967. printf("Incorrect move(moving over your own piece).\nPlease re-enter your move.");
  968. movement();
  969. return;
  970. }
  971. if(occupied[i2][j2]==1)
  972. { save_step(i1,j1,i2,j2,domain[i2][j2],domain[i1][j1]);
  973. occupied[i1][j1]=0;
  974. occupied[i2][j2]=2;
  975. killed1[number_killed1]=domain[i2][j2];
  976. domain[i2][j2]=domain[i1][j1];
  977. number_killed1++;
  978. }
  979. if(occupied[i2][j2]==0)
  980. { save_step(i1,j1,i2,j2,domain[i2][j2],domain[i1][j1]);
  981. occupied[i1][j1]=0;
  982. occupied[i2][j2]=2;
  983. domain[i2][j2]=domain[i1][j1];
  984. }
  985.  
  986. }
  987. else
  988. {
  989. printf("Incorrect move.\nPlease re-enter your move.");
  990. movement();
  991. return;
  992. }
  993.  
  994. }
  995. if(domain[i1][j1]=='K')
  996. {
  997. move_king(i1,j1,i2,j2);
  998. }
  999. }
  1000.  
  1001.  
  1002. OUT : return;
  1003. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement