Advertisement
Kenthris

Untitled

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