Guest User

Untitled

a guest
Mar 21st, 2020
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdbool.h>
  5.  
  6. /**
  7. * Auto-generated code below aims at helping you parse
  8. * the standard input according to the problem statement.
  9. **/
  10.  
  11. struct Path{
  12. struct Path *next;
  13. int length;
  14. int dir; // 0 north, 1 south, 2 east, 3 west
  15. };
  16. struct Node{
  17. int x,y;
  18. struct Node *north, *south, *east,*west;
  19. bool sea;
  20. bool visited;
  21. };
  22. int main()
  23. {
  24. int width;
  25. int height;
  26. int my_id;
  27. scanf("%d%d%d", &width, &height, &my_id); fgetc(stdin);
  28. struct Node map[height][width];
  29. for (int i = 0; i < height; i++) {
  30. char line[width + 1];
  31. fgets(line, width + 1, stdin); fgetc(stdin);
  32. for (int j = 0; j < width; j++){
  33. bool sea = true;
  34. if(line[j] == 'x'){sea = false;}
  35. map[i][j].sea = sea;
  36. map[i][j].visited = false;
  37. map[i][j].x = j;
  38. map[i][j].y = i;
  39. }
  40. }
  41. for(int i = 0; i < height; i++){
  42. for (int j = 0; j < width; j++){
  43. // define north
  44. if(i == 0){map[i][j].north = NULL;}
  45. else{map[i][j].north = &map[i-1][j];}
  46.  
  47. //define south
  48. if(i == height){map[i][j].south = NULL;}
  49. else{map[i][j].south = &map[i+1][j];}
  50.  
  51. //define west
  52. if(j == 0){map[i][j].west = NULL;}
  53. else{map[i][j].west = &map[i][j-1];}
  54.  
  55. //define east
  56. if(j == width){map[i][j].east = NULL;}
  57. else{map[i][j].east = &map[i][j+1];}
  58. }
  59. }
  60.  
  61. struct Node *pos = &map[5][7];
  62. struct Path *p;
  63. exploreNorth(pos, &p);
  64. fprintf(stderr,"%i\n",p->length);
  65. fprintf(stderr,"here");
  66. // Write an action using printf(). DON'T FORGET THE TRAILING \n
  67. // To debug: fprintf(stderr, "Debug messages...\n");
  68.  
  69. printf("7 7\n");
  70.  
  71. // game loop
  72. while (1) {
  73. int x;
  74. int y;
  75. int my_life;
  76. int opp_life;
  77. int torpedo_cooldown;
  78. int sonar_cooldown;
  79. int silence_cooldown;
  80. int mine_cooldown;
  81. scanf("%d%d%d%d%d%d%d%d", &x, &y, &my_life, &opp_life, &torpedo_cooldown, &sonar_cooldown, &silence_cooldown, &mine_cooldown);
  82. char sonar_result[4];
  83. scanf("%s", sonar_result); fgetc(stdin);
  84. char opponent_orders[201];
  85. fgets(opponent_orders, 201, stdin);
  86.  
  87. // Write an action using printf(). DON'T FORGET THE TRAILING \n
  88. // To debug: fprintf(stderr, "Debug messages...\n");
  89.  
  90. printf("MOVE N TORPEDO\n");
  91. }
  92.  
  93. return 0;
  94. }
  95.  
  96. void exploreNorth(struct Node *n, struct Path **p){
  97. fprintf(stderr,"start\n");
  98. struct Path path = {.length = 0, .dir = 0};
  99. struct Path *ptr;
  100. ptr = &path;
  101. fprintf(stderr,"%i %i\n",n->x,n->y);
  102. if(n->north == NULL){
  103. fprintf(stderr,"if null\n");
  104. *p = ptr;
  105. return;
  106. }
  107. exploreNorth(n->north,&((*p)->next));
  108. fprintf(stderr,"post\n");
  109. (*p)->length = (*p)->next->length + 1;
  110. //p->dir = 0;
  111. fprintf(stderr,"end\n");
  112. return;
  113. }
Advertisement
Add Comment
Please, Sign In to add comment