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,l,x1,x2,x3,x4,y1,y2,y3,y4;
27 /* adjust the properties depending of the track, this was "manually" optimized ;) */
28 if (strcmp(trackname,"car")==0)
37 else if (strcmp(trackname,"first")==0)
46 else if (strcmp(trackname,"icy")==0)
55 else if (strcmp(trackname,"hairpins")==0)
64 else if (strcmp(trackname,"simple")==0)
73 else if (strcmp(trackname,"loop")==0)
82 else if (strcmp(trackname,"formula")==0)
91 /* some default values that may work on some tracks */
102 /* should we accelerate or brake ? */
103 c=getpixel(fun,car->x,car->y);
107 x1=car->x-cos(car->angle)*l*s;
108 y1=car->y-sin(car->angle)*l*s;
109 if (x1>0 && y1>0 && x1<fun->w && y1<fun->h) c=getpixel(fun,x1,y1); else c=SDL_MapRGB(fun->format,0,0,0);
110 SDL_GetRGB(c,fun->format,&t,&g,&t);
111 if (g<og && car->speed>m) { *ku=0,*kd=1; break; }
114 /* should we turn ? left or right ? */
119 x2=car->x-cos(car->angle)*l*s;
120 y2=car->y-sin(car->angle)*l*s;
121 x3=car->x-cos(car->angle-o)*l*s;
122 y3=car->y-sin(car->angle-o)*l*s;
123 x4=car->x-cos(car->angle+o)*l*s;
124 y4=car->y-sin(car->angle+o)*l*s;
126 if (x3>0 && y3>0 && x3<fun->w && y3<fun->h) c=getpixel(fun,x3,y3); else c=SDL_MapRGB(fun->format,0,0,0);
127 SDL_GetRGB(c,fun->format,&t,&tg,&t);
128 if (x4>0 && y4>0 && x4<fun->w && y4<fun->h) c=getpixel(fun,x4,y4); else c=SDL_MapRGB(fun->format,0,0,0);
129 SDL_GetRGB(c,fun->format,&t,&g,&t);
130 if (g>tg) { *kr=1; break; } else if (g<tg) { *kl=1; break; }