Compare commits

..

2 Commits

Author SHA1 Message Date
Alexandre 20bdf01a00 Update #1 2025-06-06 19:44:14 +02:00
Alexandre 17983b20b3 added slow tiles$ 2025-06-06 13:55:47 +02:00
16 changed files with 221 additions and 107 deletions

View File

@ -5,7 +5,7 @@ LFLAGS = -lSDL2 -lSDL2_image -lm
all: bin/back all: bin/back
replay: bin/back replay: bin/back
bin/back levels/test.txt REP bots/dumb bots/dumb2 bots/dumb3 bots/dumb4 bin/back levels/test.txt bots/dumb bots/dumb2 bots/dumb3 bots/dumb4
testL: bin/back testL: bin/back
bin/back levels/test.txt bots/dumb bots/dumb2 bots/dumb3 bots/dumb4 bots/dumb5 bots/dumb6 bin/back levels/test.txt bots/dumb bots/dumb2 bots/dumb3 bots/dumb4 bots/dumb5 bots/dumb6

View File

@ -1 +1 @@
270 100 40 100

View File

@ -79,6 +79,7 @@ let trackDistance = read_float meta metai in (*
in other words, the width of the track is (except for start and finish) roomSize*(1-2*trackDistance) in other words, the width of the track is (except for start and finish) roomSize*(1-2*trackDistance)
*) *)
let magneticField = read_float meta metai in (* workd just like in induction : v ^ B is added to the speed each tick *) let magneticField = read_float meta metai in (* workd just like in induction : v ^ B is added to the speed each tick *)
let slowZoneWidth = read_float meta metai in (* slow area width (see schematic) *)
close_in file ; close_in file ;
(*Printf.printf "%d %d %d %f %f %f\n" roomSize maximumSpeed playerRadius friction restitutionFactor trackDistance ;;*) (*Printf.printf "%d %d %d %f %f %f\n" roomSize maximumSpeed playerRadius friction restitutionFactor trackDistance ;;*)

View File

