Пример #1
0
int		main(int ac, char **ag)
{
  t_struct	*window;
  t_data	*data;

  if (ac > 1)
    data = get_the_map(ag[1]);
  else
    data = get_the_map(NULL);
  if (data == NULL)
    return (main_error(1));
  if ((window = display(data)) == NULL)
    return (-1);
  event_manage(window, data);
  return (0);
}
Пример #2
0
void		get_new_map(t_event *event)
{
  int	i;
  char	*tmp;

  tab_free(event->data->map);
  free(event->data->initial);
  wait(&i);
  event->data->name[my_strlen(event->data->name) - 1]++;
  tmp = event->data->name;
  free(event->data);
  if ((event->data = get_the_map(tmp)) == NULL)
    {
      my_printf("Congratulation\n");
      exit(1);
    }
  back_ground(event->window);
}
main()
{     
      FILE *f;
      char filename[50];
      printf("input the name of the file:");
      scanf("%s",filename);//the file's name can be absolute path,include the .txt example: D:\\file1\\file2\\test.txt
      f=fopen(filename,"r");
      if (f==NULL)//if can not open the file,stop the program
      {
         printf("OMG,the file is not existed!\n");
         system("pause");
         return;
         }
      get_the_map(f);//get the information of map
      getchar();
      printf("input the start street name:");
      gets(start_street);
      printf("input the start house number:");
      scanf("%d",&start_house);
      getchar();
      printf("input the destination street name:");
      gets(destination_street);
      printf("input the destination house number:");
      scanf("%d",&destination_house);
      
      Insert_start_destination(street_num,start_house,destination_house,start_street,destination_street);
      if (start_unique=='\0' || destination_unique=='\0')//if we don't get the unique number for start and destination nodes,we stop.
      {
           system("pause");
           return 0;
           }
      if (start_unique == destination_unique)//if the start node has the same coordinate as the destination node.stop.
      {
           printf("the start point is the same as destination!\n");
           system("pause");
           return 0;
           }
      int k=1;
      int i,j;
      Dijkstra();//Dijkstra is to store each node's father unique numbers
      struct search_path BFS_array[50];
      /*the destination node has his father nodes,and these father nodes also have their own father nodes.
        So it's a tree,and I use the BFS method to find every shortest path.
      */
      int label;
      label=Index(destination_unique);
      BFS_array[1].unique=destination_unique;
      i=1;
      int from,present;//"from" and "present" are labels in the array 
      from=2;
      j=from;
      present=from+adj_list[label].father_num;
      while (i<=adj_list[label].father_num)//begin at the destination,so that store the destination's father firstly
      {
            BFS_array[j].unique=adj_list[label].father_unique_num[i];
            BFS_array[j].pre_label=1;
            j++;
            i++;
            }
      get_BFS_list(BFS_array,from,present);//"from" to store the present first father's position,and "present" to store the array's present position
      i=1;
      int counter=0;
      while(BFS_array[i].unique!='\0')//"counter" is to get the total number of the shortest pathes
      {
            if (BFS_array[i].unique==start_unique)
                  counter++;
            i++;
      }
      struct each_path shortest_ways[counter+1];
      get_the_pathes(shortest_ways,BFS_array);
      int ways=counter;
      for (i=1;i<=ways;i++)//for each shortest path,store each node's distance between he and his father
      {
          path_link present;
          present=&shortest_ways[i];
          float pre_x,pre_y;
          if (present->unique_num==1)//if the unique number is 1,do some special operations
          {
                pre_x=start_x;
                pre_y=start_y;
          }
          else
          {
                present->x=present->unique_num/100;
                present->y=present->unique_num%100;
                pre_x=present->x;
                pre_y=present->y;
          }
          present=present->next_node;
          while(present!=NULL)
          {
                float X,Y;
                if (present->unique_num==2)//if the next node is destination node,also do some special operations
                {
                      X=pre_x-destination_x;
                      Y=pre_y-destination_y;
                      present->distance=sqrt(pow(X,2)+pow(Y,2))*mile;
                }
                else
                {
                      present->x=present->unique_num/100;
                      present->y=present->unique_num%100;
                      X=pre_x-present->x;
                      Y=pre_y-present->y;
                      present->distance=sqrt(pow(X,2)+pow(Y,2))*mile;
                      pre_x=present->x;
                      pre_y=present->y;
                }
                present=present->next_node;
          }
      }
      turn_by_turn(shortest_ways,ways);//turn by turn output each shortest path
      system("pause");
}
main()
{     
      FILE *f;
      char filename[50];
      printf("input the name of the file:");
      scanf("%s",filename);//the file's name can be absolute path,include the .txt example: D:\\file1\\file2\\test.txt
      f=fopen(filename,"rb");
      if (f==NULL)//if can not open the file,stop the program
      {
         printf("OMG,the file is not existed!\n");
         system("pause");
         return;
         }
      get_the_map(f);
      getchar();
      printf("input the start street name:");
      gets(start_street);
      printf("input the start house number:");
      scanf("%d",&start_house);
      getchar();
      printf("input the destination street name:");
      gets(destination_street);
      printf("input the destination house number:");
      scanf("%d",&destination_house);
      
      Insert_start_destination(street_num,start_house,destination_house,start_street,destination_street);
      if (start_unique=='\0' || destination_unique=='\0')
      {
           system("pause");
           return 0;
           }
      if (start_unique == destination_unique)
      {
           printf("the start point is the same as destination!\n");
           system("pause");
           return 0;
           }
      int k=1;
      int i,j;
      Dijkstra();//Dijkstra算法存储从起点开始,每个点到起点的最短路径的父亲节点 
      struct search_path BFS_array[50];
      /*the destination node has his father nodes,and these father nodes also have their own father nodes.
        So it's a tree,and I use the BFS method to find every shortest path.
      */
      int label;
      label=Index(destination_unique);
      BFS_array[1].unique=destination_unique;
      i=1;
      int from,present;//from 和 to 都是数组的角标 
      from=2;
      j=from;
      present=from+adj_list[label].father_num;
      while (i<=adj_list[label].father_num)//此次循环得到终点以及终点的父节点,将他们纳入BFS_array这个集合 
      {
            BFS_array[j].unique=adj_list[label].father_unique_num[i];
            BFS_array[j].pre_label=1;
            j++;
            i++;
            }
      get_BFS_list(BFS_array,from,present);////////!!!!!!!!!!!!!
      i=1;
      int counter=0;
      while(BFS_array[i].unique!='\0')//get the total number of the shortest pathes
      {
            if (BFS_array[i].unique==start_unique)
                  counter++;
            i++;
      }
      struct each_path shortest_ways[counter+1];
      get_the_pathes(shortest_ways,BFS_array);
      int ways=counter;
      for (i=1;i<=ways;i++)
      {
          path_link present;
          present=&shortest_ways[i];
          float pre_x,pre_y;
          if (present->unique_num==1)
          {
                pre_x=start_x;
                pre_y=start_y;
          }
          else
          {
                present->x=present->unique_num/100;
                present->y=present->unique_num%100;
                pre_x=present->x;
                pre_y=present->y;
          }
          present=present->next_node;
          while(present!=NULL)
          {
                float X,Y;
                if (present->unique_num==2)
                {
                      X=pre_x-destination_x;
                      Y=pre_y-destination_y;
                      present->distance=sqrt(pow(X,2)+pow(Y,2))*mile;
                }
                else
                {
                      present->x=present->unique_num/100;
                      present->y=present->unique_num%100;
                      X=pre_x-present->x;
                      Y=pre_y-present->y;
                      present->distance=sqrt(pow(X,2)+pow(Y,2))*mile;
                      pre_x=present->x;
                      pre_y=present->y;
                }
                present=present->next_node;
          }
      }
      turn_by_turn(shortest_ways,ways);
      system("pause");
}