Corrections projet

This commit is contained in:
Adrien Guatto
2025-12-01 16:07:50 +01:00
parent 70fc7019dc
commit 6c8abfbade
3 changed files with 25 additions and 46 deletions

View File

@@ -66,13 +66,15 @@ let
false);
tel
(* The car angle with the road should be in the range -120..120 degree *)
node wrong_dir(ph : phase) returns (wrong : bool)
var data : map_data; error : float; ang : float;
var data : map_data; norm, error : float; ang : float;
let
data = lookup_phase(ph);
ang = ph.ph_head *. (pi /. 180.0);
norm = Mathext.sqrt(data.dir_x *. data.dir_x +. data.dir_y *. data.dir_y);
error = data.dir_x *. Mathext.cos(ang) +. data.dir_y *. Mathext.sin(ang);
wrong = error <. -. 0.5;
wrong = error <. -. 0.5 *. norm;
tel
fun aggregate_events(lightRun, speedExcess, exitRoad, collisionEvent,
@@ -188,7 +190,7 @@ tel
(* Scoring *)
node scoringA(e : event; rstatus : status) returns (score : int)
var penalty : int; collision_count : int;
var penalty : int;
let
score = (10000 fby score)
+ if Utilities.rising_edge(rstatus = Arrived) then 1000 else 0
@@ -198,9 +200,7 @@ let
+ (if e.speedExcess then -2 else 0)
+ (if Utilities.rising_edge(e.exitRoad) then -5000 else 0)
+ (if Utilities.rising_edge(e.dirEvent) then -2000 else 0)
+ (if collision_count = 0 then -500 else 0)
+ (if collision_count < 0 then 10 else 0);
collision_count = Utilities.countdown(not e.collisionEvent, 20);
+ (if Utilities.rising_edge(e.collisionEvent) then -500 else 0);
tel
node scoringB(ph : phase) returns (score : int)

View File

@@ -683,29 +683,6 @@ bool isOnRoadArc(/* IN */
return true;
}
int isOnTLight(int x, int y, int rd, float dir_x, float dir_y)
{
if (map->tlight_arr == NULL ||
map->tlight_sz <= 0)
return -1;
//no traffic light
for (int i = 0; i < map->tlight_sz; i++) {
tlight_t *tl = &map->tlight_arr[i];
if (tl->road != rd)
continue;
double d = distance(x, y, tl->tl.ptl_pos.x, tl->tl.ptl_pos.y);
/* double cosdir = dirCos(tl->tl.ptl_pos.y - y, x - tl->tl.ptl_pos.x,
dir_x, dir_y); */ //MS
double cosdir = dirCos(tl->tl.ptl_pos.x-x, tl->tl.ptl_pos.y-y,
dir_x, dir_y); //EA
if (d < TL_VIEW && cosdir > TL_COSDIR)
return i;
}
return -1;
}
bool isAfterStop(int x, int y, int rid, float dir_x, float dir_y, int* tl)
{
(*tl) = -1;
@@ -822,7 +799,7 @@ isPositionOnPoint(float x, float y, road_t* rd, position_t* p, double pWidth)
}
}
Globals__color getColorPoint(int rid, float x, float y) {
Globals__color getColorPoint(int rid, float x, float y, int* tl) {
// first go through waypoints
log_debug("[geometry] looking for waypoints at (%.2f, %.2f) on road %d\n",
x, y, rid);
@@ -855,6 +832,7 @@ Globals__color getColorPoint(int rid, float x, float y) {
// stop points are ruban
if (isPositionOnPoint(x, y, rd, &sp->position, RD_SIZE_STOP)) {
log_debug("[geometry] (%.2f, %.2f) at stop %d\n", x, y, i);
*tl = sp->sema;
return COL_STOP;
//one stop by position
}
@@ -909,28 +887,22 @@ DEFINE_HEPT_FUN(Map, lookup_pos, (Globals__position pos)) {
out->data.dir_x = dir_X;
out->data.dir_y = dir_Y;
out->data.max_speed = map->road_arr[min_rd].max_speed;
/* Update color when a waypoint or stop. */
col = getColorPoint(rid, x, y);
if (colors_equal(&col, &COL_OUT))
out->data.color = out->data.color;
else if (colors_equal(&col, &COL_STOP)) {
/* TODO: update red color */
out->data.color = col;
}
else {
/* TODO: update green color */
out->data.color = col;
}
}
}
/* Update color when a waypoint or stop. */
int tl = -1;
if (min_rd >= 0) {
Globals__color col = getColorPoint(min_rd, x, y, &tl);
if (!colors_equal(&col, &COL_OUT))
out->data.color = col;
}
/* Compute the return type. */
if (min_rd >= 0) {
log_debug("[geometry] (%.2f, %.2f) is on road %d\n", x, y, min_rd);
out->data.on_road = true;
int tl = -1;
out->data.tl_number =
isOnTLight(x, y, min_rd, out->data.dir_x, out->data.dir_y);
out->data.tl_number = tl;
out->data.tl_required = isAfterStop(x, y, min_rd,
out->data.dir_x, out->data.dir_y, &tl);
if(out->data.tl_required) {

View File

@@ -157,7 +157,7 @@ race_result_t simulation_loop(bool show_guide,
SDL_WINDOWPOS_UNDEFINED,
MAX_X,
MAX_Y,
SDL_WINDOW_SHOWN)) == NULL)
SDL_WINDOW_SHOWN|SDL_WINDOW_RESIZABLE)) == NULL)
log_fatal("[sdl] could not open window (%s)\n", SDL_GetError());
r = SDL_CreateRenderer(w, -1, SDL_RENDERER_ACCELERATED);
@@ -256,6 +256,13 @@ race_result_t simulation_loop(bool show_guide,
case SDL_QUIT:
quit = true;
break;
case SDL_WINDOWEVENT:
if (e.window.event == SDL_WINDOWEVENT_RESIZED) {
float newwidth = e.window.data1;
float newheight = e.window.data2;
SDL_RenderSetScale(r, newwidth / MAX_X, newheight / MAX_Y);
}
break;
case SDL_KEYDOWN:
switch (e.key.keysym.sym) {
case SDLK_q: