Advertisement
sp1d3o

IZP 2

Dec 1st, 2023
828
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 21.76 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5.  
  6.  
  7. typedef struct {
  8.     char side;
  9.     char inuse;
  10.     char entry;
  11.     char exit;
  12. } info;
  13.  
  14. typedef struct {
  15.     int rows;
  16.     int cols;
  17.     unsigned char *cells;
  18.     info *lab;
  19. } Map;
  20.  
  21. Map *Constructor(int rows, int collumns);
  22. void Destructor(Map *map);
  23. int GetSize(FILE *path);
  24. int CreateMap(Map *map, FILE *file);
  25. void PrintHelp();
  26. int CheckValidityMaze(Map *map);
  27. int StartValidationCheck(Map *map, int Row, int Col);
  28. int CheckBorderNum1(Map *map, int FirstSideIndex, int SecondSideIndex);
  29. int CheckBorderNum2(Map *map, int FirstSideIndex, int SecondSideIndex);
  30. int CheckBorderNum4(Map *map, int FirstSideIndex, int SecondSideIndex);
  31. int CheckMazeEntry(Map *map, int R, int Collumns);
  32. void LeftPath(Map *map, int Rows, int Columns, int Inside);
  33. void RightPath(Map *map, int Rows, int Columns, int Inside);
  34. int DirectionFirst(Map *map, int *Rows, int *Columns);
  35. int DirectionSecond(Map *map, int *Rows, int *Columns);
  36. int DirectionThird(Map *map, int *Rows, int *Columns);
  37. void DirectionBack(Map *map, int *Rows, int *Columns);
  38. bool TestInput(char *file);
  39.  
  40.  
  41. int main(int argc, char *argv[])
  42. {
  43.     if(argc < 2) {
  44.         fprintf(stderr, "Invalid usage, too few arguments\n");
  45.         PrintHelp();
  46.         return 1;
  47.     }
  48.  
  49.    
  50.  
  51.     if(argc == 2) {
  52.         if(strcmp(argv[1], "--help") == 0) {
  53.             PrintHelp();
  54.             return 0;
  55.         }
  56.     }
  57.     else if(strcmp(argv[1], "--test") == 0) {
  58.         TestInput(argv[2]);
  59.     }
  60.  
  61.     FILE *file = fopen(argv[4], "r");
  62.     if(file == 0) {
  63.         fprintf(stderr, "File opening failure\n");
  64.         return 1;
  65.     }
  66.    
  67.     int Rows = GetSize(file);
  68.     int Cols = GetSize(file);
  69.    
  70.     Map *map = Constructor(Rows, Cols);
  71.    
  72.     int InitializedMap = CreateMap(map, file);
  73.     if(InitializedMap == 1) {
  74.         fprintf(stderr, "Invalid file to work with\n");
  75.         fclose(file);
  76.         Destructor(map);
  77.         return 1;
  78.     }
  79.    
  80.     if(map->cells == NULL || map->lab == NULL) {
  81.         Destructor(map);
  82.         fprintf(stderr, "Constructor allocation failure\n");
  83.         if(file != 0) {
  84.             fclose(file);
  85.         }
  86.         return 1;
  87.     }
  88.    
  89.     if(!CheckValidityMaze(map)) {
  90.         fclose(file);
  91.         Destructor(map);
  92.         fprintf(stderr, "Invalid data in file to work with\n");
  93.         return 1;
  94.     }
  95.    
  96.     int FindedEnter = StartValidationCheck(map, atoi(argv[2]) - 1, atoi(argv[3]) - 1);
  97.     if(FindedEnter == 0) {
  98.         fclose(file);
  99.         Destructor(map);
  100.         fprintf(stderr, "No access found\n");
  101.         return 1;
  102.     }
  103.    
  104.     if(strcmp(argv[1], "--rpath") == 0) {
  105.         RightPath(map, atoi(argv[2]) - 1, atoi(argv[3]) - 1, FindedEnter);
  106.     }
  107.     else if(strcmp(argv[1], "--lpath") == 0) {
  108.         LeftPath(map, atoi(argv[2]) - 1, atoi(argv[3]) - 1, FindedEnter);
  109.     }
  110.     else {
  111.         fprintf(stderr, "Wrong argument\n");
  112.         PrintHelp();
  113.     }
  114.    
  115.     if(file != 0) {
  116.         fclose(file);
  117.     }
  118.  
  119.     Destructor(map);
  120.     return 0;
  121. }
  122.  
  123. bool TestInput(char *path)
  124. {
  125.     FILE *file = fopen(path, "r");
  126.     if(file == 0) {
  127.         fprintf(stderr, "Failed to open file");
  128.         return false;
  129.     }
  130.  
  131.     int Rows = GetSize(file);
  132.     int Cols = GetSize(file);
  133.  
  134.     Map *map = Constructor(Rows, Cols);
  135.  
  136.     if(map->cells == NULL || map->lab == NULL) {
  137.         Destructor(map);
  138.         fprintf(stderr, "Constructor allocation failure\n");
  139.         if(file != 0) {
  140.             fclose(file);
  141.         }
  142.         return 1;
  143.     }
  144.     int InitializedMap = CreateMap(map, file);
  145.  
  146.     if(CheckValidityMaze(map) && (InitializedMap == 0)) {
  147.         fclose(file);
  148.         Destructor(map);
  149.         printf("Is valid\n");
  150.         return 0;
  151.     }
  152.  
  153.     else {
  154.         fclose(file);
  155.         Destructor(map);
  156.         printf("Is not valid\n");
  157.         return 0;
  158.     }
  159. }
  160.  
  161. Map *Constructor(int rows, int collumns)
  162. {
  163.     Map *map = (Map *)malloc(sizeof(Map));
  164.     if(map == NULL) {
  165.         fprintf(stderr, "Malloc fail");
  166.         exit(1);
  167.     }
  168.  
  169.     map->rows = rows;
  170.     map->cols = collumns;
  171.  
  172.     int MemSize = ((rows * collumns) * sizeof(char));
  173.     map->cells = (unsigned char *)malloc(MemSize);
  174.     if(map->cells == NULL) {
  175.         fprintf(stderr, "Map structure allocation fail");
  176.         free(map);
  177.         exit(1);
  178.     }
  179.  
  180.     for(int i = 0; i < map->rows; i++) {
  181.         for(int j = 0; j < map->rows; j++) {
  182.             map->cells[i * map->cols] = 'O';
  183.         }
  184.     }
  185.  
  186.     map->lab = (info *)malloc((rows * collumns) * sizeof(info));
  187.     if(map->lab == NULL) {
  188.         fprintf(stderr, "Help structure allocation fail");
  189.         free(map->cells);
  190.         free(map);
  191.         exit(1);
  192.     }
  193.  
  194.     return map;
  195. }
  196.  
  197. void Destructor(Map *map)
  198. {
  199.     free(map->cells);
  200.     free(map->lab);
  201. }
  202.  
  203. //function to get both rows and cols, careful to use it reight
  204. int GetSize(FILE *path)
  205. {
  206.     char buff[3] = "\0";
  207.     if(fscanf(path, "%s", buff) == 0) {
  208.         return 0;
  209.     }
  210.  
  211.     if(buff[0] == '\0') {
  212.         return 0;
  213.     }
  214.  
  215.     return atoi(buff);
  216. }
  217.  
  218. int CreateMap(Map *map, FILE *file)
  219. {
  220.     char buff[2];
  221.     int counter = 0;
  222.     int scanned = 0;
  223.  
  224.     int IterNumber = map->rows * map->cols;
  225.  
  226.     while(1) {
  227.         scanned = fscanf(file, "%s", buff);
  228.         if((buff[0] < '0') || (buff[0] > '7')) {
  229.             return 1;
  230.         }
  231.         if(counter < IterNumber) {
  232.             map->lab[counter].side = map->cells[counter] = buff[0] - '0';
  233.         }
  234.         scanned != -1 ? counter++ : 0;
  235.         if((scanned == -1) && (counter != IterNumber)) {
  236.             return 1;
  237.         }
  238.         if(scanned == -1) {
  239.             break;
  240.         }
  241.     }
  242.  
  243.     //setting up initial values to main structure for further job
  244.     for(int i = 0; i < map->rows; i++) {
  245.         for(int j = 0; j < map->cols; j++) {
  246.             map->lab[i * map->cols + j].exit = -1;
  247.             map->lab[i * map->cols + j].entry = -1;
  248.             map->lab[i * map->cols + j].inuse = '\0';
  249.         }
  250.     }
  251.  
  252.     return 0;
  253. }
  254.  
  255. int StartValidationCheck(Map *map, int Row, int Col)
  256. {
  257.     //top and bottom pages
  258.     if((Row == 0) || (Row == map->rows -1)) {
  259.         if((Col != 0) || (Col == map->cols - 1)) {
  260.             if(!(map->cells[Row * map->cols + Col] & 4)) {
  261.                 return 4;
  262.             }
  263.             if(!(map->cells[Row * map->cols + Col] & 2)) {
  264.                 return 1;
  265.             }
  266.         }
  267.  
  268.         else {
  269.             if(!(map->cells[Row * map->cols + Col] & 2)) {
  270.                 return 1;
  271.             }
  272.             else if(!(map->cells[Row * map->cols + Col] & 1)) {
  273.                 return 2;
  274.             }
  275.             else if(!(map->cells[Row * map->cols + Col] & 4)) {
  276.                 return 4;
  277.             }
  278.         }
  279.     }
  280.  
  281.     //sides
  282.     if((Col == 0) || (Col == map->cols - 1)) {
  283.         if((Row != 0) || (Row == map->rows - 1)) {
  284.             if(!(map->cells[Row * map->cols + Col] & 1)) {
  285.                 return 2;
  286.             }
  287.  
  288.             else if(!(map->cells[Row * map->cols + Col] & 2)) {
  289.                 return 1;
  290.             }
  291.         }
  292.         else {
  293.             if(!(map->cells[Row * map->cols + Col] & 1)) {
  294.                 return 2;
  295.             }
  296.             else if(!(map->cells[Row * map->cols + Col] & 2)) {
  297.                 return 1;
  298.             }
  299.             else if(!(map->cells[Row * map->cols + Col] & 4)) {
  300.                 return 4;
  301.             }
  302.         }
  303.     }
  304.     return 0;
  305. }
  306.  
  307.  
  308.  
  309. //0 is false, 1 is true
  310. int IsBorder(Map *map, int Row, int Col, int Border)
  311. {
  312.     if(map->lab[Row * map->cols + Col].side & Border) {
  313.         return 1;
  314.     }
  315.  
  316.     return 0;
  317. }
  318.  
  319. void PrintHelp()
  320. {
  321.     printf("This is how it works:\n");
  322.     printf("Write --help for printing help\n");
  323.     printf("Type --test <filename> for running test to validation");
  324.     printf("Typed --test - if invalid - prints it");
  325.     printf("Type --rpath R C <filename> R - row and C - column for right-hand mode");
  326.     printf("Type -- lpath R C <filename> R - row and C - column for left-hand mode");
  327.     printf("Thanks for using this amazing app :)");
  328. }
  329.  
  330. //0 is false and 1 is true
  331. int CheckValidityMaze(Map *map)
  332. {
  333.     //TODO CHECK THIS
  334.     for(int i = 0; i < map->rows; i++) {
  335.         for(int j = 0; j < map->cols; j++) {
  336.             char Temp = map->cells[i * map->cols + j] - '0';
  337.             if(((Temp & 1) && (!CheckBorderNum1(map, i, j))) ||
  338.             ((Temp & 2) && (!CheckBorderNum2(map, i, j))) ||
  339.             ((Temp & 4) && (!CheckBorderNum4(map, i, j)))) {
  340.                 return 0;
  341.             }
  342.         }
  343.     }
  344.     return 1;
  345. }
  346.  
  347. //0 is false, 1 is true
  348. //TODO JMENA SPRÁVNĚ?
  349. int CheckBorder1(Map *map, int FirstSideIndex, int SecondSideIndex)
  350. {
  351.     if((SecondSideIndex == 0) || (map->cells[FirstSideIndex * map->cols + SecondSideIndex - 1] & 2)) {
  352.         return 1;
  353.     }
  354.     else {
  355.         return 0;
  356.     }
  357. }
  358.  
  359. //0 is false, 1 is true
  360. int CheckBorder2(Map *map, int FirstSideIndex, int SecondSideIndex)
  361. {
  362.     if((SecondSideIndex == map->cols - 1) || (map->cells[FirstSideIndex * map->cols + SecondSideIndex + 1] & 1)) {
  363.         return 1;
  364.     }
  365.  
  366.     else {
  367.         return 0;
  368.     }
  369. }
  370.  
  371. //0 is false, 1 is true
  372. int CheckBorder4(Map *map, int FirstSideIndex, int SecondSideIndex)
  373. {
  374.     if((FirstSideIndex + SecondSideIndex) & 1) {
  375.         if((FirstSideIndex == map->rows - 1) || (map->cells[(FirstSideIndex + 1) * map->cols + SecondSideIndex] & 4)) {
  376.             return 1;
  377.         }
  378.  
  379.         else {
  380.             return 0;
  381.         }
  382.     }
  383.  
  384.     else {
  385.         if((FirstSideIndex == 0) || (map ->cells[(FirstSideIndex - 1) * map->cols + SecondSideIndex] & 4)) {
  386.             return 1;
  387.         }
  388.         else {
  389.             return 0;
  390.         }
  391.     }
  392. }
  393.  
  394. //TODO PŘEHODIT
  395. int CheckMazeEntry(Map *map, int Rows, int Collumns)
  396. {
  397.     if((Rows == 0) || (Rows == map->rows - 1)) {
  398.         if((Collumns != 0) || (Collumns == map->cols - 1)) {
  399.             if(!(map->cells[Rows * map->cols + Collumns] & 4)) {
  400.                 return 4;
  401.             }
  402.             if(!(map->cells[Rows * map->cols + Collumns] & 2)) {
  403.                 return 1;
  404.             }
  405.         }
  406.         else {
  407.             if(!(map->cells[Rows * map->cols + Collumns] & 1)) {
  408.                 return 2;
  409.             }
  410.             else if(!(map->cells[Rows * map->cols + Collumns] & 4)) {
  411.                 return 4;
  412.             }
  413.             else if(!(map->cells[Rows * map->cols + Collumns] & 2)) {
  414.                 return 1;
  415.             }
  416.         }
  417.     }
  418.  
  419.     if((Collumns == 0) || (Collumns == map->cols - 1)) {
  420.         if((Rows != 0) || (Rows == map->rows - 1)) {
  421.             if(!(map->cells[Rows * map->cols + Collumns] & 1)) {
  422.                 //why
  423.                 return 2;
  424.             }
  425.             else if(!(map->cells[Rows * map->cols + Collumns] & 2)) {
  426.                 return 1;
  427.             }
  428.         }
  429.         else {
  430.             if(!(map->cells[Rows * map->cols + Collumns] & 1)) {
  431.                 return 2;
  432.             }
  433.  
  434.             else if(!(map->cells[Rows * map->cols + Collumns] & 2)) {
  435.                 return 2;
  436.             }
  437.  
  438.             else if(!(map->cells[Rows * map->cols + Collumns] & 4)) {
  439.                 return 4;
  440.             }
  441.         }
  442.     }
  443.  
  444.     return 0;
  445. }
  446. //returned 2 means success
  447. int DirectionFirst(Map *map, int *Rows, int *Columns)
  448. {
  449.     int Point = *Rows * map->cols + *Columns;
  450.  
  451.     if(!(map->lab[Point].side & 1) && !(map->lab[Point].inuse & 1)
  452.     && (map->lab[Point].entry != 2)) {
  453.         if(*Columns == 0) {
  454.             return 0;
  455.         }
  456.  
  457.         if(map->lab[Point - 1].exit == -1) {
  458.             map->lab[Point].exit = map->lab[Point - 1].entry = 1;
  459.             map->lab[Point].inuse |= 1;
  460.             *Columns -= -1;
  461.             return 1;
  462.         }
  463.     }
  464.     return 42;
  465. }
  466.  
  467. int DirectionSecond(Map *map, int *Rows, int *Columns)
  468. {
  469.     int Point = *Rows * map-> cols + *Columns;
  470.     if(!(map->lab[Point].side & 2) && !(map->lab[Point].inuse & 2)
  471.     && (map->lab[Point].entry != 1)) {
  472.         if(*Columns == map->cols - 1) {
  473.             return 0;
  474.         }
  475.  
  476.         if(map->lab[Point + 1].exit == -1) {
  477.             map->lab[Point].exit = map->lab[Point + 1].entry = 2;
  478.             map->lab[Point].inuse |= 2;
  479.             *Columns += 1;
  480.             return 2;
  481.         }
  482.     }
  483.  
  484.     return 42;
  485. }
  486.  
  487. int DirectionThird(Map *map, int *Rows, int *Columns)
  488. {
  489.     int Point = *Rows * map->cols + *Columns;
  490.     if(!(map->lab[Point].side & 4) && !((*Rows + *Columns) & 1) && !(map->lab[Point].inuse & 4)
  491.     && (map->lab[Point].entry != 4)) {
  492.         if(*Rows == 0) {
  493.             return 0;
  494.         }
  495.  
  496.         if((map->lab[(*Rows - 1) * map->cols + *Columns].exit == -1)) {
  497.             map->lab[Point].exit = map->lab[(*Rows - 1) * map->cols + *Columns].entry = 4;
  498.             map->lab[Point].inuse |= 4;
  499.             *Rows -= 1;
  500.             return 4;
  501.         }
  502.     }
  503.     if(!(map->lab[Point].side & 4) && ((*Rows + *Columns) & 1) && !(map->lab[Point].inuse & 4)
  504.     && map->lab[Point].entry != 4) {
  505.         if(*Rows == map->rows - 1) {
  506.             return 0;
  507.         }
  508.  
  509.         if((map->lab[(*Rows + 1) * map->cols + *Columns].exit == -1)) {
  510.             map->lab[Point].exit = map->lab[(*Rows + 1) * map->cols + *Columns].entry = 4;
  511.             map->lab[Point].inuse |= 4;
  512.             *Rows += 1;
  513.             return 4;
  514.         }
  515.     }
  516.  
  517.     return 42;
  518. }
  519.  
  520. void DirectionBack(Map *map, int *Rows, int *Columns)
  521. {
  522.     int Point = *Rows * map->cols + *Columns;
  523.     switch(map->lab[Point].entry) {
  524.         case 1:
  525.             *Columns += 1;
  526.             break;
  527.         case 2:
  528.             *Columns -= 1;
  529.             break;
  530.         case 4:
  531.             *Rows += ((*Rows + *Columns) & 1) ? 1 : -1;
  532.             break;
  533.     }
  534.  
  535.     map->lab[Point].entry = map->lab[Point].exit = -1;
  536.     map->lab[Point].inuse = 0;
  537. }
  538.  
  539. void LeftPath(Map *map, int Rows, int Columns, int Inside)
  540. {
  541.     int Row = Rows;
  542.     int Col = Columns;
  543.  
  544.     map->lab[Row * map->cols + Col].entry = Inside;
  545.  
  546.     while(1) {
  547.         printf("%d, %d\n", Row + 1, Col + 1);
  548.         int Point = Row * map->cols + Col;
  549.         int Result = 0;
  550.  
  551.         switch(map->lab[Point].entry) {
  552.             case 1:
  553.                 if((Row + Col) & 1) {
  554.                     Result = DirectionThird(map, &Row, &Col);
  555.                     if(Result == 0) {
  556.                         return;
  557.                     }
  558.                     if(Result == 4) {
  559.                         break;
  560.                     }
  561.                     Result = DirectionFirst(map, &Row, &Col);
  562.                     if(Result == 0) {
  563.                         return;
  564.                     }
  565.                     if(Result == 1) {
  566.                         break;
  567.                     }
  568.                     DirectionBack(map, &Row, &Col);
  569.                     break;
  570.                 }
  571.                 Result = DirectionFirst(map, &Row, &Col);
  572.                 if(Result == 0) {
  573.                     return;
  574.                 }
  575.                 if(Result == 1) {
  576.                     break;
  577.                 }
  578.                 Result = DirectionThird(map, &Row, &Col);
  579.                 if(Result == 0) {
  580.                     return;
  581.                 }
  582.                 if(Result == 4) {
  583.                     break;
  584.                 }
  585.                 DirectionBack(map, &Row, &Col);
  586.                 break;
  587.             case 2:
  588.                 if((Row + Col) & 1) {
  589.                     Result = DirectionSecond(map, &Row, &Col);
  590.                     if(Result == 0) {
  591.                         return;
  592.                     }
  593.                     if(Result == 2) {
  594.                         break;
  595.                     }
  596.                     Result = DirectionThird(map, &Row, &Col);
  597.                     if(Result == 0) {
  598.                         return;
  599.                     }
  600.                     if(Result == 4) {
  601.                         break;
  602.                     }
  603.                     DirectionBack(map, &Row, &Col);
  604.                     break;
  605.                 }
  606.                 Result = DirectionThird(map, &Row, &Col);
  607.                 if(Result == 0) {
  608.                     return;
  609.                 }
  610.                 if(Result == 4) {
  611.                     break;
  612.                 }
  613.                 Result = DirectionSecond(map, &Row, &Col);
  614.                 if(Result == 0) {
  615.                     return;
  616.                 }
  617.                 if(Result == 2) {
  618.                     break;
  619.                 }
  620.                 DirectionBack(map, &Row, &Col);
  621.                 break;
  622.             case 4:
  623.                 if((Row + Col) & 1) {
  624.                     Result = DirectionFirst(map, &Row, &Col);
  625.                     if(Result == 0) {
  626.                         return;
  627.                     }
  628.                     if(Result == 1) {
  629.                         break;
  630.                     }
  631.                     Result = DirectionSecond(map, &Row, &Col);
  632.                     if(Result == 0) {
  633.                         return;
  634.                     }
  635.                     if(Result == 2) {
  636.                         break;
  637.                     }
  638.                     DirectionBack(map, &Row, &Col);
  639.                     break;
  640.                 }
  641.                 Result = DirectionSecond(map, &Row, &Col);
  642.                 if(Result == 0) {
  643.                     return;
  644.                 }
  645.                 if(Result == 2) {
  646.                     break;
  647.                 }
  648.                 Result = DirectionFirst(map, &Row, &Col);
  649.                 if(Result == 0) {
  650.                     return;
  651.                 }
  652.                 if(Result == 1) {
  653.                     break;
  654.                 }
  655.                 DirectionBack(map, &Row, &Col);
  656.                 break;
  657.         }
  658.     }
  659. }
  660.  
  661. void RightPath(Map *map, int Rows, int Columns, int Inside) {
  662.     int Row = Rows;
  663.     int Col = Columns;
  664.  
  665.     //setting up the access entrance
  666.     map->lab[Row * map->cols + Col].entry = Inside;
  667.  
  668.     while (1) {
  669.  
  670.         //printf out the way
  671.         printf("%i, %i\n", Row + 1, Col + 1);
  672.         int Point = Row * map->cols + Col;
  673.         int Result;
  674.  
  675.         //in every case there is the if to see how the space is oriented, because it is different in every case
  676.         switch (map->lab[Point].entry) {
  677.             case 1:
  678.                 if ((Row + Col) & 1) {
  679.  
  680.                     //the way you go dettermined the way you came
  681.                     Result = DirectionFirst(map, &Row, &Col);
  682.                     if (Result == 0) {
  683.                         return;
  684.                     }
  685.                     if (Result == 1) {
  686.                         break;
  687.                     }
  688.                     Result = DirectionThird(map, &Row, &Col);
  689.                     if (Result == 0) {
  690.                         return;
  691.                     }
  692.                     if (Result == 4) {
  693.                         break;
  694.                     }
  695.                     DirectionBack(map, &Row, &Col);
  696.                     break;
  697.                 }
  698.                 Result = DirectionThird(map, &Row, &Col);
  699.                 if (Result == 0) {
  700.                     return;
  701.                 }
  702.                 if (Result == 4) {
  703.                     break;
  704.                 }
  705.                 Result = DirectionFirst(map, &Row, &Col);
  706.                 if (Result == 0) {
  707.                     return;
  708.                 }
  709.                 if (Result == 1) {
  710.                     break;
  711.                 }
  712.                 DirectionBack(map, &Row, &Col);
  713.                 break;
  714.             case 2:
  715.                 if ((Row + Col) & 1) {
  716.                     Result = DirectionThird(map, &Row, &Col);
  717.                     if (Result == 0) {
  718.                         return;
  719.                     }
  720.                     if (Result == 4) {
  721.                         break;
  722.                     }
  723.                     Result = DirectionSecond(map, &Row, &Col);
  724.                     if (Result == 0) {
  725.                         return;
  726.                     }
  727.                     if (Result == 2) {
  728.                         break;
  729.                     }
  730.                     DirectionBack(map, &Row, &Col);
  731.                     break;
  732.                 }
  733.                 Result = DirectionSecond(map, &Row, &Col);
  734.                 if (Result == 0) {
  735.                     return;
  736.                 }
  737.                 if (Result == 2) {
  738.                     break;
  739.                 }
  740.                 Result = DirectionThird(map, &Row, &Col);
  741.                 if (Result == 0) {
  742.                     return;
  743.                 }
  744.                 if (Result == 4) {
  745.                     break;
  746.                 }
  747.                 DirectionBack(map, &Row, &Col);
  748.                 break;
  749.             case 4:
  750.                 if ((Row + Col) & 1) {
  751.                     Result = DirectionSecond(map, &Row, &Col);
  752.                     if (Result == 0) {
  753.                         return;
  754.                     }
  755.                     if (Result == 2) {
  756.                         break;
  757.                     }
  758.                     Result = DirectionFirst(map, &Row, &Col);
  759.                     if (Result == 0) {
  760.                         return;
  761.                     }
  762.                     if (Result == 1) {
  763.                         break;
  764.                     }
  765.                     DirectionBack(map, &Row, &Col);
  766.                     break;
  767.                 }
  768.                 Result = DirectionFirst(map, &Row, &Col);
  769.                 if (Result == 0) {
  770.                     return;
  771.                 }
  772.                 if (Result == 1) {
  773.                     break;
  774.                 }
  775.                 Result = DirectionSecond(map, &Row, &Col);
  776.                 if (Result == 0) {
  777.                     return;
  778.                 }
  779.                 if (Result == 2) {
  780.                     break;
  781.                 }
  782.                 DirectionBack(map, &Row, &Col);
  783.                 break;
  784.         }
  785.     }
  786. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement