2013/pjanic.r

001/****************************************************************************/
002/*                                                                          */
003/*  Torneo di CRobots (2013)                                                */
004/*                                                                          */
005/*  CROBOT: pjanic.r                                                        */
006/*                                                                          */
007/*  CATEGORIA: 2000 istruzioni                                              */
008/*                                                                          */
009/*  AUTORE: Daniele Nuzzo                                                   */
010/*                                                                          */
011/****************************************************************************/
012 
013/*
014 
015SCHEDA TECNICA:
016 
017  Rimando draka, solo per avere il 4 robot, non ho proprio fatto in tempo a fare altro ... 
018   
019*/
020/*********************/
021/* Variabili globali */
022/*********************/
023 
024int deg,rng,dir,odeg,orng,b,x,y,en,yHigh,xHigh,xLim,yLim,xOut,yOut,zOut,timer,timer2,dmin,dmax,t,xd,yd,zd,wd,welcome,dam;
025 
026main()
027{
028    /* Conta gli avversari */
029    while (deg<360)
030        if (scan(deg+=20,10)) {
031            en+=1;
032            if (!welcome) {
033                cannon(deg,scan(deg,10));
034                welcome=1;
035            }
036        }
037     
038    /* Se f2f o scontro a 3 usa le tattiche specifiche */
039    if (en==1) f2f();
040    else if (en==2) {
041        en=0;
042        while (deg) if (scan(deg-=20,10)) ++en;
043        if (en==2) vs2();
044    }
045     
046         
047    /* Vai nell'angolo */
048    if (yHigh=(loc_y()>500)) {
049        while (loc_y()<880) fuoco(90,100);
050        drive(90,0);
051    } else {
052        while (loc_y()>120) fuoco(270,100);    
053        drive(270,0);
054    }
055    if (xHigh=(loc_x()>500)) {
056        while (loc_x()<880) fuoco(0,100);      
057        drive(0,0);
058    } else {
059        while (loc_x()>120) fuoco(180,100);
060        drive(180,0);
061    }
062         
063    /* Calcola i parametri utilizzati nell'angolo */
064    yLim=60+yHigh*880;
065    xLim=60+xHigh*880;
066    xOut=180*xHigh;
067    dmax=(dmin=zOut=((yOut=90+180*yHigh)-105+90*(xHigh^yHigh)))+100;
068 
069    /* Oscilla */
070    while(en>1) {
071        run(xOut,xLim,2-xHigh);
072        run(yOut,yLim,6-yHigh);
073    }
074             
075    f2f();
076     
077}
078 
079/*********************/
080/* Routine di fuoco  */
081/*********************/
082 
083fire()
084{
085    if ((orng=scan(odeg=deg,10))) {
086        if (scan(deg-8,5)) {   
087            if (scan(deg-=5,2)) ;
088            else deg-=4;
089        } else {
090            if (scan(deg+8,5)) {
091                if (scan(deg+=5,2)) ;
092                else deg+=4;
093            } else {
094                if (scan(deg,1)) ;
095                else if (scan(deg-=3,2)) ; else deg+=6;
096            }
097        }
098        return cannon(deg+deg-odeg,scan(deg,10));
099    } else {
100        if (orng=scan(deg+=340,10)) return cannon(deg,2*scan(deg,10)-orng);
101        if (orng=scan(deg+=40,10)) return cannon(deg,2*scan(deg,10)-orng);
102        if (scan(deg+=300,10)) return cannon(deg,scan(deg,10));
103        if (scan(deg+=80,10)) return cannon(deg,scan(deg,10));
104        if (en>1)
105            if(scan(dir,10))
106                return deg=dir;
107        deg+=60;
108    }
109}
110 
111fuoco(dir,v)
112{
113    drive(dir,v);
114    if (rng=scan(odeg=deg,10)) {
115        if (scan(deg-8,5))  { if (scan(deg-=5,2)) ; else deg-=4; return(cannon(deg+(deg-odeg),2*scan(deg,10)-rng)); }
116        if (scan(deg+8,5))  { if (scan(deg+=5,2)) ; else deg+=4; return(cannon(deg+(deg-odeg),2*scan(deg,10)-rng)); }
117        if (scan(deg,10))   { if (scan(deg-=2,2)) ; else deg+=4; return(cannon(deg+(deg-odeg),2*scan(deg,10)-rng)); }
118    }
119    else if(scan(deg+=20,10));
120    else if(scan(deg-=40,10));
121    else if(scan(dir,10)) deg=dir;
122    else deg+=77;
123}
124 
125/***********************************/
126/* Routines utilizzate nell'angolo */
127/***********************************/
128 
129run(d,l,m) {
130 
131    int r;
132 
133    /* Conta gli avversari */
134    if (timer%12==2) {
135        en=0;
136        while (dmin<=dmax) en+=(scan(dmin+=20,10)>0);
137        dmin=zOut;
138        if (en==2)
139            vs2();
140         
141        if (timer>400)
142            if (en==3)
143                if (damage()<40)
144                    { vs3(); f2f(); }
145    }
146 
147    /* Esegue i 2 movimenti della oscillazione */  
148    while(++r<3) {
149     
150        drive(d,100);
151         
152        if (++timer>550) en=1;
153        if (scan(d,10)) {  while (scan(deg=d,10)>840) ; } else while(check(l,m)) ;
154        fire(drive(d,0)); 
155        while(speed()>59) ;
156        ++m; 
157        d+=180;
158    }
159}
160 
161check(l,m) {
162    /* Verifica la vicinanza al perimetro di gioco */
163    int c1;
164    if (m<5) c1=loc_x(); else c1=loc_y();
165    if (m%2) return (c1>l); else return (c1<l);
166}  
167 
168/* Attacco in f2f */
169f2f() {
170    while(1) {         
171        if ((x=loc_x(y=loc_y()))>880) dir=160+40*(y>500);
172        else if (x<120) dir=340+40*(y<500);
173        else if ((y)>880) dir=250+40*(x<500);
174        else if (y<120) dir=70+40*(x>500);                       
175 
176        else if (orng>600) dir=deg+25+(b^=1)*235;
177        else if (orng<150) dir=deg+170+(b^=1)*25;
178        else dir=deg+180*(b^=1);
179         
180        drive(dir,100);    
181        fire();
182        drive(dir,100);    
183        fire();
184        fire();
185        drive(dir,100);    
186                     
187        drive(dir,60);
188    }
189}
190 
191/* Attacco contro 2 avversari */
192vs2() {
193    while(1) {
194        while (loc_x()<930) fuoco(0,100);
195        fuoco(90,0);
196        while (loc_y()<930) fuoco(90,100);
197        fuoco(180,0);
198        while (loc_x()>70) fuoco(180,100);
199        fuoco(270,0);
200        while (loc_y()>70) fuoco(270,100);
201        fuoco(0,0);
202    }
203}
204 
205/* Attacco contro 3 avversari */
206vs3() {
207 
208    if (xHigh) {
209        if (yHigh) {
210            xd=135; yd=315; zd=225;
211        } else {
212            xd=225; yd=45; zd=135;
213        }
214    } else {
215        if (yHigh) {
216            xd=45; yd=225; zd=315;
217        } else {
218            xd=315; yd=135; zd=45;
219        }
220    }  
221    wd=zd+180;
222     
223    dam=damage()+40;
224     
225    while(damage()<dam) {
226         
227        deg=xd;
228        if (xHigh) {
229            while (loc_x()>550) fuoco(180,100);
230            drive(180,0);
231            while (loc_x()<600) fuoco(0,100);
232            drive(0,0);
233        } else {
234            while (loc_x()<450) fuoco(0,100);
235            drive (0,0);
236            while (loc_x()>400) fuoco(180,100);
237            drive (180,0);
238        }
239         
240        deg=yd;
241        if (yHigh) {
242            while (loc_y()>550) fuoco(270,100);
243            drive(270,0);
244            while (loc_y()<600) fuoco(90,100);
245            drive(90,0);
246        } else {
247            while (loc_y()<450) fuoco(90,100);
248            drive (90,0);
249            while (loc_y()>400) fuoco(270,100);
250            drive (270,0);
251        }
252         
253        while (scan(wd,10)) {
254            deg=wd;
255            if (yHigh) {
256                while (loc_y()<650) fuoco(wd,100);
257                drive (wd,0);
258                while (loc_y()>600) fuoco(zd,100);
259                drive (zd,0);
260            } else {
261                while (loc_y()>450) fuoco(wd,100);
262                drive(wd,0);
263                while (loc_y()<400) fuoco(zd,100);
264                drive(zd,0);
265            }      
266        }
267 
268        deg=zd;
269        if (yHigh) {
270            while (loc_y()>500) fuoco(zd,100);
271            drive(zd,0);
272            while (loc_y()<600) fuoco(wd,100);
273            drive(wd,0);
274        } else {
275            while (loc_y()<500) fuoco(zd,100);
276            drive (zd,0);
277            while (loc_y()>400) fuoco(wd,100);
278            drive (wd,0);
279        }      
280     
281    }
282 
283}