X-Git-Url: http://royale.zerezo.com/git/?p=zeRace;a=blobdiff_plain;f=bot_anticip.c;fp=bot_anticip.c;h=22de8dde0e6a79a197172d9e994ab61a5e531c87;hp=0000000000000000000000000000000000000000;hb=ee6ec6d95d78f74973a2ba97077cc94709bb6c61;hpb=dde2df6289f6daf23ee1632560c4c89061ef2f4a diff --git a/bot_anticip.c b/bot_anticip.c new file mode 100644 index 0000000..22de8dd --- /dev/null +++ b/bot_anticip.c @@ -0,0 +1,121 @@ +/* + * zeRace "anticip" bot + * http://royale.zerezo.com/zerace/ + * + * Copyright (C) 2004 Antoine Jacquet + * Licensed under GPL + * + * This robot uses the idea described on this page : + * http://rars.sourceforge.net/selection/felix.html + * Thanks to Doug Eleveld + */ + +#include "bot.h" + +char *bot_name() +{ + return "Anticip"; +} + +void bot_ia(char *trackname,struct _car *car,SDL_Surface *fun,int *ku,int *kd,int *kl,int *kr) +{ + int a1,a2,c,g,tg,og,l,x1,x2,x3,x4,y1,y2,y3,y4; + float o,m,s; + + /* adjust the properties depending of the track, this was "manually" optimized ;) */ + if (strcmp(trackname,"car")==0) + { + a1=190; + a2=180; + o=0.1; + m=0.1; + s=car->speed/3.3+0.4; + og=130; + } + else if (strcmp(trackname,"first")==0) + { + a1=240; + a2=230; + o=0.1; + m=0.1; + s=car->speed/3.3+0.3; + og=120; + } + else if (strcmp(trackname,"icy")==0) + { + a1=250; + a2=240; + o=0.3; + m=0.1; + s=car->speed/3.3+0.3; + og=120; + } + else if (strcmp(trackname,"hairpins")==0) + { + a1=220; + a2=210; + o=0.6; + m=0.1; + s=car->speed/3.3+0.4; + og=120; + } + else if (strcmp(trackname,"simple")==0) + { + a1=190; + a2=180; + o=0.2; + m=0.1; + s=car->speed/3.3+0.4; + og=1; + } + else if (strcmp(trackname,"loop")==0) + { + a1=150; + a2=90; + o=0.8; + m=0.1; + s=car->speed/3.3+0.4; + og=1; + } + /* some default values that may work on some tracks */ + else + { + a1=190; + a2=180; + o=0.2; + m=0.1; + s=car->speed/3.3+0.4; + og=1; + } + + /* should we accelerate or brake ? */ + c=getpixel(fun,car->x,car->y); + *ku=1,*kd=0; + for (l=0;lx-cos(car->angle)*l*s; + y1=car->y-sin(car->angle)*l*s; + if (x1>0 && y1>0 && x1w && y1h) c=getpixel(fun,x1,y1); else c=0; + g=(c>>GSHIFT)&0xff; + if (gspeed>m) { *ku=0,*kd=1; break; } + } + + /* should we turn ? left or right ? */ + *kl=0; + *kr=0; + for (l=0;lx-cos(car->angle)*l*s; + y2=car->y-sin(car->angle)*l*s; + x3=car->x-cos(car->angle-o)*l*s; + y3=car->y-sin(car->angle-o)*l*s; + x4=car->x-cos(car->angle+o)*l*s; + y4=car->y-sin(car->angle+o)*l*s; + + if (x3>0 && y3>0 && x3w && y3h) c=getpixel(fun,x3,y3); else c=0; + tg=(c>>GSHIFT)&0xff; + if (x4>0 && y4>0 && x4w && y4h) c=getpixel(fun,x4,y4); else c=0; + g=(c>>GSHIFT)&0xff; + if (g>tg) { *kr=1; break; } else if (g