添加了求与请求距离的函数

添加了表示整个轨道长度的全局变量
This commit is contained in:
jackfiled 2022-06-03 21:28:52 +08:00
parent 7e0afb9990
commit 3b6d7933a7
6 changed files with 42 additions and 4 deletions

View File

@ -28,14 +28,13 @@ extern bus_t *the_bus;
/**
* 使
* @param rails
* @param direction
*/
void RunBus(int direction);
/**
*
* @return
* @return BUS_TRUE为到站BUS_FALSE为未到站
*/
int JudgeOnStation();
@ -44,4 +43,12 @@ int JudgeOnStation();
* @return
*/
int GetBusPosition();
/**
*
* @param query
* @param orientation BUS_CLOCK_WISE BUS_COUNTER_CLOCK_WISE
* @return
*/
int GetQueryDistance(bus_query_t *query, int orientation);
#endif //AUTO_PILOT_BUS_BUS_H

View File

@ -26,8 +26,6 @@ int ReadInput(char* inputString);
/**
*
* @param rails
* @return
*/
void PrintState();

View File

@ -35,6 +35,11 @@ typedef struct rail_node rail_node_t;
*/
extern rail_node_t *rails;
/**
*
*/
extern int all_distance;
/**
*
*/

View File

@ -82,4 +82,30 @@ int JudgeOnStation()
{
return BUS_FAlSE;
}
}
int GetQueryDistance(bus_query_t *query, int orientation)
{
rail_node_t *target_node = query->node;
rail_node_t *now_node = the_bus->rail_node_pos;
int distance = 0;
if(orientation == BUS_CLOCK_WISE)
{
while (now_node != target_node)
{
distance += now_node->next_node_distance;
now_node = now_node->next_node;
}
}
else if(orientation == BUS_COUNTER_CLOCK_WISE)
{
while (now_node != target_node)
{
distance += now_node->last_node_distance;
now_node = now_node->last_node;
}
}
return distance;
}

View File

@ -151,6 +151,7 @@ rail_node_t *ReadConfigFile()
chosen_strategy = BUS_FCFS;
}
all_distance = distance * total_station;
rail_node_t *head = CreateRails(distance, total_station);
return head;
}

View File

@ -2,6 +2,7 @@
rail_node_t *rails = NULL;
int bus_time = 0;
int all_distance = 0;
rail_node_t *CreateRails(int length, int node_num)
{