1992/et_4.r
001 | /**************************************************************************/ |
002 | /* Robot Name : ET_4 */ |
003 | /* Author Name : Luigi Morelli */ |
004 | /* */ |
005 | /* TATTICA : */ |
006 | /* Il robot percorre un circuito triangolare, evitando gli angoli ed */ |
007 | /* il centro dell'arena. Va il piu' velocemente possibile senza */ |
008 | /* urtare le pareti. La routine di sparo cerca di centrare il bersaglio */ |
009 | /* presupponendo che questo si trovi entro 80 gradi dall'ultima */ |
010 | /* posizione. In ciascun vertice del triangolo, qualora il bersaglio */ |
011 | /* sia perso, viene controllato il centro del campo cercando di */ |
012 | /* massimizzare la ricerca nel minor tempo possibile. */ |
013 | /**************************************************************************/ |
014 |
015 | int dir, ang, dist; |
016 |
017 | main() |
018 |
019 | { |
020 | if (!((loc_x() > 600) && (loc_y() < 600))) { |
021 | dir = plot_course (950, 200); |
022 | ang = dir; |
023 | while ((loc_x() < 900) && (loc_y() > 250)) /* vai a casa... */ |
024 | shoot (100); /*...sparando */ |
025 | drive (dir, 40); /* Rallenta */ |
026 | while (speed > 40) /* continuando a sparare |
027 | */ |
028 | shoot (40); |
029 | } |
030 |
031 | while (1) { |
032 |
033 |
034 | /* Primo lato del triangolo */ |
035 |
036 | dir = plot_course (50, 300); /* prossima destinazione */ |
037 | if (dist == 0) /* Nessuno in vista? */ |
038 | ang = dir; /* Avanti! */ |
039 | while (loc_x() > 170) /* Controlla l'arrivo */ |
040 | shoot (100); /* sparando al massimo */ |
041 | drive (dir, 40); /* Sei vicino, rallenta! */ |
042 | if (dist == 0) /* Se non ci sono nemici in vista */ |
043 | ang = dir; /* Aggiusta la direzione */ |
044 | while (speed > 40) |
045 | shoot (40); /* Controlla mentre rallenta */ |
046 |
047 |
048 | /* Secondo lato del triangolo */ |
049 |
050 |
051 | dir = plot_course (650, 950); /* prossima destinazione */ |
052 | if (dist == 0) /* Nessuno in vista? */ |
053 | ang = dir; /* Avanti! */ |
054 | while (loc_y() < 890) /* Controlla l'arrivo */ |
055 | shoot (100); /* sparando al massimo */ |
056 | drive (dir, 40); /* Sei vicino, rallenta! */ |
057 | if (dist == 0) /* Se non ci sono nemici in vista */ |
058 | ang = dir; /* Aggiusta la direzione */ |
059 | while (speed > 40) |
060 | shoot (40); /* Controlla mentre rallenta */ |
061 |
062 |
063 | /* Terzo lato del triangolo */ |
064 |
065 |
066 | dir = plot_course (950, 200); /* prossima destinazione */ |
067 | if (dist == 0) /* Nessuno in vista? */ |
068 | ang = dir; /* Avanti! */ |
069 | while (loc_y() > 270) /* Controlla l'arrivo */ |
070 | shoot (100); /* sparando al massimo */ |
071 | drive (dir, 40); /* Sei vicino, rallenta! */ |
072 | if (dist == 0) /* Se non ci sono nemici in vista */ |
073 | ang = dir; /* Aggiusta la direzione */ |
074 | while (speed > 40) |
075 | shoot (40); /* Controlla mentre rallenta */ |
076 | } |
077 | } |
078 |
079 |
080 |
081 | /* plot course function, return degree heading to */ |
082 | /* reach destination x, y; uses atan() trig function */ |
083 |
084 | plot_course(xx, yy) |
085 | int xx, yy; |
086 | { |
087 | int d; |
088 | int x, y; |
089 | int scale; |
090 | int curx, cury; |
091 |
092 | scale = 100000; /* scale for trig functions */ |
093 | curx = loc_x(); /* get current location */ |
094 | cury = loc_y(); |
095 | x = curx - xx; |
096 | y = cury - yy; |
097 |
098 | /* atan only returns -90 to +90, so figure out how to use */ |
099 | /* the atan() value */ |
100 |
101 | if (x == 0) { /* x is zero, we either move due north or south */ |
102 | if (yy > cury) |
103 | d = 90; /* north */ |
104 | else |
105 | d = 270; /* south */ |
106 | } else { |
107 | if (yy < cury) { |
108 | if (xx > curx) |
109 | d = 360 + atan ((scale * y) / x); /* south-east, quadrant 4 */ |
110 | else |
111 | d = 180 + atan ((scale * y) / x); /* south-west, quadrant 3 */ |
112 | } else { |
113 | if (xx > curx) |
114 | d = atan ((scale * y) / x); /* north-east, quadrant 1 */ |
115 | else |
116 | d = 180 + atan ((scale * y) / x); /* north-west, quadrant 2 */ |
117 | } |
118 | } |
119 | return (d); |
120 | } |
121 |
122 |
123 | /* Funzione che spazza un'area di ricerca ampia 120 gradi; se nulla */ |
124 | /* e' a tiro continua la scansione, altrimenti spara 2 volte */ |
125 |
126 | shoot (spd) |
127 | int spd; |
128 | { |
129 | drive (dir, spd); |
130 | dist = scan (ang, 10); |
131 | if (dist > 39) { |
132 | cannon (ang + 3, dist); |
133 | cannon (ang - 3, dist); |
134 | } else |
135 | { |
136 | ang += 20; |
137 | if (scan (ang, 10) == 0) { |
138 | ang -= 40; |
139 | if (scan (ang, 10) == 0) { |
140 | ang += 60; |
141 | if (scan (ang, 10) == 0) |
142 | while (scan (ang, 10) = 0) |
143 | ang -= 20; |
144 | } |
145 | } |
146 | dist = scan (ang, 10); |
147 | if (dist > 39) { |
148 | cannon (ang - 3, dist); |
149 | cannon (ang + 3, dist); |
150 | } |
151 | } |
152 | } |