Advertisement
Kenthris

Untitled

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