1995/saxy.r
001 | /* |
002 |
003 | IL programma realizzato da Dinardo Saverio |
004 | effettua principalmente un'operazione di scan sfruttando come |
005 | tecnica di mira una tecnica di restringimento del cono di |
006 | scan attraverso successive approssimazioni; |
007 | si muove solo nel caso in cui venga colpito e va ad occupare |
008 | in sequenza quattro punti precisi nei pressi dei bordi del campo di |
009 | gioco , ciascuno su di un lato del campo stesso; |
010 | le routine di fuoco sono due e differenziate a seconda |
011 | che il robot SAXY si trovi in una fase di attesa ( fermo FIND()) |
012 | o in fase di fuga ( FUOCO()) ; |
013 | LA procedura di fuga � SCAPPA() e sfrutta le funzioni calcola_ang() e |
014 | vai() per raggiunge i punti prestabiliti dalla SCAPPA() stessa; |
015 |
016 |
017 |
018 | */ |
019 |
020 |
021 | int d1, |
022 | f, |
023 | flag, |
024 | dir, |
025 | x,y,x1,y1, |
026 | ang, |
027 | d, |
028 | range; |
029 |
030 |
031 |
032 | main() |
033 | {ang=540; |
034 | f=0; |
035 | x=950;y=500; |
036 | dir=calcola_ang(x,y); |
037 | vai(x,y,dir); |
038 | d=damage(); |
039 | while (1) |
040 | { |
041 | d=damage(); |
042 | while ( !(range = scan(ang,4))) |
043 | ang+=9; |
044 | if (!find(ang)) |
045 | ang+=30; |
046 | if (d!=damage()) |
047 | scappa(); |
048 | } |
049 | } |
050 |
051 | fuoco() |
052 | { int sfas,i,oldr; |
053 | oldr=range; |
054 | if (!(range = scan (ang, 3))) |
055 | { |
056 | if (range = scan(ang -= 6, 3)) |
057 | sfas = -4; |
058 | else |
059 | if (range = scan(ang -= 7, 4)) |
060 | sfas = -7; |
061 | else |
062 | if (range = scan(ang -= 12, 8)) |
063 | sfas = -10; |
064 | else |
065 | if (range = scan(ang += 31, 3)) |
066 | sfas = 4; |
067 | else |
068 | if (range = scan(ang += 7, 4)) |
069 | sfas = 7; |
070 | else |
071 | if (range = scan(ang += 12, 8)) |
072 | sfas = 10; |
073 | } |
074 | else |
075 | sfas=0; |
076 |
077 | if ((range)&&(range<710)) |
078 | { |
079 | if (oldr) |
080 | cannon(ang+sfas,range+(range - oldr)/3); |
081 | else |
082 | cannon(ang,range); |
083 | } |
084 | else |
085 | if (range>850) |
086 | { |
087 | ang+=40; |
088 | oldr=0; |
089 | } |
090 | } |
091 |
092 | find(ang) |
093 | int ang; |
094 | { int r; |
095 | range=scan(ang,4); |
096 | if (range) |
097 | { |
098 | if (scan(ang-2,2)) |
099 | ang-=2; |
100 | else |
101 | ang+=2; |
102 | if (scan(ang-1,1)) |
103 | ang-=1; |
104 | else |
105 | ang+=1; |
106 | if (scan(ang-1,0)) |
107 | ang--; |
108 | else |
109 | if (scan(ang+1,0)) |
110 | ang++; |
111 | cannon(ang,range); |
112 | return (1); |
113 | } |
114 | if ((range=scan(ang,4))&&(range<700)) |
115 | {cannon(ang,range); return (1);} |
116 | else |
117 | { |
118 | if (scan(ang+9,4)) |
119 | {ang +=9; return (1);} |
120 | else |
121 | if (scan(ang-9,4)) |
122 | {ang -= 9; return (1);} |
123 | else |
124 | return (0); |
125 | } |
126 |
127 | } |
128 |
129 | scappa() |
130 | { int xs,ys; |
131 | f = (f + 1 + 4) % 4; |
132 | if (f==0) |
133 | {xs=50;ys=500;dir=225; |
134 | } |
135 | else |
136 | { |
137 | if (f==1) |
138 | {xs=500;ys=950;dir=45;} |
139 | else |
140 | { |
141 | if (f==2) |
142 | {xs=950;ys=500;dir=315;} |
143 | else |
144 | {xs=500;ys=950;dir=135;} |
145 | } |
146 | } |
147 | vai(xs,ys,dir); |
148 | } |
149 |
150 | calcola_ang(xx,yy) |
151 | int xx, yy; |
152 | { |
153 | int d1; |
154 | int x,y; |
155 | int scale; |
156 | int curx, cury; |
157 |
158 | scale = 100000; /* scale for trig functions */ |
159 | curx = loc_x(); /* get current location */ |
160 | cury = loc_y(); |
161 | x = curx - xx; |
162 | y = cury - yy; |
163 |
164 | /* atan only returns -90 to +90, so figure out how to use */ |
165 | /* the atan() value */ |
166 |
167 | if (x == 0) { /* x is zero, we either move due north or south */ |
168 | if (yy > cury) |
169 | d1 = 90; /* north */ |
170 | else |
171 | d1 = 270; /* south */ |
172 | } else { |
173 | if (yy < cury) { |
174 | if (xx > curx) |
175 | d1 = 360 + atan ((scale * y) / x); /* south-east, quadrant 4 */ |
176 | else |
177 | d1 = 180 + atan ((scale * y) / x); /* south-west, quadrant 3 */ |
178 | } else { |
179 | if (xx > curx) |
180 | d1 = atan ((scale * y) / x); /* north-east, quadrant 1 */ |
181 | else |
182 | d1 = 180 + atan ((scale * y) / x); /* north-west, quadrant 2 */ |
183 | } |
184 | } |
185 | return (d1); |
186 | } |
187 |
188 |
189 | vai(x,y,dir) |
190 | int x; int y; int dir; |
191 | { |
192 | drive(dir,100); |
193 | while (distanza(loc_x(),loc_y(),x,y) > 150 && speed() > 0) |
194 | fuoco(); |
195 | drive(dir,20); |
196 | while (distanza(loc_x(),loc_y(),x,y) > 20 && speed() > 0) |
197 | ; |
198 | drive(dir,0); |
199 | } |
200 |
201 | distanza(x1,y1,x2,y2) |
202 | int x1; |
203 | int y1; |
204 | int x2; |
205 | int y2; |
206 | { |
207 | int x, y, d1; |
208 | x = x1 - x2; |
209 | y = y1 - y2; |
210 | d1 = sqrt ((x*x) + (y*y)); |
211 | return (d1); |
212 | } |