1994/deluxe_4.r

001/*********************************************************************/
002/*                                                                   */
003/*      Nome robot:     DELUXE_4                                     */
004/*      Autore:         GIANNI PERUGINI                              */
005/*                                                                   */
006/*********************************************************************/
007 
008int ang,range,x,y,oldx,oldy,newx,newy,locx,locy,olx,oly,alg,oldr;
009main()
010{
011    int dam1,dam2;
012    ang=1000000;
013    alg=0;
014    goto(0,0);
015    goto(500,1000);
016    goto(1000,0);
017    goto(0,500);
018    goto(1000,1000);
019    dam1=test1();
020    dam2=test2();
021    if(dam1<=dam2)
022        alg=0;
023    while(1)
024    {
025        goto(0,0);
026        goto(500,1000);
027        goto(1000,0);
028        goto(0,500);
029        goto(1000,1000);
030        goto(500,0);
031        goto(0,1000);
032        goto(1000,500);
033    }
034}
035 
036test1()
037{
038    int d;
039    alg=0;
040    d=damage();
041    goto(500,0);
042    goto(0,1000);
043    goto(1000,500);
044    return(damage()-d);
045}
046 
047test2()
048{
049    int d;
050    alg=1;
051    d=damage();
052    goto(500,250);
053    return(damage()-d);
054}
055 
056goto(x,y)
057int x,y;
058{
059    int dir,vel;
060    vel=100-80*alg;
061    dir=arctan(x-loc_x(),y-loc_y());
062    drive(dir,0);
063    drive(dir,vel); 
064    if(alg)
065    {
066        while( ((x-loc_x())*(x-loc_x())+(y-loc_y())*(y-loc_y()))>20000 )
067            spara2();
068        drive(dir,0);      
069    }
070    else
071    {
072        while( ((x-loc_x())*(x-loc_x())+(y-loc_y())*(y-loc_y()))>20000 )
073            spara1();
074        drive(dir,0);      
075        while(speed()>49)  
076            spara1();   
077    }
078}
079 
080spara1()
081{
082    ang+=324;
083    while(!(range=scan(ang,10)))  
084        ang+=18;
085    cannon(ang,7*range/(8-2*(oldr<range)));     
086    oldr=range;
087}
088 
089 
090spara2()
091{
092    ang+=328;
093    olx=locx;
094    oly=locy;
095    while(!(range=scan(ang,8)))
096        ang+=15;
097    ang+=4-8*(scan(ang-4,4)!=0);   
098    ang+=2-4*(scan(ang-2,2)!=0);   
099    locx=loc_x();
100    locy=loc_y();
101    oldx=x;
102    oldy=y;
103    x=range*cos(ang)/100000;
104    y=range*sin(ang)/100000;
105    newx=range*(x+locx-oldx-olx)/1200+1250*(x-oldx)/1200+x;
106    newy=range*(y+locy-oldy-oly)/1200+1250*(y-oldy)/1200+y;
107    cannon(arctan(newx,newy),sqrt(newx*newx+newy*newy));
108}
109 
110arctan(x,y)
111int x, y;
112{
113    int d;
114    if(x==0)
115    {
116        if(y>0)
117            d=90;
118        else
119            d=270;
120    }
121    else
122    {
123        if (y < 0)
124        {
125            if (x>0)
126                d=360+atan(100000*y/x);
127            else
128                d=180+atan(100000*y/x);
129        }
130        else
131        {
132            if(x>0)
133                d=atan(100000*y/x);
134            else
135                d=180+atan(100000*y/x);
136        }
137    }
138    return(d);
139}