添加了求与请求距离的函数
添加了表示整个轨道长度的全局变量
This commit is contained in:
parent
7e0afb9990
commit
3b6d7933a7
|
@ -28,14 +28,13 @@ extern bus_t *the_bus;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 每个时刻使公交车前进
|
* 每个时刻使公交车前进
|
||||||
* @param rails 轨道链表
|
|
||||||
* @param direction 公交车前进的方向
|
* @param direction 公交车前进的方向
|
||||||
*/
|
*/
|
||||||
void RunBus(int direction);
|
void RunBus(int direction);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 判断公交车是否到站
|
* 判断公交车是否到站
|
||||||
* @return
|
* @return BUS_TRUE为到站,BUS_FALSE为未到站
|
||||||
*/
|
*/
|
||||||
int JudgeOnStation();
|
int JudgeOnStation();
|
||||||
|
|
||||||
|
@ -44,4 +43,12 @@ int JudgeOnStation();
|
||||||
* @return 公交车当前所在的位置
|
* @return 公交车当前所在的位置
|
||||||
*/
|
*/
|
||||||
int GetBusPosition();
|
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
|
#endif //AUTO_PILOT_BUS_BUS_H
|
||||||
|
|
|
@ -26,8 +26,6 @@ int ReadInput(char* inputString);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 打印当前的状态
|
* 打印当前的状态
|
||||||
* @param rails 轨道链表
|
|
||||||
* @return 返回需输出的字符串
|
|
||||||
*/
|
*/
|
||||||
void PrintState();
|
void PrintState();
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,11 @@ typedef struct rail_node rail_node_t;
|
||||||
*/
|
*/
|
||||||
extern rail_node_t *rails;
|
extern rail_node_t *rails;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 轨道的总长度
|
||||||
|
*/
|
||||||
|
extern int all_distance;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 全局的计时器
|
* 全局的计时器
|
||||||
*/
|
*/
|
||||||
|
|
26
src/bus.c
26
src/bus.c
|
@ -83,3 +83,29 @@ int JudgeOnStation()
|
||||||
return BUS_FAlSE;
|
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;
|
||||||
|
}
|
|
@ -151,6 +151,7 @@ rail_node_t *ReadConfigFile()
|
||||||
chosen_strategy = BUS_FCFS;
|
chosen_strategy = BUS_FCFS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
all_distance = distance * total_station;
|
||||||
rail_node_t *head = CreateRails(distance, total_station);
|
rail_node_t *head = CreateRails(distance, total_station);
|
||||||
return head;
|
return head;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
rail_node_t *rails = NULL;
|
rail_node_t *rails = NULL;
|
||||||
int bus_time = 0;
|
int bus_time = 0;
|
||||||
|
int all_distance = 0;
|
||||||
|
|
||||||
rail_node_t *CreateRails(int length, int node_num)
|
rail_node_t *CreateRails(int length, int node_num)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user