1994/anglek2.r

001/* By Klausoft-Caserta. a nice robot anti-robocop2*/
002int corner;
003int c1x, c1y;
004int s1;
005int sc;
006int a,b,d,min;
007int dist,old;
008int ran;
009 
010main()
011{
012  int ang;
013  c1x = 996;  c1y = 4;  s1 = 0;
014  new_point();
015  ran = 270;
016  a=186; b=90;
017  while (1) {
018   while (ran < a) {
019     while ((dist=scan(ran,2)) && (dist < 700 && dist > 30)) {
020       if (old <= dist) {
021       cannon(ran,15*dist/14);
022       old=dist;
023      } else {
024        cannon(ran,7*dist/8);
025        old=dist;
026      }
027      ran -= 4;
028      if (damage() > 80 && s1 < 2) {
029       c1x = 4; c1y = 996; s1 = 3;
030       new_point();
031       ran=90; a=360; b=264;
032      }
033     }
034      ran += 4;
035   }
036   ran=b;
037  }
038}
039 
040/*Tutto il resto � preso dagli esempi : Sniper.r*/
041 
042new_point() {
043  int x, y;
044  int angle;
045  int new;
046    x = c1x;
047    y = c1y;
048    sc = s1;
049 
050  angle = plot_course(x,y);
051 
052  drive(angle,100);
053 
054  while (distance(loc_x(),loc_y(),x,y) > 100 && speed() > 0) {
055      if (dist=scan(ran,3))
056       cannon(ran,dist);
057      else {
058       ran -= 23;
059       if (!(dist=scan(ran,10)))
060        ran += 40;
061       else
062        cannon(ran,dist);
063      }
064  }
065  drive(angle,15);
066  while (distance(loc_x(),loc_y(),x,y) > 10 && speed() > 0)
067    ;
068 
069  drive(angle,0);
070}
071 
072 
073distance(x1,y1,x2,y2)
074int x1;
075int y1;
076int x2;
077int y2;
078{
079  int x, y;
080 
081  x = x1 - x2;
082  y = y1 - y2;
083  d = sqrt((x*x) + (y*y));
084  return(d);
085}
086 
087 
088plot_course(xx,yy)
089int xx, yy;
090{
091  int d;
092  int x,y;
093  int scale;
094  int curx, cury;
095 
096  scale = 100000; 
097  curx = loc_x(); 
098  cury = loc_y();
099  x = curx - xx;
100  y = cury - yy;
101 
102  if (x == 0) {   
103    if (yy > cury)
104      d = 90;        /* north */
105    else
106      d = 270;       /* south */
107  } else {
108    if (yy < cury) {
109      if (xx > curx)
110        d = 360 + atan((scale * y) / x);  /* south-east, quadrant 4 */
111      else
112        d = 180 + atan((scale * y) / x);  /* south-west, quadrant 3 */
113    } else {
114      if (xx > curx)
115        d = atan((scale * y) / x);        /* north-east, quadrant 1 */
116      else
117        d = 180 + atan((scale * y) / x);  /* north-west, quadrant 2 */
118    }
119  }
120  return (d);
121}
122 
123