crobs/silly.r
001 | /* silly */ |
002 | /* silly runs around the field, randomly */ |
003 | /* and scans randomly firing when stumbling upon a robot*/ |
004 |
005 |
006 | main() |
007 | { |
008 | int da; |
009 | da = 0; |
010 | while (1) |
011 | { |
012 | go( rand (1000), rand (1000)); /* go somewhere in the field */ |
013 | } |
014 |
015 | } /* end of main */ |
016 |
017 |
018 |
019 | /* go - go to the point specified */ |
020 |
021 | go (dest_x, dest_y) |
022 | int dest_x, dest_y; |
023 | { |
024 | int course; |
025 | int range; |
026 | int degree; |
027 | int times; |
028 | int degree1; |
029 | int degree2; |
030 | int number; |
031 | int range1; |
032 | int range2; |
033 | int running; |
034 |
035 | course = plot_course(dest_x,dest_y); |
036 | running = 0; |
037 | drive(course,50); |
038 | while ((distance(loc_x(),loc_y(),dest_x,dest_y) > 150)) |
039 | { |
040 | degree = rand (360); |
041 | degree1 = (degree + 3) % 359; |
042 | degree2 = (degree + 356) % 359; |
043 | if (((range = scan(degree,2)) > 2) && (range < 700)) |
044 | { |
045 | drive(course,0); |
046 | cannon(degree,range); |
047 | times = 0; |
048 | d = damage(); |
049 | running = 0; |
050 | while ((times++ < 30)&&(running == 0)) |
051 | { |
052 | /* if (d != damage()) |
053 | { |
054 | drive(course,100); |
055 | running = 1; |
056 | d = damage(); |
057 | } |
058 | else { */ |
059 | if (((range1 = scan(degree1,2)) > 2) && (range1 < 700)) |
060 | { |
061 | while (cannon(degree1,range1)!=0); |
062 | degree1 = (degree1 + 3) % 359; |
063 | } |
064 | else |
065 | { |
066 | degree1 = (degree1 + 356) % 359; |
067 | } |
068 | if (((range2 = scan(degree2,2)) > 2) && (range2 < 700)) |
069 | { |
070 | while (cannon(degree2,range2)!=0); |
071 | degree2 = (degree2 + 356) % 359; |
072 | } |
073 | else |
074 | { |
075 | degree2 = (degree2 + 3) % 359; |
076 | } |
077 | if (((range = scan(degree,2)) > 2) && (range < 700)) |
078 | while (cannon(degree,range)!=0); |
079 | } |
080 | } |
081 | if (speed() == 0) |
082 | { |
083 | drive(course,50); |
084 | } |
085 | } |
086 | drive(course,0); |
087 | while (speed() > 0) |
088 | ; |
089 | } |
090 |
091 | /* distance forumula */ |
092 |
093 | distance(x1,y1,x2,y2) |
094 | int x1; |
095 | int y1; |
096 | int x2; |
097 | int y2; |
098 | { |
099 | int x, y; |
100 |
101 | x = x1 - x2; |
102 | y = y1 - y2; |
103 | d = sqrt ((x*x) + (y*y)); |
104 |
105 | return (d); |
106 | } |
107 |
108 | /* plot_course - figure out which heading to go */ |
109 |
110 | plot_course(xx,yy) |
111 | int xx, yy; |
112 | { |
113 | int d; |
114 | int x,y; |
115 | int scale; |
116 | int curx, cury; |
117 |
118 | scale = 100000; /* scale for trig functions */ |
119 |
120 | curx = loc_x(); |
121 | cury = loc_y(); |
122 | x = curx - xx; |
123 | y = cury - yy; |
124 |
125 | if (x == 0) { |
126 | if (yy > cury) |
127 | d = 90; |
128 | else |
129 | d = 270; |
130 | } else { |
131 | if (yy < cury) { |
132 | if (xx > curx) |
133 | d = 360 + atan ((scale * y) / x); |
134 | else |
135 | d = 180 + atan ((scale * y) / x); |
136 | } else { |
137 | if (xx > curx) |
138 | d = atan ((scale * y) / x); |
139 | else |
140 | d = 180 + atan ((scale * y) / x); |
141 | } |
142 | } |
143 | return (d); |
144 | } |
145 |
146 |
147 | /* end of silly.r */ |
148 |
|