Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <stdbool.h>
- /**
- * Auto-generated code below aims at helping you parse
- * the standard input according to the problem statement.
- **/
- struct Path{
- struct Path *next;
- int length;
- int dir; // 0 north, 1 south, 2 east, 3 west
- };
- struct Node{
- int x,y;
- struct Node *north, *south, *east,*west;
- bool sea;
- bool visited;
- };
- int main()
- {
- int width;
- int height;
- int my_id;
- scanf("%d%d%d", &width, &height, &my_id); fgetc(stdin);
- struct Node map[height][width];
- for (int i = 0; i < height; i++) {
- char line[width + 1];
- fgets(line, width + 1, stdin); fgetc(stdin);
- for (int j = 0; j < width; j++){
- bool sea = true;
- if(line[j] == 'x'){sea = false;}
- map[i][j].sea = sea;
- map[i][j].visited = false;
- map[i][j].x = j;
- map[i][j].y = i;
- }
- }
- for(int i = 0; i < height; i++){
- for (int j = 0; j < width; j++){
- // define north
- if(i == 0){map[i][j].north = NULL;}
- else{map[i][j].north = &map[i-1][j];}
- //define south
- if(i == height){map[i][j].south = NULL;}
- else{map[i][j].south = &map[i+1][j];}
- //define west
- if(j == 0){map[i][j].west = NULL;}
- else{map[i][j].west = &map[i][j-1];}
- //define east
- if(j == width){map[i][j].east = NULL;}
- else{map[i][j].east = &map[i][j+1];}
- }
- }
- struct Node *pos = &map[5][7];
- struct Path *p;
- exploreNorth(pos, &p);
- fprintf(stderr,"%i\n",p->length);
- fprintf(stderr,"here");
- // Write an action using printf(). DON'T FORGET THE TRAILING \n
- // To debug: fprintf(stderr, "Debug messages...\n");
- printf("7 7\n");
- // game loop
- while (1) {
- int x;
- int y;
- int my_life;
- int opp_life;
- int torpedo_cooldown;
- int sonar_cooldown;
- int silence_cooldown;
- int mine_cooldown;
- scanf("%d%d%d%d%d%d%d%d", &x, &y, &my_life, &opp_life, &torpedo_cooldown, &sonar_cooldown, &silence_cooldown, &mine_cooldown);
- char sonar_result[4];
- scanf("%s", sonar_result); fgetc(stdin);
- char opponent_orders[201];
- fgets(opponent_orders, 201, stdin);
- // Write an action using printf(). DON'T FORGET THE TRAILING \n
- // To debug: fprintf(stderr, "Debug messages...\n");
- printf("MOVE N TORPEDO\n");
- }
- return 0;
- }
- void exploreNorth(struct Node *n, struct Path **p){
- fprintf(stderr,"start\n");
- struct Path path = {.length = 0, .dir = 0};
- struct Path *ptr;
- ptr = &path;
- fprintf(stderr,"%i %i\n",n->x,n->y);
- if(n->north == NULL){
- fprintf(stderr,"if null\n");
- *p = ptr;
- return;
- }
- exploreNorth(n->north,&((*p)->next));
- fprintf(stderr,"post\n");
- (*p)->length = (*p)->next->length + 1;
- //p->dir = 0;
- fprintf(stderr,"end\n");
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment