diff --git a/Makefile b/Makefile index b3af131..32daa54 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/answer.txt b/answer.txt index f70f636..0597bd9 100644 --- a/answer.txt +++ b/answer.txt @@ -1 +1 @@ -18 68 \ No newline at end of file +202 90 \ No newline at end of file diff --git a/bin/back b/bin/back index 6c1b621..9cec4cc 100755 Binary files a/bin/back and b/bin/back differ diff --git a/lastActions.txt b/lastActions.txt index f324091..a11feb3 100644 --- a/lastActions.txt +++ b/lastActions.txt @@ -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 diff --git a/leaderboard.txt b/leaderboard.txt index f3acaec..2ca8818 100644 --- a/leaderboard.txt +++ b/leaderboard.txt @@ -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 diff --git a/levels/turning.txt b/levels/turning.txt index 5f4747f..4f59bc0 100644 --- a/levels/turning.txt +++ b/levels/turning.txt @@ -1,6 +1,6 @@ 7 8 -........ -..31S... +...S.... +..35.... ..24.... ...24... ...353E. diff --git a/obj/base.o b/obj/base.o index a7b37aa..9afc501 100644 Binary files a/obj/base.o and b/obj/base.o differ diff --git a/obj/collisions.o b/obj/collisions.o index 9f170b4..c3d6c88 100644 Binary files a/obj/collisions.o and b/obj/collisions.o differ diff --git a/obj/display.o b/obj/display.o index 5a2ca59..66c2eda 100644 Binary files a/obj/display.o and b/obj/display.o differ diff --git a/obj/main.o b/obj/main.o index bac39e1..67afc45 100644 Binary files a/obj/main.o and b/obj/main.o differ diff --git a/output.txt b/output.txt index 2c08767..a53ea53 100644 --- a/output.txt +++ b/output.txt @@ -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 diff --git a/src/base.c b/src/base.c index 3c9e350..95bdb6a 100644 --- a/src/base.c +++ b/src/base.c @@ -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 (ab)?(a):(b);} +int mfin(double a, double b) {return (apos.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) { diff --git a/src/display.c b/src/display.c index 72d8e2d..16bf637 100644 --- a/src/display.c +++ b/src/display.c @@ -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); diff --git a/src/main.c b/src/main.c index 4a495a1..605fd7f 100644 --- a/src/main.c +++ b/src/main.c @@ -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); diff --git a/src/structure.h b/src/structure.h index e99e9de..eccabbe 100644 --- a/src/structure.h +++ b/src/structure.h @@ -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; // -------------------------------------------------------------------------------- // diff --git a/tempLeader.txt b/tempLeader.txt index f3acaec..2ca8818 100644 --- a/tempLeader.txt +++ b/tempLeader.txt @@ -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