1999/mcenrobo.r
001 | /****************************************************************/ |
002 | /* McEnrobo */ |
003 | /* -------- */ |
004 | /* Author: Alex Paci */ |
005 | /* Date : 1990-1999 */ |
006 | /* */ |
007 | /* if you like CRobots, you may visit TpT (Tennis pro */ |
008 | /* Tournament) site, the first italian sport related PBeM where */ |
009 | /* you've to "program" your tennis player at */ |
010 | /* http://space.tin.it/io/rpaci */ |
011 | /* */ |
012 | /* Strategy is to move around the ring at maximum speed */ |
013 | /* until damages become too high. At this point he moves with */ |
014 | /* rectangular path near the corners changing corner if */ |
015 | /* threatened. Fire routine is quicker as much as possible, */ |
016 | /* being the robot in a continuous run. */ |
017 | /****************************************************************/ |
018 |
019 | /* Global Variables */ |
020 |
021 | int direction; /* Running Direction */ |
022 | int d; /* Distance to the Border */ |
023 | int gradi; /* Turning Degrees */ |
024 | int old_damage; /* Suffered Damages */ |
025 | int sc_dir; /* Scanning Direction */ |
026 | int upx; /* Auxiliar Variables */ |
027 | int downx; |
028 | int upy; |
029 | int downy; |
030 | int high1; |
031 | int high2; |
032 | int low1; |
033 | int low2; |
034 | int changed; |
035 |
036 |
037 |
038 | /* MAIN ROUTINE */ |
039 |
040 | main() { |
041 |
042 | /* Variables Initialization */ |
043 | direction = 0; |
044 | old_damage = 0; |
045 | sc_dir = 0; |
046 |
047 | /* Rectangle is Whole Screen with Deceleration Margins */ |
048 | high1 = 950; |
049 | high2 = 50; |
050 | low1 = 950; |
051 | low2 = 50; |
052 | changed = 0; |
053 |
054 | upx = high1; |
055 | downx = low2; |
056 | upy = high1; |
057 | downy = low2; |
058 |
059 | /* Main Cycle */ |
060 | while (1) { |
061 |
062 | if (!changed && damage()>75) { |
063 | /* Rectangle is Near Corner */ |
064 | high1 = 950; |
065 | high2 = 700; |
066 | low1 = 300; |
067 | low2 = 50; |
068 | /* Select Nearest Rectangle Corner */ |
069 | upx = high1; |
070 | downx = high2; |
071 | if (loc_x()<=500) { |
072 | upx = low1; |
073 | downx = low2; |
074 | } |
075 | upy = high1; |
076 | downy = high2; |
077 | if (loc_y()<=500) { |
078 | upy = low1; |
079 | downy = low2; |
080 | } |
081 |
082 | changed=1; |
083 | } |
084 |
085 | if (direction==0) |
086 | d=(upx-loc_x()); |
087 | else if (direction==90) |
088 | d=(upy-loc_y()); |
089 | else if (direction==180) |
090 | d=(loc_x()-downx); |
091 | else if (direction==270) |
092 | d=(loc_y()-downy); |
093 |
094 | /* Decelate if Too Close to Border */ |
095 | drive(direction,d); |
096 |
097 | if (d<20) |
098 | d=20; |
099 |
100 | if (d<=20) { |
101 | /* Turn 90 Degrees Rightwards */ |
102 | gradi=90; |
103 | /* Turn 90 Degrees More if Still no much Damaged and Safe Border */ |
104 | if (damage()<=75 && damage()==old_damage) |
105 | gradi+=90; |
106 | else |
107 | old_damage=damage(); |
108 | change_direction(); |
109 | } |
110 |
111 | /* Change Corner if Not Safe */ |
112 | if (damage()>=old_damage+10 && damage()>75) { |
113 | old_damage=damage(); |
114 | cambia_angolo(); |
115 | } |
116 |
117 | /* Quick Scan and Fire */ |
118 | fire(); |
119 | |
120 | } |
121 | } |
122 |
123 |
124 |
125 | /* Change Direction Function */ |
126 | change_direction() { |
127 | direction=(direction+gradi)%360; |
128 | drive(direction,d); |
129 | } |
130 |
131 | /* Change Corner Function */ |
132 | cambia_angolo() { |
133 | if (upx==high1) { |
134 | if (upy==high1) { |
135 | upx=low1; |
136 | downx=low2; |
137 | } |
138 | else { |
139 | upy=high1; |
140 | downy=high2; |
141 | } |
142 | } |
143 | else { |
144 | if (upy==high1) { |
145 | upy=low1; |
146 | downy=low2; |
147 | } |
148 | else { |
149 | upx=high1; |
150 | downx=high2; |
151 | } |
152 | } |
153 | } |
154 |
155 |
156 | /* Quick Scan and Fire Routine */ |
157 | fire() { |
158 |
159 | int r ; |
160 | int sc_dist; |
161 |
162 | if ( sc_dist = scan( sc_dir , 10 ) ) ; else |
163 | if ( sc_dist = scan( sc_dir += 20 , 10 ) ) ; else |
164 | if ( sc_dist = scan( sc_dir -= 40 , 10 ) ) ; else { |
165 | sc_dir -= 60 ; |
166 | return ; |
167 | } |
168 |
169 | if (r= scan( sc_dir -= 7 , 5 ) ) cannon(sc_dir,2*r-sc_dist) ; else sc_dir += 10 ; |
170 | if (r= scan( sc_dir -= 2 , 2 ) ) cannon(sc_dir,2*r-sc_dist); else sc_dir += 4 ; |
171 |
172 | if ( r = scan( sc_dir , 10 ) ) cannon( sc_dir , 2*r-sc_dist ); |
173 |
174 | if ( r > 700 ) sc_dir -= 60 ; |
175 |
176 | } |