1991/jazz.r

01/**********************************************************************
02 *  == Jazz ==  CRobot by Giuseppe Menozzi (Wheeling Pitch) 10/9/91.  *
03 *              Questo semplice CRobot corre sulla diagonale princi-  *
04 *              pale, sparando con poca precisione. Aiuta in maniera  *
05 *              sorprendente il tiro usando un Range leggerissima-    *
06 *              mente piu' corto di quello fornito da scan().         *
07 **********************************************************************/
08 
09 
10int Dir, Range, DirR;
11 
12main()
13{
14    DirR = xy2dir (100, 100);
15 
16    while (1) {
17        drive (DirR, 100);
18        while (loc_x() > 90 && speed()) {
19            if (Range = scan (Dir, 3))
20                cannon (Dir, 7 * Range / 8);
21            else
22             {
23                Dir -= 23;
24                while (!(Range = scan (Dir, 10)))
25                    Dir += 20;
26                if (Range < 60)
27                    Range = 60;
28                cannon (Dir, 7 * Range / 8);
29            };
30        };
31        DirR = xy2dir (899, 899);
32        while (speed() > 50)
33            drive (DirR, 50);
34 
35        drive (DirR, 100);
36        while (loc_x() < 910 && speed()) {
37            if (Range = scan (Dir, 3))
38                cannon (Dir, 7 * Range / 8);
39            else
40             {
41                Dir -= 23;
42                while (!(Range = scan (Dir, 10)))
43                    Dir += 20;
44                if (Range < 60)
45                    Range = 60;
46                cannon (Dir, 7 * Range / 8);
47            };
48        };
49        DirR = xy2dir (100, 100);
50        while (speed() > 50)
51            drive (DirR, 50);
52    };
53}
54 
55 
56xy2dir (x, y)
57int x, y;
58{
59    int d, locx, locy;
60 
61    locx = loc_x();
62    locy = loc_y();
63 
64    if (locx == x) {
65        if (y > locy)
66            d = 90;
67        else
68            d = 270;
69    } else
70     {
71        if (y < locy) {
72            if (x > locx)
73                d = 360 + atan ((100000 * (locy - y)) / (locx - x) );
74            else
75                d = 180 + atan ((100000 * (locy - y)) / (locx - x) );
76        } else if (x > locx)
77            d = atan ((100000 * (locy - y)) / (locx - x) );
78        else
79            d = 180 + atan ((100000 * (locy - y)) / (locx - x) );
80    };
81    return (d);
82}