added speed modifiers depending on placement

This commit is contained in:
Alexandre 2025-05-24 20:01:35 +02:00
parent d07f0fc126
commit 404f32a414
18 changed files with 138 additions and 34 deletions

View File

@ -11,7 +11,7 @@ testL: bin/back
bin/back levels/test.txt bots/dumb bots/dumb2 bots/dumb3 bots/dumb4 bots/dumb5 bots/dumb6
test: bin/back
bin/back levels/long.txt bots/dumb bots/dumb2 bots/dumb3 bots/dumb4
bin/back levels/test.txt bots/dumb bots/dumb2 bots/dumb3 bots/dumb4
ez: bin/back
bin/back levels/simple.txt bots/dumb bots/dumb2 bots/dumb3 bots/dumb4

View File

@ -1 +1 @@
18 68
202 90

BIN
bin/back

Binary file not shown.

View File

@ -1,8 +1,44 @@
16.118180 135.441519
15.256039 -174.406057
104.496250 -148.082488
191.197494 16.230970
-112.462982 -31.358173
119.618077 -121.687300
104.527851 139.009942
120.783208 54.245212
379.298997 -90.460396
-411.933782 -102.829478
529.790599 106.085366
199.425937 -339.933600
-95.896503 -427.381434
621.489630 -271.395621
-91.910447 -431.083935
532.790163 -251.126350
-441.742872 -379.482434
-156.873311 -631.713832
-401.488913 234.715098
105.077659 284.150054
524.564488 78.261213
276.789079 -499.510206
-381.421657 -316.021931
-523.227183 -149.848072
101.368066 -470.891248
-443.642759 -24.105970
-184.386517 489.797115
-240.105707 -570.235746
-243.737743 -542.014315
10.519746 -514.182691
-195.243675 -309.577683
332.009157 395.515767
-176.294945 -347.245183
175.812024 -404.875378
387.383699 270.406430
519.318908 3.851934
258.416467 -497.716698
383.335139 -130.461029
17.811949 406.832575
202.002036 -232.264703
-73.837280 619.550755
87.161172 -536.662133
-264.435947 -410.760055
488.070671 158.002418
488.103030 -214.321833
-571.397831 -78.964646
-404.666249 112.426128
577.348182 -253.487910
151.737589 322.901126
-394.690142 -402.872287
-145.130089 -320.154490
-493.847237 -180.188736

View File

@ -1,7 +1,7 @@
name, elo
./bots/dumb 1595
./bots/dumb2 1570
./bots/dumb3 1576
./bots/dumb4 1447
./bots/dumb 1405
./bots/dumb2 1504
./bots/dumb3 1487
./bots/dumb4 1392
./bots/dumb5 540
./bots/dumb6 562

View File

@ -1,6 +1,6 @@
7 8
........
..31S...
...S....
..35....
..24....
...24...
...353E.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,16 +1,18 @@
4
0 (0 1) (30.90 71.34)
1 (1 0) (5.60 61.29)
2 (0 1) (15.00 61.48)
3 (0 0) (70.64 69.26)
3
0 (3 0) (24.83 26.41)
1 (4 5) (73.32 64.02)
2 (3 4) (90.21 27.10)
3 (6 4) (41.16 68.33)
2
5 9
31114.314
S...035.0
.E..25..0
.0..31115
.2115....
7 8
...S....
..35....
..24....
...24...
...353E.
...215..
........
100 200 5 0.90 0.80 0.20

View File