@ -1,68 +1,80 @@
-4.520035 -153.010954 -126.965777 105.016079
21.769531 -238.471209 178.506987 157.483510
-19.987625 -241.204125 79.937093 241.211724
-19.500799 -168.039659 -160.774653 -38.383354
14.728318 -231.892620 -167.593415 -29.904529
-1.146169 -211.802657 -7.294048 -246.314004
160.346794 -12.942202 1.925443 225.657331
14.734663 -229.843788 -83.767622 138.353905
183.187726 -20.067243 85.819605 202.420133
191.008872 -6.736352 82.714981 -146.254252
170.348954 0.561499 -113.224829 -183.040838
14.343889 -247.122293 -44.292231 239.426093
20.500323 190.947536 73.408148 -201.606239
203.536940 20.430462 136.403228 78.074414
-16.283639 158.826220 -118.750657 -212.011229
238.344449 12.606080 -199.504334 -148.063798
177.328188 4.682923 -61.943425 -155.586957
186.150359 3.312978 -94.406224 124.392990
156.149007 -14.652285 -118.474016 134.581478
-0.279201 226.257003 176.787805 -145.003525
155.454736 7.969019 -0.963485 167.948868
-15.445195 -203.505108 -147.156717 -49.324155
154.883574 -19.965314 124.324729 198.216477
2.886820 249.026500 86.737908 -232.027331
193.744106 9.469789 -108.706596 116.156123
224.583212 11.928862 -111.198585 199.679652
158.436164 -17.376616 4.233347 -154.343522
-16.274097 -246.655139 53.134941 219.045650
201.930360 18.198730 52.531427 188.860283
211.031319 13.971414 199.759825 142.236295
167.641503 2.279956 -153.335297 33.127230
240.821867 -1.488584 109.768908 -156.403842
15.075325 169.095356 191.522197 69.161770
-7.630298 196.102117 220.062526 70.577410
-16.364244 182.033073 41.550781 164.810963
235.854636 -0.618213 -48.473045 -144.188006
-3.898845 151.466209 -182.774442 -73.038390
11.772678 255.408435 -49.452259 -244.218394
14.850871 172.844069 -13.630715 162.124555
-18.121169 196.343427 39.864674 150.674710
-159.980078 -16.452435 -188.697044 -71.996776
-1.103776 223.906609 209.144759 -94.677939
-164.136493 2.665638 68.331180 -148.688378
-188.419881 11.708277 -152.071067 -16.616042
-168.416232 3.726386 27.734569 244.386576
-246.001750 26.159777 23.194074 224.207761
-162.864443 -16.413678 -121.424647 -99.335541
-185.432804 -17.595811 -81.004541 -144.285027
10.500652 172.253365 -54.705548 197.298754
-246.953352 -25.972959 -158.456711 185.805850
2.389557 169.349638 -195.595346 53.989574
11.802635 177.146925 155.441325 -30.768053
-150.628957 1.655484 131.351333 -190.332676
-21.620570 212.484655 151.633615 -144.272948
-174.943953 17.815758 -215.382455 100.160594
10.246061 250.882924 -16.877039 150.231786
-159.806539 11.576918 -244.040463 41.574689
-230.847475 -27.358011 -30.789249 -164.256939
-156.905847 -16.074234 243.535105 -70.333548
-232.901653 13.792754 -123.309534 -93.410730
-13.141665 -171.881205 141.183147 198.054222
17.978969 -168.541785 111.648590 -121.110859
10.998418 -163.890031 159.960839 119.300008
-226.053584 27.174607 152.093937 -56.629404
19.537432 -182.302590 117.736144 -192.205400
0.707694 -182.975442 -67.552365 143.397390
-25.737269 -245.385320 -144.829862 55.225338
-22.985682 -253.425572 137.854776 73.989149
107.712460 -220.424780
-72.295537 -188.604800
-157.285398 158.442411
18.084724 166.016643
-4.225048 204.566741
202.324807 -62.010358
-119.442761 208.986514
-116.518561 -106.891697
-52.721865 -192.322387
-124.217802 -133.451340
191.087537 -159.194411
127.328099 107.726608

View File

@ -5,7 +5,7 @@ name, elo
./bots/dumb4 1466 ./bots/dumb4 1466
./bots/dumb5 540 ./bots/dumb5 540
./bots/dumb6 562 ./bots/dumb6 562
./bots/follow1 616 ./bots/follow1 657
./bots/follow2 702 ./bots/follow2 726
./bots/follow3 641 ./bots/follow3 652
./bots/follow4 617 ./bots/follow4 671

View File

@ -1,9 +1,9 @@
5 9 5 9
31114.314 31714.314
S...035.0 S...035.6
.E..25..0 .E..25..0
.0..31115 .6..37115
.2115.... .2175....
$ $
. = NULL . = NULL

View File

@ -1,17 +1,17 @@
4 4
0 (1 2) (77.50 55.88) 0 (2 0) (33.61 47.56)
1 (1 2) (54.26 37.50) 1 (3 0) (11.28 52.68)
2 (1 2) (33.12 59.00) 2 (0 1) (84.28 14.94)
3 (1 3) (74.02 24.62) 3 (4 0) (50.30 85.67)
3 3
5 9 5 9
31114.314 31714.314
S...035.0 S...035.6
.E..25..0 .E..25..0
.0..31115 .6..37115
.2115.... .2175....
100 200 5 0.90 0.80 0.20 0.00 100 200 5 0.90 0.80 0.20 0.00 0.20
Room Size, Maximum speed, Player Radius, Friction, Restitution factor, Track Distance to Edge, Magnetic Field Room Size, Maximum speed, Player Radius, Friction, Restitution factor, Track Distance to Edge, Magnetic Field, Slow zone Width

View File

@ -91,6 +91,8 @@ int return_directions(road r) {
case END: return 15; case END: return 15;
case STR_V: return 5; case STR_V: return 5;
case STR_H: return 10; case STR_H: return 10;
case STR_VB: return 5;
case STR_HB: return 10;
case TURN_NE: return 3; case TURN_NE: return 3;
case TURN_SE: return 6; case TURN_SE: return 6;
case TURN_SW: return 12; case TURN_SW: return 12;

View File

@ -138,6 +138,27 @@ void move_on_STR_V(int nPl) {
} }
} }
double absf(double x) {return (x<0.0)?(-x):(x);}
void move_on_STR_VB(int nPl) {
car* c = players[nPl].c;
c->pos.fx += c->vel.fx*DT;
c->pos.fy += c->vel.fy*DT;
if(c->pos.fx-PLAYER_R <= ROOM_SIZE*DIST_EDGE && c->vel.fx < 0.0) { // left wall
c->vel.fx *= -1.0;
c->pos.fx += 2.0*c->vel.fx*DT;
c->vel.fx *= RESTITUTION_WALL;
}
if(c->pos.fx+PLAYER_R >= ROOM_SIZE*(1.0-DIST_EDGE) && c->vel.fx > 0.0) { // right wall
c->vel.fx *= -1.0;
c->pos.fx += 2.0*c->vel.fx*DT;
c->vel.fx *= RESTITUTION_WALL;
}
if(absf(c->pos.fx - 0.5*ROOM_SIZE) < ROOM_SIZE*STR2_W/2.0) { // middle area
apply_friction(nPl);
apply_friction(nPl);
}
}
void move_on_STR_H(int nPl) { void move_on_STR_H(int nPl) {
car* c = players[nPl].c; car* c = players[nPl].c;
c->pos.fx += c->vel.fx*DT; c->pos.fx += c->vel.fx*DT;
@ -154,6 +175,26 @@ void move_on_STR_H(int nPl) {
} }
} }
void move_on_STR_HB(int nPl) {
car* c = players[nPl].c;
c->pos.fx += c->vel.fx*DT;
c->pos.fy += c->vel.fy*DT;
if(c->pos.fy-PLAYER_R <= ROOM_SIZE*DIST_EDGE && c->vel.fy < 0.0) { // top wall
c->vel.fy *= -1.0;
c->pos.fy += 2.0*c->vel.fy*DT;
c->vel.fy *= RESTITUTION_WALL;
}
if(c->pos.fy+PLAYER_R >= ROOM_SIZE*(1.0-DIST_EDGE) && c->vel.fy > 0.0) { // bottom wall
c->vel.fy *= -1.0;
c->pos.fy += 2.0*c->vel.fy*DT;
c->vel.fy *= RESTITUTION_WALL;
}
if(absf(c->pos.fy - 0.5*ROOM_SIZE) < ROOM_SIZE*STR2_W/2.0) { // middle area
apply_friction(nPl);
apply_friction(nPl);
}
}
void move_on_TURN(int nPl, int cenX, int cenY) { void move_on_TURN(int nPl, int cenX, int cenY) {
car* c = players[nPl].c; car* c = players[nPl].c;
ptf prev = (ptf){.fx = c->pos.fx, .fy = c->pos.fy}; ptf prev = (ptf){.fx = c->pos.fx, .fy = c->pos.fy};
@ -332,6 +373,26 @@ bool updateCar(level* lvl, int nPl) {
updateChunk(lvl, nPl); updateChunk(lvl, nPl);
return true; return true;
case STR_VB:
addEnviroSpeed(nPl);
move_on_STR_VB(nPl);
removeEnviroSpeed(nPl);
bumpOtherCars(nPl);
apply_friction(nPl);
updateChunk(lvl, nPl);
return true;
case STR_HB:
addEnviroSpeed(nPl);
move_on_STR_HB(nPl);
removeEnviroSpeed(nPl);
bumpOtherCars(nPl);
apply_friction(nPl);
updateChunk(lvl, nPl);
return true;
case TURN_NE: case TURN_NE:
addEnviroSpeed(nPl); addEnviroSpeed(nPl);
move_on_TURN(nPl, ROOM_SIZE, 0); move_on_TURN(nPl, ROOM_SIZE, 0);

View File

@ -4,4 +4,6 @@
bool updateCars(level* lvl); bool updateCars(level* lvl);
void updateWins(int* ranks); void updateWins(int* ranks);
void apply_friction(int nPl);
#endif #endif

View File

@ -365,12 +365,18 @@ void drawQuarterCircleToRenderer(SDL_Renderer * renderer, int32_t centreX, int32
++y; ++y;
error += ty; error += ty;
ty += 2; ty += 2;
++y;
error += ty;
ty += 2;
} }
if(error > 0) { if(error > 0) {
--x; --x;
tx += 2; tx += 2;
error += (tx - diameter); error += (tx - diameter);
--x;
tx += 2;
error += (tx - diameter);
} }
} }
} }
@ -423,16 +429,36 @@ void renderStraights(SDL_Renderer* renderer, level* lvl, int cx, int cy, int ran
64, 64, 64, 255); 64, 64, 64, 255);
break; break;
case TURN_NE: case STR_VB:
placeRectToRenderer(renderer, (WIDTH-rsize)/2+rsize*y, (HEIGHT-rsize)/2+rsize*x, rsize, rsize, 0, 0, 0, 255);
placeRectToRenderer(renderer,
(WIDTH-rsize)/2+rsize*y+(int)(DIST_EDGE*rsize),
(HEIGHT-rsize)/2+rsize*x,
rsize-(int)(2*DIST_EDGE*rsize),
rsize,
64, 64, 64, 255);
placeRectToRenderer(renderer,
(WIDTH-rsize)/2+rsize*y+(int)((1.0-STR2_W)/2.0*rsize),
(HEIGHT-rsize)/2+rsize*x,
(int)(STR2_W*rsize),
rsize,
64, 0, 0, 255);
break; break;
case TURN_SE: case STR_HB:
break; placeRectToRenderer(renderer, (WIDTH-rsize)/2+rsize*y, (HEIGHT-rsize)/2+rsize*x, rsize, rsize, 0, 0, 0, 255);
placeRectToRenderer(renderer,
case TURN_SW: (WIDTH-rsize)/2+rsize*y,
break; (HEIGHT-rsize)/2+rsize*x+(int)(DIST_EDGE*rsize),
rsize,
case TURN_NW: rsize-(int)(2*DIST_EDGE*rsize),
64, 64, 64, 255);
placeRectToRenderer(renderer,
(WIDTH-rsize)/2+rsize*y,
(HEIGHT-rsize)/2+rsize*x+(int)((1.0-STR2_W)/2.0*rsize),
rsize,
(int)(STR2_W*rsize),
64, 0, 0, 255);
break; break;
default: default:

