| 1 | package Acme::RTB; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.008; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use IO::Select; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use IO::Handle; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 1 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | =head1 NAME | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | Acme::RTB - Perl extension for building realtimebattle bots | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | use Acme::RTB; | ||||||||||||||||||||||||||||
| 19 | my $robot = Acme::RTB->new({ Name => 'Anarion PerlBot 1.0', | ||||||||||||||||||||||||||||
| 20 | Colour => 'ff0000 ff0000', | ||||||||||||||||||||||||||||
| 21 | Log => '/home/anarion/perl/rtb/robot.log'} ); | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | $robot->Start; | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | This module will allow you to create bots for battling with realtimebattle. | ||||||||||||||||||||||||||||
| 28 | L<http://realtimebattle.sourceforge.net/> | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | =head1 METHODS | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | =over 4 | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | =head2 new | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | =back | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | First create an object, you should pass a hashref with the Name, Colour and if you | ||||||||||||||||||||||||||||
| 39 | will the logfile. | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | my $robot = Acme::RTB->new({ Name => 'Anarion PerlBot 1.0', | ||||||||||||||||||||||||||||
| 42 | Colour => 'ff0000 ff0000', | ||||||||||||||||||||||||||||
| 43 | Log => '/home/anarion/perl/rtb/robot.log'} ); | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | =over 4 | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | =head2 modify_action | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | =back | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | With this method you can change all the actions that your bot do when it recieves | ||||||||||||||||||||||||||||
| 53 | a msg from the server, the possible actions are: | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | Initialize | ||||||||||||||||||||||||||||
| 56 | YourName | ||||||||||||||||||||||||||||
| 57 | YourColour | ||||||||||||||||||||||||||||
| 58 | GameOption | ||||||||||||||||||||||||||||
| 59 | GameStarts | ||||||||||||||||||||||||||||
| 60 | Radar | ||||||||||||||||||||||||||||
| 61 | Info | ||||||||||||||||||||||||||||
| 62 | RobotInfo | ||||||||||||||||||||||||||||
| 63 | RotationReached | ||||||||||||||||||||||||||||
| 64 | Energy | ||||||||||||||||||||||||||||
| 65 | RobotsLeft | ||||||||||||||||||||||||||||
| 66 | Collision | ||||||||||||||||||||||||||||
| 67 | Warning | ||||||||||||||||||||||||||||
| 68 | Dead | ||||||||||||||||||||||||||||
| 69 | GameFinishes | ||||||||||||||||||||||||||||
| 70 | Unknown | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | $robot->modify_action( Radar => \&my_radar ); | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | $robot->modify_action( GameStarts => \&my_gamestart); | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | $robot->modify_action( Collision => \&my_collision); | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | Here are the parameters that you recieve from the server: | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | =head3 Initialize [first? (int)] | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | This is the very first message the robot will get. If the argument is one, it is the first sequence in the tournament and it should send Name and Colour to the server, otherwise it should wait for YourName and YourColour messages (see below). | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | =head3 YourName [name (string)] | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | Current name of the robot, don't change it if you don't have very good reasons. | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | =head3 YourColour [colour (hex)] | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | Current colour of the robot, change it if you find it ugly. | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | =head3 GameOption [optionnr (int)] [value (double)] | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | At the beginning of each game the robots will be sent a number of settings, which can be useful for the robot. For a complete list of these, look in the file Messagetypes.h for the game_option_type enum. In the options chapter you can get more detailed information on each option. The debug level is also sent as a game option even though it is not in the options list. | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | =head3 GameStarts | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | This message is sent when the game starts (surprise!) | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | =head3 Radar [distance (double)] [observed object type (int)] [radar angle (double)] | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | This message gives information from the radar each turn. Remember that the radar-angle is relative to the robot front; it is given in radians. | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | =head3 Info [time (double)] [speed (double)] [cannon angle (double)] | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | The Info message does always follow the Radar message. It gives more general information on the state of the robot. The time is the game-time elapsed since the start of the game. This is not necessarily the same as the real time elapsed, due to time scale and max timestep. | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | =head3 Coordinates [x (double)] [y (double)] [angle (double)] | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | Tells you the current robot position. It is only sent if the option Send robot coordinates is 1 or 2. If it is 1 the coordinates are sent relative the starting position, which has the effect that the robot doesn't know where it is starting, but only where it has moved since. | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | =head3 RobotInfo [energy level (double)] [teammate? (int)] | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | If you detect a robot with your radar, this message will follow, giving some information on the robot. The opponents energy level will be given in the same manner as your own energy (see below). The second argument is only interesting in team-mode (which current isn't implemented), 1 means a teammate and 0 an enemy. | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | =head3 RotationReached [what has reached(int)] | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | When the robot option SEND_ROTATION_REACHED is set appropriately, this message is sent when a rotation (with RotateTo or RotateAmount) has finished or the direction has changed (when sweeping). The argument corresponds to 'what to rotate' in e.g. Rotate. | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | =head3 Energy [energy level(double)] | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | The end of each round the robot will get to know its energy level. It will not, however, get the exact energy, instead it is discretized into a number of energy levels. | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | =head3 RobotsLeft [number of robots (int)] | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | At the beginning of the game and when a robot is killed the number of remaining robots is broadcasted to all living robots. | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | =head3 Collision [colliding object type (int)] [angle relative robot (double)] | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | When a robot hits (or is hit by) something it gets this message. In the file Messagetypes.h you can find a list of the object types. You get the angle from where the collision occurred (the angle relative the robot) and the type of object hitting you, but not how severe the collision was. This can, however, be determined indirectly (approximately) by the loss of energy. | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | =head3 Warning [warning type (int)] [message (string)] | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | A warning message can be sent when robot has to be notified on different problems which have occured. Currently seven different warning messages can be sent, namely | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | UNKNOWN_MESSAGE: The server received a message it couldn't recognize. | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | PROCESS_TIME_LOW: The CPU usage has reached the CPU warning percentage. Only in competition-mode. | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | MESSAGE_SENT_IN_ILLEGAL_STATE: The message received couldn't be handled in this state of the program. For example Rotate is sent before the game has started. | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | UNKNOWN_OPTION: The robot sent a robot option with either illegal option name or illegal argument to that option. | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | OBSOLETE_KEYWORD: The keyword sent is obsolete and should not be used any more, see the ChangeLog file for information on what to use instead. | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | NAME_NOT_GIVEN: The robot has not sent its name before the game begins. This happens if the robot startup time is too short or the robot does not send its name early enough. | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | COLOUR_NOT_GIVEN: The robot has not sent its colour before the game begins. | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | =head3 Dead | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | Robot died. Do not try to send more messages to the server until the end of the game, the server doesn't read them. | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | =head3 GameFinishes | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | Current game is finished, get prepared for the next! | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | =head3 ExitRobot | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | Exit from the program immediately! Otherwise it will be killed forcefully. | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | =over 4 | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | =head2 process_lines | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | =back | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | This is the method that reads (if it can) from the server and execute | ||||||||||||||||||||||||||||
| 172 | the apropiate method. You can manage yourself, or let the module to | ||||||||||||||||||||||||||||
| 173 | do it itself. | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | while(1) | ||||||||||||||||||||||||||||
| 176 | { | ||||||||||||||||||||||||||||
| 177 | # Read stdin | ||||||||||||||||||||||||||||
| 178 | $robot->parse_lines; | ||||||||||||||||||||||||||||
| 179 | # do other stuff here | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | =over 4 | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | =head2 Rotate [what to rotate (int)] [angular velocity (double)] | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | =back | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | Set the angular velocity for the robot, its cannon and/or its radar. Set 'what to rotate' to 1 for robot, 2 for cannon, 4 for radar or to a sum of these to rotate more objects at the same time. The angular velocity is given in radians per second and is limited by Robot (cannon/radar) max rotate speed. | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | =over 4 | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | =head2 RotateTo [what to rotate (int)] [angular velocity (double)] [end angle (double)] | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | =back | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | As Rotate, but will rotate to a given angle. Note that radar and cannon angles are relative to the robot angle. You cannot use this command to rotate the robot itself, use RotateAmount instead! | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | =over 4 | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | =head2 RotateAmount [what to rotate (int)] [angular velocity (double)] [angle (double)] | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | =back | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | As Rotate, but will rotate relative to the current angle. | ||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | =over 4 | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | =head2 Sweep [what to rotate (int)] [angular velocity (dbl)] [left angle (dbl)] [right angle (dbl)] | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | =back | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | As rotate, but sets the radar and/or the cannon (not available for the robot itself) in a sweep mode. | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | =over 4 | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | =head2 Accelerate [value (double)] | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | =back | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | Set the robot acceleration. Value is bounded by Robot max/min acceleration. | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | =over 4 | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | =head2 Brake [portion (double)] | ||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | =back | ||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | Set the brake. Full brake (portion = 1.0) means that the friction in the robot direction is equal to Slide friction. | ||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | =over 4 | ||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | =head2 Shoot [shot energy (double)] | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | =back | ||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | Shoot with the given energy. The shot options give more information. | ||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | =over 4 | ||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | =head2 Print [message (string)] | ||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | =back | ||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | Print message on the message window. | ||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | =over 4 | ||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | =head2 Debug [message (string)] | ||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | =back | ||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | Print message on the message window if in debug-mode. | ||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | =over 4 | ||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | =head2 DebugLine [angle1 (double)] [radius1 (double)] [angle2 (double)] [radius2 (double)] | ||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | =back | ||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | Draw a line direct to the arena. This is only allowed in the highest debug level(5), otherwise a warning message is sent. The arguments are the start and end point of the line given in polar coordinates relative to the robot. | ||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | =over 4 | ||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||
| 272 | =head2 DebugCircle [center angle (double)] [center radius (double)] [circle radius (double)] | ||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | =back | ||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||
| 276 | Similar to DebugLine above, but draws a circle. The first two arguments are the angle and radius of the central point of the circle relative to the robot. The third argument gives the radius of the circle. | ||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||
| 278 | =head1 EXAMPLES | ||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | My hello botworld: | ||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||
| 282 | use Acme::RTB; | ||||||||||||||||||||||||||||
| 283 | my $robot = Acme::RTB->new({ Name => 'Anarion PerlBot 1.0', | ||||||||||||||||||||||||||||
| 284 | Colour => 'ff0000 ff0000', | ||||||||||||||||||||||||||||
| 285 | Log => '/home/anarion/perl/rtb/robot.log'} ); | ||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||
| 287 | $robot->Start; | ||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | Example two: | ||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||
| 292 | #!/usr/bin/perl | ||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||
| 294 | use strict; | ||||||||||||||||||||||||||||
| 295 | use warnings; | ||||||||||||||||||||||||||||
| 296 | use lib "/home/anarion/perl/rtb"; | ||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||
| 298 | use Acme::RTB; | ||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | my $robot = Acme::RTB->new({ Name => 'Killer Montses', | ||||||||||||||||||||||||||||
| 301 | Colour => 'ff0000 ff0000', | ||||||||||||||||||||||||||||
| 302 | Log => '/home/anarion/perl/rtb/anarion.log'} ); | ||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | $robot->modify_action( Radar => \&my_radar ); | ||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||
| 307 | $robot->modify_action( GameStarts => \&my_gamestart); | ||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||
| 309 | $robot->modify_action( Collision => \&my_collision); | ||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||
| 311 | $robot->Start; | ||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||
| 313 | sub my_radar | ||||||||||||||||||||||||||||
| 314 | { | ||||||||||||||||||||||||||||
| 315 | my ($self, $dist, $obj, $angle) = @_; | ||||||||||||||||||||||||||||
| 316 | for($obj) | ||||||||||||||||||||||||||||
| 317 | { | ||||||||||||||||||||||||||||
| 318 | /0/ && do { robot($dist,$angle) }; | ||||||||||||||||||||||||||||
| 319 | /1/ && do { dodge($dist,$angle) }; | ||||||||||||||||||||||||||||
| 320 | /2/ && do { turn($dist,$angle) }; | ||||||||||||||||||||||||||||
| 321 | /3/ && do { cookie($dist,$angle) }; | ||||||||||||||||||||||||||||
| 322 | /4/ && do { mine($dist,$angle) }; | ||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||
| 327 | sub my_gamestart | ||||||||||||||||||||||||||||
| 328 | { | ||||||||||||||||||||||||||||
| 329 | my $self = shift; | ||||||||||||||||||||||||||||
| 330 | my $speed = rand(1)+1; | ||||||||||||||||||||||||||||
| 331 | my $angle = rand(0.4)-0.8; | ||||||||||||||||||||||||||||
| 332 | $self->Accelerate($speed); | ||||||||||||||||||||||||||||
| 333 | $self->RotateAmount(7,rand(2),rand(5)); | ||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||
| 337 | sub my_collision | ||||||||||||||||||||||||||||
| 338 | { | ||||||||||||||||||||||||||||
| 339 | my ($self, $object_type, $angle) = @_; | ||||||||||||||||||||||||||||
| 340 | $robot->RotateAmount(7,rand(2),rand(5)-2.5); | ||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||
| 344 | sub robot | ||||||||||||||||||||||||||||
| 345 | { | ||||||||||||||||||||||||||||
| 346 | my ($dist, $angle) = @_; | ||||||||||||||||||||||||||||
| 347 | $robot->RotateTo(7,2,$angle-0.2); | ||||||||||||||||||||||||||||
| 348 | $robot->Shoot(10); | ||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||
| 352 | sub dodge | ||||||||||||||||||||||||||||
| 353 | { | ||||||||||||||||||||||||||||
| 354 | $robot->RotateAmount(7,2,1); | ||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||
| 358 | sub turn | ||||||||||||||||||||||||||||
| 359 | { | ||||||||||||||||||||||||||||
| 360 | my ($dist, $angle) = @_; | ||||||||||||||||||||||||||||
| 361 | if($dist < 10) | ||||||||||||||||||||||||||||
| 362 | { | ||||||||||||||||||||||||||||
| 363 | $robot->RotateAmount(7,2,rand(5)-2.5); | ||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||
| 368 | sub cookie | ||||||||||||||||||||||||||||
| 369 | { | ||||||||||||||||||||||||||||
| 370 | my ($dist, $angle) = @_; | ||||||||||||||||||||||||||||
| 371 | $robot->RotateAmount(7,2,$angle); | ||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||
| 375 | sub mine | ||||||||||||||||||||||||||||
| 376 | { | ||||||||||||||||||||||||||||
| 377 | my ($dist, $angle) = @_; | ||||||||||||||||||||||||||||
| 378 | $robot->RotateTo(7,2,$angle); | ||||||||||||||||||||||||||||
| 379 | $robot->Shoot(1); | ||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||
| 382 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||
| 384 | Debian User, E<lt>anarion@7a69ezine.orgE<gt> | ||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||
| 386 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||
| 388 | Copyright 2003 by Anarion | ||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||
| 390 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 391 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||
| 393 | =cut | ||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||
| 396 | 1 | STDOUT->autoflush(1); | |||||||||||||||||||||||||||
| 397 | 1 | STDERR->autoflush(1); | |||||||||||||||||||||||||||
| 398 | 1 | my $select = IO::Select->new(); | |||||||||||||||||||||||||||
| 399 | 1 | $select->add(*STDIN); | |||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||
| 401 | 1 | my %actions = ( Initialize => \&initialize, | |||||||||||||||||||||||||||
| 402 | YourName => \&your_name, | ||||||||||||||||||||||||||||
| 403 | YourColour => \&your_color, | ||||||||||||||||||||||||||||
| 404 | GameOption => \&game_option, | ||||||||||||||||||||||||||||
| 405 | GameStarts => \&game_starts, | ||||||||||||||||||||||||||||
| 406 | Radar => \&radar, | ||||||||||||||||||||||||||||
| 407 | Info => \&info, | ||||||||||||||||||||||||||||
| 408 | RobotInfo => \&robot_info, | ||||||||||||||||||||||||||||
| 409 | RotationReached => \&rotation_reached, | ||||||||||||||||||||||||||||
| 410 | Energy => \&energy, | ||||||||||||||||||||||||||||
| 411 | RobotsLeft => \&robots_left, | ||||||||||||||||||||||||||||
| 412 | Collision => \&collision, | ||||||||||||||||||||||||||||
| 413 | Warning => \&warning, | ||||||||||||||||||||||||||||
| 414 | Dead => \&dead, | ||||||||||||||||||||||||||||
| 415 | GameFinishes => \&game_finish, | ||||||||||||||||||||||||||||
| 416 | Unknown => \&unknown, ); | ||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||
| 418 | 1 | my %options; | |||||||||||||||||||||||||||
| 419 | 1 | local *LOG; | |||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||
| 421 | sub new | ||||||||||||||||||||||||||||
| 422 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.7
Pod
documented
| |||||||||||||||||||||||||||||
| 423 | 1 | my ($class, $options) = @_; | |||||||||||||||||||||||||||
| 424 | my $self = { Name => $options->{Name} || "RTB v$VERSION", | ||||||||||||||||||||||||||||
| 425 | Colour => $options->{Colour} || 'ff0000 ff0000', | ||||||||||||||||||||||||||||
| 426 | 1 | ▶ | Log => $options->{Log} }; | ||||||||||||||||||||||||||
|
Condition50%2/4
$options->{'Name'} || "RTB v$Acme::RTB::VERSION"
$options->{'Colour'} || 'ff0000 ff0000'
MC/DC0%0/1
$options->{'Name'} || "RTB v$Acme::RTB::VERSION"
$options->{'Name'}
MC/DC0%0/1
$options->{'Colour'} || 'ff0000 ff0000'
$options->{'Colour'}
Truth table50%1/2
A
A= $options->{'Name'}
Truth table50%1/2
A
A= $options->{'Colour'}
| |||||||||||||||||||||||||||||
| 427 | 1 | ▶ | if($options->{Log}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 428 | { | ||||||||||||||||||||||||||||
| 429 | 1 | ▶ | open(LOG,">$options->{Log}") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 430 | or die "Cant write to logfile: $options->{Log}: $!"; | ||||||||||||||||||||||||||||
| 431 | 1 | LOG->autoflush(1); | |||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||
| 434 | 1 | my $obj = bless $self,$class; | |||||||||||||||||||||||||||
| 435 | 1 | $obj->RobotOption(3,1); # Use Select | |||||||||||||||||||||||||||
| 436 | 1 | $obj->RobotOption(1,1); # Rotation reached | |||||||||||||||||||||||||||
| 437 | 1 | return $obj | |||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||
| 440 | ### | ||||||||||||||||||||||||||||
| 441 | sub modify_action | ||||||||||||||||||||||||||||
| 442 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
modify_action: called CC=3 SCAR=12.5
Pod
documented
| |||||||||||||||||||||||||||||
| 443 | 1 | my ($self, $key , $code) = @_; | |||||||||||||||||||||||||||
| 444 | 1 | ▶ | if(exists $actions{$key} and ref($code) eq "CODE") | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $actions{$key} and ref $code eq "CODE"
MC/DC0%0/2
exists $actions{$key} and ref $code eq "CODE"
exists $actions{$key}
ref $code eq "CODE"
Truth table33%1/3
A and B
A= exists $actions{$key}B= ref $code eq "CODE"
| |||||||||||||||||||||||||||||
| 445 | { | ||||||||||||||||||||||||||||
| 446 | 1 | $actions{$key} = $code; | |||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||
| 450 | ### | ||||||||||||||||||||||||||||
| 451 | sub process_lines | ||||||||||||||||||||||||||||
| 452 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
process_lines: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 453 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 454 | 0 | ▶ | while(my @l = $select->can_read(0.1)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 455 | { | ||||||||||||||||||||||||||||
| 456 | 0 | my $hd = $l[0]; | |||||||||||||||||||||||||||
| 457 | 0 | my $msg = <$hd>; | |||||||||||||||||||||||||||
| 458 | 0 | chomp($msg); | |||||||||||||||||||||||||||
| 459 | 0 | ▶ | print LOG "<--- $msg\n" if $self->{Log}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 460 | 0 | my ($cmd, @options) = split' ',$msg; | |||||||||||||||||||||||||||
| 461 | 0 | ▶ | $cmd = 'Unknown' unless exists $actions{ $cmd }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 462 | 0 | $actions{ $cmd }->($self, @options) | |||||||||||||||||||||||||||
| 463 | } | ||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||
| 466 | ### | ||||||||||||||||||||||||||||
| 467 | sub initialize | ||||||||||||||||||||||||||||
| 468 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
initialize: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 469 | 0 | my ($self, $num) = @_; | |||||||||||||||||||||||||||
| 470 | 0 | ▶ | if ($num == 1) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 471 | { | ||||||||||||||||||||||||||||
| 472 | 0 | $self->Name; | |||||||||||||||||||||||||||
| 473 | 0 | $self->Colour; | |||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||
| 475 | } | ||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||
| 477 | ### | ||||||||||||||||||||||||||||
| 478 | sub your_name | ||||||||||||||||||||||||||||
| 479 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
your_name: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 480 | 0 | my ($self, $name) = @_; | |||||||||||||||||||||||||||
| 481 | 0 | $self->{Name} = $name; | |||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||
| 484 | ### | ||||||||||||||||||||||||||||
| 485 | sub your_colour | ||||||||||||||||||||||||||||
| 486 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
your_colour: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 487 | 0 | my ($self, $name) = @_; | |||||||||||||||||||||||||||
| 488 | 0 | $self->{Colour} = $name; | |||||||||||||||||||||||||||
| 489 | } | ||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||
| 491 | ### | ||||||||||||||||||||||||||||
| 492 | sub game_option | ||||||||||||||||||||||||||||
| 493 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
game_option: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 494 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 495 | 0 | %options = split' ',shift; | |||||||||||||||||||||||||||
| 496 | } | ||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||
| 498 | ### | ||||||||||||||||||||||||||||
| 499 | sub game_starts | ||||||||||||||||||||||||||||
| 500 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
game_starts: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||
| 503 | } | ||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||
| 505 | ### | ||||||||||||||||||||||||||||
| 506 | sub radar | ||||||||||||||||||||||||||||
| 507 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
radar: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 508 | # Objects: Robot=0, Shot=1, Wall=2, Cookie=3, Mine=4, LAST=5 | ||||||||||||||||||||||||||||
| 509 | 0 | my ($self, $dist, $obj, $angle) = @_; | |||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||
| 511 | } | ||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||
| 513 | ### | ||||||||||||||||||||||||||||
| 514 | sub info | ||||||||||||||||||||||||||||
| 515 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
info: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 516 | 0 | my ($self, $time, $speed, $cannon_angle) = @_; | |||||||||||||||||||||||||||
| 517 | } | ||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||
| 519 | ### | ||||||||||||||||||||||||||||
| 520 | sub robot_info | ||||||||||||||||||||||||||||
| 521 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
robot_info: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 522 | 0 | my ($self, $energy, $teammate) = @_; | |||||||||||||||||||||||||||
| 523 | 0 | $self->{Energy} = $energy; | |||||||||||||||||||||||||||
| 524 | } | ||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||
| 526 | ### | ||||||||||||||||||||||||||||
| 527 | sub rotation_reached | ||||||||||||||||||||||||||||
| 528 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
rotation_reached: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 529 | 0 | my ($self, $what) = @_; | |||||||||||||||||||||||||||
| 530 | } | ||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||
| 532 | ### | ||||||||||||||||||||||||||||
| 533 | sub energy | ||||||||||||||||||||||||||||
| 534 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
energy: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 535 | 0 | my ($self, $energy) = @_; | |||||||||||||||||||||||||||
| 536 | 0 | $self->{Energy} = $energy; | |||||||||||||||||||||||||||
| 537 | } | ||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||
| 539 | ### | ||||||||||||||||||||||||||||
| 540 | sub robots_left | ||||||||||||||||||||||||||||
| 541 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
robots_left: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 542 | 0 | my ($self, $robotsleft) = @_; | |||||||||||||||||||||||||||
| 543 | } | ||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||
| 545 | ### | ||||||||||||||||||||||||||||
| 546 | sub collision | ||||||||||||||||||||||||||||
| 547 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
collision: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 548 | 0 | my ($self, $object_type, $angle) = @_; | |||||||||||||||||||||||||||
| 549 | } | ||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||
| 551 | ### | ||||||||||||||||||||||||||||
| 552 | sub warning | ||||||||||||||||||||||||||||
| 553 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
warning: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 554 | 0 | my ($self, $warning_type, $msg) = @_; | |||||||||||||||||||||||||||
| 555 | } | ||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||
| 557 | ### | ||||||||||||||||||||||||||||
| 558 | sub dead | ||||||||||||||||||||||||||||
| 559 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
dead: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||
| 561 | } | ||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||
| 563 | ### | ||||||||||||||||||||||||||||
| 564 | sub game_finish | ||||||||||||||||||||||||||||
| 565 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
game_finish: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||
| 567 | } | ||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||
| 569 | ### | ||||||||||||||||||||||||||||
| 570 | sub unknown | ||||||||||||||||||||||||||||
| 571 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
unknown: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 572 | # Put here som sample code | ||||||||||||||||||||||||||||
| 573 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 574 | 0 | ▶ | print LOG "Unknown command: @_\n" if $self->{Log}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 575 | } | ||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||
| 577 | #### METHODS ##### | ||||||||||||||||||||||||||||
| 578 | sub RobotOption | ||||||||||||||||||||||||||||
| 579 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
RobotOption: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 580 | 2 | my ($self, $nr, $value) = @_; | |||||||||||||||||||||||||||
| 581 | 2 | print "RobotOption $nr $value\n"; | |||||||||||||||||||||||||||
| 582 | 2 | ▶ | print LOG "--> RobotOption $nr $value\n" if $self->{Log}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 583 | } | ||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||
| 585 | sub Name | ||||||||||||||||||||||||||||
| 586 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
Name: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 587 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 588 | 0 | print "Name $self->{Name}\n"; | |||||||||||||||||||||||||||
| 589 | 0 | ▶ | print LOG "--> Name $self->{Name}\n" if $self->{Log}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 590 | } | ||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||
| 592 | sub Colour | ||||||||||||||||||||||||||||
| 593 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
Colour: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 594 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 595 | 0 | print "Colour $self->{Colour}\n"; | |||||||||||||||||||||||||||
| 596 | 0 | ▶ | print LOG "--> Colour $self->{Colour}\n" if $self->{Log}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 597 | } | ||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||
| 599 | sub Rotate | ||||||||||||||||||||||||||||
| 600 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
Rotate: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 601 | # 1 - robot, 2 - cannon, 4 - radar | ||||||||||||||||||||||||||||
| 602 | 0 | my ($self, $what, $velocity) = @_; | |||||||||||||||||||||||||||
| 603 | 0 | print "Rotate $what $velocity\n"; | |||||||||||||||||||||||||||
| 604 | 0 | ▶ | print LOG "--> Rotate $what $velocity\n" if $self->{Log}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||
| 606 | } | ||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||
| 608 | sub RotateTo | ||||||||||||||||||||||||||||
| 609 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
RotateTo: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 610 | 0 | my ($self, $what, $velocity, $end) = @_; | |||||||||||||||||||||||||||
| 611 | 0 | print "RotateTo $what $velocity $end\n"; | |||||||||||||||||||||||||||
| 612 | 0 | ▶ | print LOG "--> RotateTo $what $velocity $end\n" if $self->{Log}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 613 | } | ||||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||
| 615 | sub RotateAmount | ||||||||||||||||||||||||||||
| 616 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
RotateAmount: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 617 | 1 | my ($self, $what, $velocity, $angl) = @_; | |||||||||||||||||||||||||||
| 618 | 1 | print "RotateAmount $what $velocity $angl\n"; | |||||||||||||||||||||||||||
| 619 | 1 | ▶ | print LOG "--> RotateAmount $what $velocity $angl\n" if $self->{Log}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 620 | } | ||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||
| 622 | sub Sweep | ||||||||||||||||||||||||||||
| 623 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
Sweep: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 624 | 0 | my ($self, $what, $velocity, $la, $ra) = @_; | |||||||||||||||||||||||||||
| 625 | 0 | print "Sweep $what $velocity $la $ra\n"; | |||||||||||||||||||||||||||
| 626 | 0 | ▶ | print LOG "--> Sweep $what $velocity $la $ra\n" if $self->{Log}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 627 | } | ||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||
| 629 | sub Accelerate | ||||||||||||||||||||||||||||
| 630 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
Accelerate: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 631 | 0 | my ($self, $value) = @_; | |||||||||||||||||||||||||||
| 632 | 0 | print "Accelerate $value\n"; | |||||||||||||||||||||||||||
| 633 | 0 | ▶ | print LOG "--> Accelerate $value\n" if $self->{Log}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 634 | } | ||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||
| 636 | sub Brake | ||||||||||||||||||||||||||||
| 637 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
Brake: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 638 | 0 | my ($self, $portion) = @_; | |||||||||||||||||||||||||||
| 639 | 0 | print "Brake $portion\n"; | |||||||||||||||||||||||||||
| 640 | 0 | ▶ | print LOG "Brake $portion\n" if $self->{Log}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 641 | } | ||||||||||||||||||||||||||||
| 642 | |||||||||||||||||||||||||||||
| 643 | sub Shoot | ||||||||||||||||||||||||||||
| 644 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
Shoot: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 645 | 0 | my ($self, $energy) = shift; | |||||||||||||||||||||||||||
| 646 | 0 | print "Shoot $energy\n"; | |||||||||||||||||||||||||||
| 647 | 0 | ▶ | print LOG "Shoot $energy\n" if $self->{Log}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 648 | } | ||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||
| 650 | sub Print | ||||||||||||||||||||||||||||
| 651 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
Print: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 652 | 0 | my ($self, $txt) = @_; | |||||||||||||||||||||||||||
| 653 | 0 | print "Print $txt\n"; | |||||||||||||||||||||||||||
| 654 | 0 | ▶ | print LOG "Print $txt\n" if $self->{Log}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 655 | } | ||||||||||||||||||||||||||||
| 656 | |||||||||||||||||||||||||||||
| 657 | sub Debug | ||||||||||||||||||||||||||||
| 658 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
Debug: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 659 | 0 | my ($self,$txt) = @_; | |||||||||||||||||||||||||||
| 660 | 0 | print "Debug $txt\n"; | |||||||||||||||||||||||||||
| 661 | 0 | ▶ | print LOG "Debug $txt\n" if $self->{Log}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 662 | } | ||||||||||||||||||||||||||||
| 663 | |||||||||||||||||||||||||||||
| 664 | sub DebugLine | ||||||||||||||||||||||||||||
| 665 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
DebugLine: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 666 | 0 | my ($self, $a1, $r1, $a2, $r2) = @_; | |||||||||||||||||||||||||||
| 667 | 0 | print "DebugLine $a1 $r1 $a2 $r2\n"; | |||||||||||||||||||||||||||
| 668 | 0 | ▶ | print LOG "DebugLine $a1 $r1 $a2 $r2\n" if $self->{Log}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 669 | } | ||||||||||||||||||||||||||||
| 670 | |||||||||||||||||||||||||||||
| 671 | sub DebugCircle | ||||||||||||||||||||||||||||
| 672 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
DebugCircle: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 673 | 0 | my ($self, $a,$r1,$r2) = @_; | |||||||||||||||||||||||||||
| 674 | 0 | print "DebugCircle $a $r1 $r2\n"; | |||||||||||||||||||||||||||
| 675 | 0 | ▶ | print LOG "DebugCircle $a $r1 $r2\n" if $self->{Log}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 676 | } | ||||||||||||||||||||||||||||
| 677 | |||||||||||||||||||||||||||||
| 678 | sub Start | ||||||||||||||||||||||||||||
| 679 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
Start: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 680 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 681 | 0 | while(1) | |||||||||||||||||||||||||||
| 682 | { | ||||||||||||||||||||||||||||
| 683 | 0 | $self->process_lines; | |||||||||||||||||||||||||||
| 684 | 0 | sleep 1; | |||||||||||||||||||||||||||
| 685 | } | ||||||||||||||||||||||||||||
| 686 | } | ||||||||||||||||||||||||||||
| 687 | |||||||||||||||||||||||||||||
| 688 | sub Log | ||||||||||||||||||||||||||||
| 689 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
Log: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 690 | 0 | my ($self, $msg) = @_; | |||||||||||||||||||||||||||
| 691 | 0 | ▶ | print LOG "$msg\n" if $self->{Log}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 692 | } | ||||||||||||||||||||||||||||
| 693 | |||||||||||||||||||||||||||||
| 694 | 1 | 1; | |||||||||||||||||||||||||||