@ -22,6 +22,10 @@ int nextRank;
int currentTurn;
int nPlayers;
carData* players;
double* remainingD;
double minRemD;
double maxRemD;
int RED = 0;
int GREEN = 0;
@ -58,11 +62,15 @@ void init_all(int nPl) {
remainingTurns = -1;
winners = malloc(sizeof(int)*nPlayers);
players = malloc(sizeof(carData)*nPlayers);
remainingD = malloc(sizeof(double)*nPlayers);
for(int p = 0; p < nPlayers; p++) {
winners[p] = 0;
players[p].rgb = assignColor();
remainingD[p] = 0.0;
players[p].c = init_car(p, nPlayers);
}
minRemD = 0.0;
maxRemD = 0.0;
}
void destroy_all() {
@ -315,6 +323,9 @@ double distance_pt(int x1, int x2, int y1, int y2) {
int max(int a, int b) {return (a>b)?(a):(b);}
int min(int a, int b) {return (a<b)?(a):(b);}
int mfax(double a, double b) {return (a>b)?(a):(b);}
int mfin(double a, double b) {return (a<b)?(a):(b);}
double norm(ptf p) {
return sqrt(p.fx*p.fx + p.fy*p.fy);
}

View File

@ -12,6 +12,8 @@ int pw(int x, int n);
double distance_pt(int x1, int x2, int y1, int y2);
int max(int a, int b);
int min(int a, int b);
int mfax(double a, double b);
int mfin(double a, double b);
double norm(ptf p);
double distance(ptf p1, ptf p2);

View File

@ -177,6 +177,19 @@ void move_on_TURN(int nPl, int cenX, int cenY) {
c->pos.fy += 2.0*c->vel.fy*DT;
}
// in case someone clips (inner)
if(nextDist-prevDist < 0.0 && prevDist-PLAYER_R < ROOM_SIZE*DIST_EDGE) {
ptf to_in = normalize((ptf){
.fx = cenX-prev.fx,
.fy = cenY-prev.fy
});
double inwards = dot(to_in, c->vel);
c->vel = add(c->vel, (ptf){.fx = -2.0*to_in.fx*inwards, .fy = -2.0*to_in.fy*inwards});
c->pos.fx += 2.0*c->vel.fx*DT;
c->pos.fy += 2.0*c->vel.fy*DT;
}
// outer circle
if(prevDist+PLAYER_R < ROOM_SIZE*(1.0-DIST_EDGE) && nextDist+PLAYER_R >= ROOM_SIZE*(1.0-DIST_EDGE)) {
ptf to_out = normalize((ptf){
@ -189,6 +202,19 @@ void move_on_TURN(int nPl, int cenX, int cenY) {
c->pos.fx += 2.0*c->vel.fx*DT;
c->pos.fy += 2.0*c->vel.fy*DT;
}
// in case someone clips (outer)
if(nextDist-prevDist > 0.0 && prevDist-PLAYER_R > ROOM_SIZE*(1.0-DIST_EDGE)) {
ptf to_in = normalize((ptf){
.fx = cenX-prev.fx,
.fy = cenY-prev.fy
});
double inwards = dot(to_in, c->vel);
c->vel = add(c->vel, (ptf){.fx = -2.0*to_in.fx*inwards, .fy = -2.0*to_in.fy*inwards});
c->pos.fx += 2.0*c->vel.fx*DT;
c->pos.fy += 2.0*c->vel.fy*DT;
}
}
void bumpOtherCars(int nPl) {

View File

@ -516,6 +516,9 @@ const int BAR_T = 3;
void renderProgress(SDL_Renderer* renderer, level* lvl, path* pth) {
for(int p = 0; p < nPlayers; p++) {
double remD = getTotalRemainingDistance(lvl, pth, p);
remainingD[p] = remD;
maxRemD = mfax(maxRemD, remD);
minRemD = mfin(minRemD, remD);
//printf("(%lf out of %lf rem)\n", remD, maxD);
placeRectToRenderer(renderer, 10, BAR_W/8+p*(BAR_W+BAR_W/8), WIDTH-20, BAR_W, players[p].rgb.red/2, players[p].rgb.green/2, players[p].rgb.blue/2, 255);
placeRectToRenderer(renderer, 10+BAR_T, BAR_W/8+p*(BAR_W+BAR_W/8)+BAR_T, WIDTH-20-2*BAR_T, BAR_W-2*BAR_T, 0, 0, 0, 255);

View File

@ -80,6 +80,18 @@ void cameraActions(level* lvl, bool* halt, int* cx, int* cy, int* dezoom, int* s
}
}
double playerSpeedModifier(int nPl) {
// gives players a speed boost/penalty depending on their position
// -12% if in the lead, and +12% if last
if(maxRemD-minRemD >= 0.0001) {
double theta = (remainingD[nPl]-minRemD)/(maxRemD-minRemD);
printf("%lf\n", theta);
return (1.0 + (24.0*theta-12.0)/100.0);
} else {
return 1.0;
}
}
void player_turn(int id, char* exec) {
if(noise) {
system(exec);
@ -89,9 +101,16 @@ void player_turn(int id, char* exec) {
fclose(ptr);
double dvx = 1.0+(rand()%200-100)/100.0*(DELTA_V/100.0);
double dvy = 1.0+(rand()%200-100)/100.0*(DELTA_V/100.0);
double psm = playerSpeedModifier(id);
double dtheta = (rand()%200-100)*DELTA_THETA/100.0;
set_speed_car(players[id].c, dvx*MAX_SPEED*(mult)/100.0*cos((angle+dtheta)*3.14159/180.0), dvy*MAX_SPEED*(mult)/100.0*sin((angle+dtheta)*3.14159/180.0));
fprintf(save, "%lf %lf\n", dvx*MAX_SPEED*(mult)/100.0*cos((angle+dtheta)*3.14159/180.0), dvy*MAX_SPEED*(mult)/100.0*sin((angle+dtheta)*3.14159/180.0));
set_speed_car(players[id].c,
psm*dvx*MAX_SPEED*(mult)/100.0*cos((angle+dtheta)*3.14159/180.0),
psm*dvy*MAX_SPEED*(mult)/100.0*sin((angle+dtheta)*3.14159/180.0)
);
fprintf(save, "%lf %lf\n",
psm*dvx*MAX_SPEED*(mult)/100.0*cos((angle+dtheta)*3.14159/180.0),
psm*dvy*MAX_SPEED*(mult)/100.0*sin((angle+dtheta)*3.14159/180.0)
);
} else {
double vx, vy;
fscanf(save, "%lf %lf", &vx, &vy);
@ -199,6 +218,8 @@ int main(int argc, char** argv) {
int count = 0;
while(!halt) {
resetRenderer(rend);
minRemD = 999999.0;
maxRemD = 0.0;
renderMap(rend, stage, pth, cx, cy, dezoom, sizeR, SHOW);
for(int p = 0; p < N_PLAYERS; p++) {
pt proj = project(p, cx, cy, dezoom, sizeR);
@ -262,7 +283,7 @@ int main(int argc, char** argv) {
free(execs[k]);
}
free(execs);
free(remainingD);
free(ranks);
SDL_DestroyRenderer(rend);

View File

@ -114,6 +114,9 @@ extern const double DELTA_THETA;
extern int* winners;
extern int nextRank;
extern int remainingTurns;
extern double* remainingD;
extern double minRemD;
extern double maxRemD;
// -------------------------------------------------------------------------------- //

View File

@ -1,7 +1,7 @@
name, elo
./bots/dumb 1595
./bots/dumb2 1570
./bots/dumb3 1576
./bots/dumb4 1447
./bots/dumb 1405
./bots/dumb2 1504
./bots/dumb3 1487
./bots/dumb4 1392
./bots/dumb5 540
./bots/dumb6 562