Advertisement
Kenthris

Untitled

Apr 30th, 2017
550
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 31.11 KB | None | 0 0
  1. //Name: Kostas Papageorgiou, AM: 2025201100063, mail: cst11063@uop.gr
  2. //Name: Athanasios Levendis, AM: 2022201600206, mail: dit16206@uop.gr
  3. //work in progress
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include <stdlib.h>
  7. #include <time.h>
  8. int main(void)
  9. {
  10.  
  11. //----------------arxikes diastaseis tamplo -----------------
  12. int dimensions=10,yes,no,flag=1,max,length,*type,users=0, user, computer,sumi,sumj,obnum,k,newflag,co1,co2,co3,co4,spot,sum,blanks=0,obcounter,p;
  13. char yesno[4],*nam,**name,**array,**possible,typ[9],*symbol,sym,set;
  14. int i,players,j,l,turn;
  15. int sp, counter=0, player,**pcoord;
  16. int userflag = 1;
  17. int direction,match,*wincon;
  18. int a1=0,exit,target,help;
  19. char move[6];
  20. int bloc=0;
  21. int uflag=1;
  22. int dflag=1;
  23. int rflag=1;
  24. int lflag=1;
  25. int aflag1=1;
  26. int aflag2=1;//flags used to see if a direction has already been checked for an obstacle. aflag stops us from checking further directions
  27. // time_t t;
  28. //----------------epalitheusi gia to an thelei o xristis na paiksei me tis prokathorismens diastaseis------
  29. srand(time(NULL));
  30. do
  31. {
  32. printf("Do you want to play by defaut dimensions(10X10)?(yes/no) ");
  33. scanf("%s", yesno);
  34. yes=strcmp(yesno,"yes");
  35. no=strcmp(yesno,"no");
  36. if ((yes==0)||(no==0))
  37. {
  38. flag=0;
  39. }
  40. if (flag==1)
  41. {
  42. printf("\nWrong input.Please choose between default dimensions(yes) and custom dimensions(no) ");
  43. }
  44. }while (flag!=0);
  45. //---------------epalitheusi gia to oti oi custom diastaseis tha einai megaliteris i ises tou 5------
  46. if (no==0)
  47. {
  48. do
  49. {
  50. printf("\nChoose your own dimensions ");
  51. scanf("%d", &dimensions);
  52. if (dimensions<5)
  53. {
  54. printf("\nWrong input.Please choose a number >=5 and <=26");
  55. }
  56. }while((dimensions<5)||(dimensions>26));
  57. }
  58. //--------------------paixtes-------------------------
  59. //--------------------arithmos paixton-----------------
  60. do
  61. {
  62. printf("\nChoose the number of players (2 or 4) ");
  63. scanf("%d",&players);
  64. if (!((players==2)||(players==4)))
  65. {
  66. printf("\nWrong input.Please choose between 2 or 4 ");
  67. }
  68. }while(!((players==2)||(players==4)));
  69. //-------------------onoma kai typos paixton-----------
  70. nam=(char*)malloc(players*101);
  71. //-----------------arxikopoisi enos pinaka nam,ston opoio tha perasoume ola ta onomata----------
  72. for (i=0;i<players;i++)
  73. {
  74. nam[i]='\0';
  75. }
  76. printf("\nEnter the name and the type(user or computer) of each player.Keep in mind that there should be at least one user ");
  77. type=(int*)malloc(players*sizeof(int));
  78. symbol=(char*)malloc(players);
  79. //---------arxikopoioume ton pinaka symbol,vazontas '0' se kathe thesi
  80. //----------arxikopoioume ton pinaka type me 1,theorontas oti arxika einai oloi computers
  81. for (i=0;i<players;i++)
  82. {
  83. symbol[i]='0';
  84. type[i]=1;
  85. }
  86. for (i=0;i<players;i++)
  87. {
  88. printf("\nEnter the name of player number %d ",i+1);
  89. scanf("%s",&nam[i*101]);
  90. printf("\nEnter the type of player number %d ",i+1);
  91. flag=1;
  92. do
  93. {
  94. scanf("%s", typ);
  95. user=strcmp(typ,"user");
  96. computer=strcmp(typ,"computer");
  97. if ((user==0)||(computer==0))
  98. {
  99. flag=0;
  100. }
  101. if (flag==1)
  102. {
  103. printf("\nWrong input.Please choose one of your options (user,computer) ");
  104. }
  105. }while (flag!=0);
  106.  
  107. printf("\nEnter the symbol of player number %d .You can choose between (#,*,&,@) ",i+1);
  108. flag=1;
  109. do
  110. {
  111. if (flag==2)
  112. {
  113. flag=1;
  114. }
  115. scanf("%s",&sym);
  116. if ((sym=='#')||(sym=='@')||(sym=='&')||(sym=='*'))
  117. {
  118. flag=0;
  119. for (j=0;j<players;j++)
  120. {
  121. if (sym==symbol[j])
  122. {
  123. flag=2;
  124. printf("Another player already has this symbol taken.Please choose another one (#,*,&,@) ");
  125. }
  126. }
  127. }
  128. if (flag==1)
  129. {
  130. printf("\nWrong input.Please choose one of your options (#,*,&,@) ");
  131. }
  132. if ((flag!=2)&&(flag!=1))
  133. {
  134. flag=0;
  135. symbol[i]=sym;
  136. }
  137. }while (flag!=0);
  138. if (user==0)
  139. {
  140. users++;
  141. type[i]=0;
  142. }
  143. }
  144. //-------------elegxos gia enan toulaxiston paixti--------------
  145. if (users==0)
  146. {
  147. do
  148. {
  149. printf("There must be at least on user.Please re-enter the type of each player,making sure that there is one user! ");
  150. flag=1;
  151. for (i=0;i<players;i++)
  152. {
  153. user=1;
  154. computer=1;
  155. printf("\nEnter the type of player number %d ",i+1);
  156. do
  157. {
  158.  
  159. scanf("%s", typ);
  160. user=strcmp(typ,"user");
  161. computer=strcmp(typ,"computer");
  162. if ((user==0)||(computer==0))
  163. {
  164. flag=0;
  165. }
  166. else
  167. {
  168. printf("\nWrong input.Please choose one of your options (user,computer) ");
  169. }
  170. }while (flag!=0);
  171. if(user==0)
  172. {
  173. users++;
  174. type[i]=0;
  175. }
  176. }
  177.  
  178. }while(users==0);
  179. }
  180. max=0;
  181. i=0;
  182. while((nam[i]!='\0')&&(i<101))
  183. {
  184. max++;
  185. i++;
  186. }
  187. length=0;
  188. for (i=101;i<(players*101);i=i+101)
  189. {
  190. while(nam[i]!='\0')
  191. {
  192. length++;
  193. i++;
  194. }
  195. if (length>max)
  196. {
  197. max=length;
  198. }
  199. i=i-length;
  200. length=0;
  201. }
  202. max=max+1;
  203. name=(char**)malloc(players*sizeof(char*));
  204. for (i=0;i<players;i++)
  205. {
  206. name[i]=(char*)malloc(max*sizeof(char));
  207. }
  208. for(i=0;i<players;i++)
  209. {
  210. for (j=0;j<max;j++)
  211. {
  212. name[i][j]=nam[j+(i*101)];
  213. }
  214. }
  215.  
  216. for (i=0;i<players;i++)
  217. {
  218. j=0;
  219. printf("\nThe player with the name ");
  220. while((name[i][j]!='\0')&&(j<max))
  221. {
  222. printf("%c",name[i][j]);
  223. j++;
  224. }
  225.  
  226. printf(" is a ");
  227. if (type[i]==0)
  228. {
  229. printf("user");
  230. }
  231. if (type[i]==1)
  232. {
  233. printf("computer");
  234. }
  235. printf(" and his symbol is %c ",symbol[i]);
  236. printf("\n");
  237. }
  238. flag=1;
  239. do
  240. {
  241. printf("\nDo you want the map to be populated by obstacles?(yes/no) ");
  242. scanf("%s", yesno);
  243. yes=strcmp(yesno,"yes");
  244. no=strcmp(yesno,"no");
  245. if ((yes==0)||(no==0))
  246. {
  247. flag=0;
  248. }
  249. if (flag==1)
  250. {
  251. printf("\nWrong input.Choose between (yes) and (no) ");
  252. }
  253. }while (flag!=0);
  254. sumi=dimensions+2;
  255. sumj=dimensions+3;
  256. array=(char**)malloc((sumi)*sizeof(char*));
  257. possible=(char**)malloc((sumi)*sizeof(char*));
  258. for (i=0;i<sumi;i++)
  259. {
  260. array[i]=(char*)malloc((sumj)*sizeof(char));
  261. possible[i]=(char*)malloc((sumj)*sizeof(char));
  262.  
  263. }
  264.  
  265. for (i = 0; i < sumi; i++)
  266. {
  267. if ((i > 1) && (i < 11))
  268. {
  269. array[i][0] = i - 1 + '0';
  270. array[i][1] = ' ';
  271. array[i][2] = '|';
  272. for (j = 3; j < sumj; j++)
  273. {
  274. array[i][j] = '.';
  275. }
  276. }
  277. else
  278. {
  279. array[i][0] = ((i -1)/10) + '0';
  280. array[i][1] = ((i -1)%10) + '0';
  281. array[i][2] = '|';
  282. for (j = 3; j < sumj; j++)
  283. {
  284. array[i][j] = '.';
  285. }
  286. }
  287. if (i == 0)
  288. {
  289. array[i][2] = '|';
  290. for (j = 3; j < sumj; j++)
  291. {
  292. array[i][j] = j - 3 + 'a';
  293. }
  294. }
  295. if (i == 1)
  296. {
  297. for (j = 0; j < sumj; j++)
  298. {
  299. array[i][j] = '-';
  300. }
  301. }
  302. }
  303. array[0][0]=' ';
  304. array[0][1]=' ';
  305. array[0][2]=' ';
  306.  
  307. obnum = ((dimensions - 1)/2);
  308.  
  309. //after do{}while (counter < players);
  310. if (yes == 0)
  311. {
  312. do{
  313. newflag=1;//used to confirm that the spot for the first piece of the obstacle is surrounded by at least one more dot
  314. do{
  315. do{
  316. co1 = (rand() % dimensions) + 2;
  317. co2 = (rand() % dimensions) + 3;
  318. }while (array[co1][co2] != '.');
  319. spot = rand() % 4;
  320. if((spot == 0) && (array[co1+1][co2] == '.'))
  321. {
  322. co3=co1+1;
  323. co4=co2;
  324. newflag=0;
  325. }
  326. else if((spot == 1) && (array[co1-1][co2] == '.'))
  327. {
  328. co3=co1-1;
  329. co4=co2;
  330. newflag=0;
  331. }
  332. else if((spot == 2) && (array[co1][co2+1] == '.'))
  333. {
  334. co3=co1;
  335. co4=co2+1;
  336. newflag=0;
  337. }
  338. else if((spot == 3) && (array[co1][co2-1] == '.'))
  339. {
  340. co3=co1;
  341. co4=co2-1;
  342. newflag=0;
  343. }
  344. }while(newflag!=0);
  345. array[co1][co2] = 'X';//there was a random } here. keep this in mind...
  346. array[co3][co4] = 'X';
  347. obnum--;
  348. }while(obnum > 0);
  349. }
  350. //direction becomes 0 (up), 1 (left) or 2 (right) through the use of rand(). Keep this comment in the code
  351. //it is later used to check a direction's corresponding starting point for availability to put a player on
  352. sp = (dimensions/2) + 1;
  353. wincon=(int*)malloc(players*sizeof(int));
  354. //malloc an array the size of players called wincon. it will save the characters u, l, r and d
  355. //which will be the opposite of the player's direction when he is being given a starting point
  356. //malloc an array named pcoord which will be players x 2, where player coordinates will be saved
  357. //initialize all of pcoord to be dimensions + 1
  358. pcoord=(int**)malloc(players*sizeof(int*));
  359. for (i=0;i<players;i++)
  360. {
  361. pcoord[i]=(int*)malloc(2*sizeof(int));
  362. }
  363. for (i=0;i<players;i++)
  364. {
  365. wincon[i]=5;
  366. for (j=0;j<2;j++)
  367. {
  368. pcoord[i][j]=(dimensions+7);
  369. }
  370. }
  371. do
  372. {
  373. player=rand()%players;
  374. if(pcoord[player][0] == (dimensions + 7))
  375. { //this if checks if the player has already had his starting point set
  376. if((type[player] == 0) && (userflag == 1))
  377. { //this if checks for the first randomly chosen player
  378. pcoord[player][0] = sumi-1;
  379. pcoord[player][1] = sp+1;
  380. wincon[player] = 1;
  381. array[sumi-1][sp+1] = symbol[player];
  382. userflag = 0;
  383. counter++; //now that a new player has had his starting point set, the counter can increment
  384. }
  385. else
  386. {
  387. if (players==2)
  388. {
  389. pcoord[player][0]=2;
  390. pcoord[player][1]=sp+1;
  391. wincon[player]=3;
  392. array[2][sp+1]=symbol[player];
  393. counter++;
  394. }
  395. if (players==4)
  396. {
  397. direction = rand()%3;
  398. //randomly check a direction
  399. //check for direction's availability. we could potentially use a small array, but i did it the hard way
  400. //make the check in a loop. might need a new variable
  401. if ((direction == 0) && (array[2][sp] == '.'))
  402. { //0 is for starting position up (array[2][sp])
  403. pcoord[player][0] = 2;
  404. pcoord[player][1] = sp;
  405. wincon[player] = 3;
  406. array[2][sp+1] = symbol[player];
  407. counter++; //now that a new player has had his starting point set, the counter can increment
  408. }
  409. else if((direction == 1) && (array[sp][3] == '.'))
  410. { //1 is for starting position left (array[sp][3])
  411. pcoord[player][0] = sp;
  412. pcoord[player][1] = 3;
  413. wincon[player] = 2;
  414. array[sp][3] = symbol[player];
  415. counter++; //now that a new player has had his starting point set, the counter can increment
  416. }
  417. else if((direction == 2) && (array[sp][sumj-1] == '.'))
  418. {
  419. //2 is for starting position right (array[sp][sumj])
  420. //could have gone for a simple else, but put the check in as a precaution
  421. pcoord[player][0] = sp;
  422. pcoord[player][1] = sumj-1;
  423. wincon[player] = 4;
  424. array[sp][sumj-1] = symbol[player];
  425. counter++; //now that a new player has had his starting point set, the counter can increment
  426. }
  427. }
  428. }
  429. }
  430. }while (counter < players);
  431. for (i = 0; i < sumi; i++)
  432. {
  433. printf("\n");
  434. for (j=0;j<sumj;j++)
  435. {
  436. printf("%c ",array[i][j]);
  437. }
  438. }
  439. turn=0;
  440. do{
  441. if(type[turn] != 0){//this if puts us into the ai's turn, specifically the part the places obstacles. no mobility has been added yet
  442. int bloc=0;
  443. int uflag=dflag=rflag=lflag=aflag1=aflag2=1;//flags used to see if a direction has already been checked for an obstacle. aflag stops us from checking further directions
  444.  
  445. newflag=1;
  446. do{
  447. co1=pcoord[fastest][0];
  448. co2=pcoord[fastest][1];
  449. if(fastest == 0){
  450. if(array[pcoord[fastest][0]-1][pcoord[fastest][1]]=='.'){
  451. co1=pcoord[fastest][0]-1;
  452. aflag1=0;
  453. }
  454. else{
  455. bloc++;
  456. }
  457. spot = rand() % 4;
  458. do{
  459. if((spot==1) && (rflag!=0)){
  460. if(array[co1][co2+1]=='.'){
  461. rflag=0;
  462. if(aflag1==0){//this if ensures that an open space for movement has already been found before setting a place to block
  463. aflag12=0;
  464. }
  465. else{
  466. aflag1=0;
  467. co2=co2+1;//a coordinate is set for an obstacle if there is no previously found spot for it. having placed one direction outside the loop gives that direction priority
  468. }
  469. }
  470. else{
  471. rflag=0;
  472. bloc++;
  473. }
  474. }
  475. else if((spot==2) && (dflag!=0)){
  476. if(array[co+1][co2]=='.'){
  477. dflag=0;
  478. if(aflag1==0){
  479. co1=co1+1;
  480. aflag2=0;
  481. }
  482. else{
  483. aflag1=0;
  484. }
  485. }
  486. else{
  487. dflag=0;
  488. bloc++;
  489. }
  490. }
  491. else if((spot==3) && (lflag!=0)){
  492. if(array[co1][co2-1]=='.'){
  493. lflag=0;
  494. if(aflag1==0){
  495. co2=co2-1;
  496. aflag12=0;
  497. }
  498. else{
  499. aflag1=0;
  500. }
  501. }
  502. else{
  503. lflag=0;
  504. bloc++;
  505. }
  506. }//with this we have checked all directions for an open space. If bloc becomes 3, we only have one open space, and thus cannot place further obstacles around the fastest
  507. //if, however, we can block him, co1 and co2 have become the coordinates of a free adjacent space. with this, we can look around that space for the next part of the obstacle
  508. //if we find that as well, we will set both locations on array (array[co1][co2] and array[co3][co4]) to become 'X'
  509. spot = rand() % 4;
  510. }while(!((aflag1==0) && (aflag2==0)) || (bloc==3));
  511. }
  512. else if(fastest == 1){
  513. if(array[pcoord[fastest][0]][pcoord[fastest][1]+1]=='.'){
  514. co2=pcoord[fastest][1]+1;
  515. }
  516. else{
  517. bloc++;
  518. spot = rand() % 4;
  519. do{
  520. if((spot==0) && (uflag!=0)){
  521. if(array[co1-1][co2]=='.'){
  522. uflag=0;
  523. if(aflag1==0){
  524. co1=co1-1;
  525. aflag2=0;
  526. }
  527. else{
  528. aflag1=0;
  529. }
  530. }
  531. else{
  532. uflag=0;
  533. bloc++;
  534. }
  535. }
  536. else if((spot==2) && (dflag!=0)){
  537. if(array[co+1][co2]=='.'){
  538. dflag=0;
  539. if(aflag1==0){
  540. co1=co1+1;
  541. aflag2=0;
  542. }
  543. else{
  544. aflag1=0;
  545. }
  546. }
  547. else{
  548. dflag=0;
  549. bloc++;
  550. }
  551. }
  552. else if((spot==3) && (lflag!=0)){
  553. if(array[co1][co2-1]=='.'){
  554. lflag=0;
  555. if(aflag1==0){
  556. co2=co2-1;
  557. aflag12=0;
  558. }
  559. else{
  560. aflag1=0;
  561. }
  562. }
  563. else{
  564. lflag=0;
  565. bloc++;
  566. }
  567. }
  568. spot = rand() % 4;
  569. }while((aflag!=0) && (bloc!=4));
  570. }
  571. }
  572. else if(fastest == 2){
  573. if(array[pcoord[fastest][0]+1][pcoord[fastest][1]]=='.'){
  574. co1=pcoord[fastest][0]+1;
  575. }
  576. else{
  577. bloc++;
  578. spot = rand() % 4;
  579. do{
  580. if((spot==0) && (uflag!=0)){
  581. if(array[co1-1][co2]=='.'){
  582. uflag=0;
  583. if(aflag1==0){
  584. co1=co1-1;
  585. aflag2=0;
  586. }
  587. else{
  588. aflag1=0;
  589. }
  590. }
  591. else{
  592. uflag=0;
  593. bloc++;
  594. }
  595. }
  596. else if((spot==1) && (rflag!=0)){
  597. if(array[co1][co2+1]=='.'){
  598. rflag=0;
  599. if(aflag1==0){//this if ensures that an open space for movement has already been found before setting a place to block
  600. aflag12=0;
  601. }
  602. else{
  603. aflag1=0;
  604. co2=co2+1;//a coordinate is set for an obstacle if there is no previously found spot for it. having placed one direction outside the loop gives that direction priority
  605. }
  606. }
  607. else{
  608. rflag=0;
  609. bloc++;
  610. }
  611. }
  612. else if((spot==3) && (lflag!=0)){
  613. if(array[co1][co2-1]=='.'){
  614. lflag=0;
  615. if(aflag1==0){
  616. co2=co2-1;
  617. aflag12=0;
  618. }
  619. else{
  620. aflag1=0;
  621. }
  622. }
  623. else{
  624. lflag=0;
  625. bloc++;
  626. }
  627. }
  628. spot = rand() % 4;
  629. }while((aflag!=0) && (bloc!=4));
  630. }
  631. }
  632. else if(fastest == 3){
  633. if(array[pcoord[fastest][0]][pcoord[fastest][1]-1]=='.'){
  634. co2=pcoord[fastest][1]-1;
  635. }
  636. else{
  637. bloc++;
  638. spot = rand() % 4;
  639. do{
  640. if((spot==0) && (uflag!=0)){
  641. if(array[co1-1][co2]=='.'){
  642. uflag=0;
  643. if(aflag1==0){
  644. co1=co1-1;
  645. aflag2=0;
  646. }
  647. else{
  648. aflag1=0;
  649. }
  650. }
  651. else{
  652. uflag=0;
  653. bloc++;
  654. }
  655. }
  656. else if((spot==1) && (rflag!=0)){
  657. if(array[co1][co2+1]=='.'){
  658. rflag=0;
  659. if(aflag1==0){//this if ensures that an open space for movement has already been found before setting a place to block
  660. aflag12=0;
  661. }
  662. else{
  663. aflag1=0;
  664. co2=co2+1;//a coordinate is set for an obstacle if there is no previously found spot for it. having placed one direction outside the loop gives that direction priority
  665. }
  666. }
  667. else{
  668. rflag=0;
  669. bloc++;
  670. }
  671. }
  672. else if((spot==2) && (dflag!=0)){
  673. if(array[co+1][co2]=='.'){
  674. dflag=0;
  675. if(aflag1==0){
  676. co1=co1+1;
  677. aflag2=0;
  678. }
  679. else{
  680. aflag1=0;
  681. }
  682. }
  683. else{
  684. dflag=0;
  685. bloc++;
  686. }
  687. }
  688. spot = rand() % 4;
  689. }while((aflag!=0) && (bloc!=4));
  690. }
  691. }
  692. //once co1 and co2 have been found and an obstacle can be placed, we need co3 and co4 for the second piece
  693. //if an obstacle can be placed, we start by setting co3 and co4 to co1 and co2 respectively. if not, we set them to the coordinates of the fastest
  694. if((aflag1==0) && (aflag2==0)){
  695. co3=co1;
  696. co4=co2;
  697. spot = rand() % 4;
  698. if((spot == 0) && (array[co1+1][co2] == '.')){
  699. co3=co1+1;
  700. newflag=0;
  701. }
  702. else if((spot == 1) && (array[co1-1][co2] == '.')){
  703. co3=co1-1;
  704. newflag=0;
  705. }
  706. else if((spot == 2) && (array[co1][co2+1] == '.')){
  707. co4=co2+1;
  708. newflag=0;
  709. }
  710. else if((spot == 3) && (array[co1][co2-1] == '.')){
  711. co4=co2-1;
  712. newflag=0;
  713. }
  714. }
  715. //now we check their values. if no obstacle can be placed, we set newflag to 0 and call proceed instead
  716. if((co3!=co1) || (co4!=co2)){
  717. array[co1][co2]='X';
  718. array[co3][co4]='X';
  719. }
  720. else{
  721. aflag2=2;//outside the obstacles side of the code, check for this flag. if it is 2, call proceed instead
  722. }
  723. }while (newflag!=0);
  724. }
  725. else{//this is where the player's actions would be
  726.  
  727. }
  728. }while((pcoord[0][0] != 2) && (pcoord[1][1] != (sumj-1)) && (pcoord[2][0] != (sumi-1)) && (pcoord[3][1] != 3));//this is where the main game goes
  729. // for(i=0;i<players;i++)
  730. // {
  731. // exit=1;
  732. // help=1;
  733. // if (players==2)
  734. // {
  735. // if ((wincon[i]==1)||(wincon[i]==3))
  736. // {
  737. // j=0;
  738. // while((name[i][j]!='\0')&&(j<max))
  739. // {
  740. // printf("\n%d",wincon[i]);
  741. // j++;
  742. // }
  743. // do
  744. // {
  745. // printf(" is playing.Enter the coordinates of the square you want to move to,or the coordinates of the squares you want to place an obstacle.You can also enter 'help' or 'exit')");
  746. // scanf("%s", move);
  747. // exit=strcmp(move,"exit");
  748. // help=strcmp(move,"help");
  749. // flag=1;
  750. // if (!(exit==0)||(help==0))
  751. // {
  752. // target=strlen(move);
  753. // match=0;
  754. // j=0;
  755. // while((j<target)&&(flag==1))
  756. // {
  757. // if (j==0)
  758. // {
  759. // for (k = 3; k < sumj; k++)
  760. // {
  761. // if (array[0][k]!=move[j])
  762. // {
  763. // match++;
  764. // }
  765. // else
  766. // {
  767. // a1=0;
  768. // }
  769. // }
  770. //
  771. // }
  772. // else
  773. // {
  774. // //an o proigoumenos einai arithmos
  775. // if(a1==1)
  776. // {
  777. // for (k = 3; k < sumj; k++)
  778. // {
  779. // if (array[0][k]!=move[j])
  780. // {
  781. // match++;
  782. // }
  783. // else
  784. // {
  785. // a1=0;
  786. // }
  787. // }
  788. // for (k=2;k<sumi;k++)
  789. // {
  790. // if(array[k][1]!=move[j])
  791. // {
  792. // match++;
  793. // }
  794. // else
  795. // {
  796. // a1=1;
  797. // }
  798. // }
  799. // }
  800. // else
  801. // {
  802. // for(k=2;k<sumi;k++)
  803. // {
  804. // if(array[k][0]!=move[j])
  805. // {
  806. // match++;
  807. // }
  808. // else
  809. // {
  810. // a1=1;
  811. // }
  812. // }
  813. // }
  814. // }
  815. // j++;
  816. // }
  817. //
  818. // }
  819. // if (match!=0)
  820. // {
  821. // printf("\n Wrong input.");
  822. // }
  823. // }while (match!=0);
  824. // }
  825. // }
  826. // if (players==4)
  827. // {
  828. // if (wincon[i]==i+1)
  829. // {
  830. // j=0;
  831. // while((name[i][j]!='\0')&&(j<max))
  832. // {
  833. // printf("\n%d",wincon[i]);
  834. // j++;
  835. // }
  836. // do
  837. // {
  838. // printf(" is playing.Enter the coordinates of the square you want to move to,or the coordinates of the squares you want to place an obstacle.You can also enter 'help' or 'exit')");
  839. // scanf("%s", move);
  840. // exit=strcmp(move,"exit");
  841. // help=strcmp(move,"help");
  842. //// flag=1;
  843. // if (!(exit==0)||(help==0))
  844. // {
  845. // target=strlen(move);
  846. // match=0;
  847. // j=0;
  848. // while((j<target)&&(flag==1))
  849. // {
  850. // if (j==0)
  851. // {
  852. // for (k = 3; k < sumj; k++)
  853. // {
  854. // if (array[0][k]!=move[j])
  855. // {
  856. // match++;
  857. // }
  858. // else
  859. // {
  860. // a1=0;
  861. // }
  862. // }
  863. //
  864. // }
  865. // else
  866. // {
  867. // //an o proigoumenos einai arithmos
  868. // if(a1==1)
  869. // {
  870. // for (k = 3; k < sumj; k++)
  871. // {
  872. // if (array[0][k]!=move[j])
  873. // {
  874. // match++;
  875. // }
  876. // else
  877. // {
  878. // a1=0;
  879. // }
  880. // }
  881. // for (k=2;k<sumi;k++)
  882. // {
  883. // if(array[k][1]!=move[j])
  884. // {
  885. // match++;
  886. // }
  887. // else
  888. // {
  889. // a1=1;
  890. // }
  891. // }
  892. // }
  893. // else
  894. // {
  895. // for(k=2;k<sumi;k++)
  896. // {
  897. // if(possible[k][0]!=move[j])
  898. // {
  899. // match++;
  900. // }
  901. // else
  902. // {
  903. // a1=1;
  904. // }
  905. // }
  906. // }
  907. // }
  908. // j++;
  909. // }
  910. //
  911. // }
  912. // if (match!=0)
  913. // {
  914. // printf("\n Wrong input.");
  915. // }
  916. // }while (match!=0);
  917. // }
  918. // }
  919. // }
  920.  
  921.  
  922. for (i=0;i<players;i++)
  923. {
  924. free (name[i]);
  925. free(pcoord[i]);
  926. }
  927. for (i = 0; i < sumi; i++)
  928. {
  929. free (array[i]);
  930. }
  931. free(nam);
  932. free(type);
  933. free(symbol);
  934. free(wincon);
  935. free(array);
  936. free(name);
  937. free(pcoord);
  938. return 0;
  939. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement