3 * http://royale.zerezo.com/zerace/
5 * Copyright (C) 2004 Antoine Jacquet <royale@zerezo.com>
8 * This robot uses the idea described on this page :
9 * http://rars.sourceforge.net/selection/felix.html
10 * Thanks to Doug Eleveld
20 void bot_ia(char *trackname,struct _car *car,SDL_Surface *fun,int *ku,int *kd,int *kl,int *kr)
22 int a1,a2,c,g,tg,og,l,x1,x2,x3,x4,y1,y2,y3,y4;
25 /* adjust the properties depending of the track, this was "manually" optimized ;) */
26 if (strcmp(trackname,"car")==0)
35 else if (strcmp(trackname,"first")==0)
44 else if (strcmp(trackname,"icy")==0)
53 else if (strcmp(trackname,"hairpins")==0)
62 else if (strcmp(trackname,"simple")==0)
71 else if (strcmp(trackname,"loop")==0)
80 /* some default values that may work on some tracks */
91 /* should we accelerate or brake ? */
92 c=getpixel(fun,car->x,car->y);
96 x1=car->x-cos(car->angle)*l*s;
97 y1=car->y-sin(car->angle)*l*s;
98 if (x1>0 && y1>0 && x1<fun->w && y1<fun->h) c=getpixel(fun,x1,y1); else c=0;
100 if (g<og && car->speed>m) { *ku=0,*kd=1; break; }
103 /* should we turn ? left or right ? */
108 x2=car->x-cos(car->angle)*l*s;
109 y2=car->y-sin(car->angle)*l*s;
110 x3=car->x-cos(car->angle-o)*l*s;
111 y3=car->y-sin(car->angle-o)*l*s;
112 x4=car->x-cos(car->angle+o)*l*s;
113 y4=car->y-sin(car->angle+o)*l*s;
115 if (x3>0 && y3>0 && x3<fun->w && y3<fun->h) c=getpixel(fun,x3,y3); else c=0;
117 if (x4>0 && y4>0 && x4<fun->w && y4<fun->h) c=getpixel(fun,x4,y4); else c=0;
119 if (g>tg) { *kr=1; break; } else if (g<tg) { *kl=1; break; }