View File

@ -134,12 +134,12 @@ void parse_all_players(level* lvl, char** execs) {
int main(int argc, char** argv) { int main(int argc, char** argv) {
if(argc < 2) { if(argc < 2) {
fprintf(stderr, "usage : ./back <level_path> <P1 executable> <P2 executable> ...\n"); fprintf(stderr, "usage : ./back ?<-R> <level_path> <P1 executable> <P2 executable> ...\n");
exit(1); exit(1);
} }
int offsetP = 0; int offsetP = 0;
if(argv[2][0] == 'R' && argv[2][1] == 'E' && argv[2][2] == 'P' && argv[2][3] == '\0') { if(argv[1+offsetP][0] == '-' && argv[1+offsetP][1] == 'R' && argv[1+offsetP][2] == '\0') {
// replay mode // replay mode
noise = false; noise = false;
printf("---------------------------\n"); printf("---------------------------\n");
@ -192,7 +192,7 @@ int main(int argc, char** argv) {
init_music(); init_music();
// ---------------------------- // // ---------------------------- //
//stage_file("levels/stage.txt"); //stage_file("levels/stage.txt");
level* stage = parse_level(argv[1]); level* stage = parse_level(argv[1+offsetP]);
init_all(N_PLAYERS); init_all(N_PLAYERS);
printf("\n"); printf("\n");
path* pth = getPath(stage); path* pth = getPath(stage);
@ -304,5 +304,5 @@ TODO :
+ add hazards + add hazards
KNOWN ISSUES : KNOWN ISSUES :
- car can sometimes clip into walls (rare, seems turn-related) - /
*/ */

View File

@ -47,6 +47,8 @@ int read_int(FILE* ptr) {
3 = BottomRight (SE) 3 = BottomRight (SE)
4 = BottomLeft (SW) 4 = BottomLeft (SW)
5 = TopLeft (NW) 5 = TopLeft (NW)
6 = Vertical2
7 = Horizontal2
S = Start S = Start
E = End E = End
*/ */
@ -70,6 +72,10 @@ road get_type(char c) {
return TURN_SW; return TURN_SW;
case '5': case '5':
return TURN_NW; return TURN_NW;
case '6':
return STR_VB;
case '7':
return STR_HB;
default: default:
fprintf(stderr, "unrecognized character '%c' encountered in parsing", c); fprintf(stderr, "unrecognized character '%c' encountered in parsing", c);

View File

@ -33,6 +33,8 @@ const double DELTA_THETA = 7.0; // degrees
const double WIND_X = 0.0; const double WIND_X = 0.0;
const double WIND_Y = 0.0; const double WIND_Y = 0.0;
const double STR2_W = 0.2;
double B = 0.0; // 0.6 works fine double B = 0.0; // 0.6 works fine
// ------------------------------------------------------------------------------------------ // // ------------------------------------------------------------------------------------------ //
@ -68,8 +70,8 @@ void write_output(char* stream, level* lvl, int nPl) {
fprintf(ptr, "\n"); fprintf(ptr, "\n");
} }
fprintf(ptr, "\n"); fprintf(ptr, "\n");
fprintf(ptr, "%d %d %d %.2lf %.2lf %.2lf %.2lf\n", ROOM_SIZE, MAX_SPEED, PLAYER_R, FRICTION, RESTITUTION_WALL, DIST_EDGE, B); fprintf(ptr, "%d %d %d %.2lf %.2lf %.2lf %.2lf %.2lf\n", ROOM_SIZE, MAX_SPEED, PLAYER_R, FRICTION, RESTITUTION_WALL, DIST_EDGE, B, STR2_W);
fprintf(ptr, "\nRoom Size, Maximum speed, Player Radius, Friction, Restitution factor, Track Distance to Edge, Magnetic Field"); fprintf(ptr, "\nRoom Size, Maximum speed, Player Radius, Friction, Restitution factor, Track Distance to Edge, Magnetic Field, Slow zone Width");
fclose(ptr); fclose(ptr);
} }

View File

@ -43,7 +43,7 @@ typedef struct color_t {
} color; } color;
// one chunk // one chunk
typedef enum road_t {NONE, START, END, STR_V, STR_H, TURN_NE, TURN_SE, TURN_SW, TURN_NW} road; typedef enum road_t {NONE, START, END, STR_V, STR_H, TURN_NE, TURN_SE, TURN_SW, TURN_NW, STR_VB, STR_HB} road;
typedef struct level_t { typedef struct level_t {
int lines; int lines;
@ -87,6 +87,8 @@ extern const int HEIGHT;
extern const int ROOM_SIZE; extern const int ROOM_SIZE;
extern const int MAX_SPEED; extern const int MAX_SPEED;
extern const double STR2_W;
extern int START_CHX; extern int START_CHX;
extern int START_CHY; extern int START_CHY;
extern int FINISH_CHX; extern int FINISH_CHX;

View File

@ -5,7 +5,7 @@ name, elo
./bots/dumb4 1466 ./bots/dumb4 1466
./bots/dumb5 540 ./bots/dumb5 540
./bots/dumb6 562 ./bots/dumb6 562
./bots/follow1 616 ./bots/follow1 657
./bots/follow2 702 ./bots/follow2 726
./bots/follow3 641 ./bots/follow3 652
./bots/follow4 617 ./bots/follow4 671