#!/usr/bin/perl # Implements an insane shooter tank. # Just shoots in a random direction. # Doesn't care if there is enough Epoints or not. # Use this module to make a client (or a server) # It must be in the same directory as your client. use ClientServer; # First create the object you will use. # new is historically the object creator but can be anything $Client = new ClientServer('Client'); # Decide on a name. This will be your ID. # No spaces or funny char are allowed, only RE m/\w\-/ $name = 'Insane'; # Register your tank. This is how you use an object in perl. $Client->Register($name); # Initialize the first command # How to use random numbers in perl $no = rand(8); # return a random fractional number less than 8 $direction = 1 + int($no); $cmd = "SHOOT $name $direction"; # Now the loop where you decide on your commands while (1) { # loop forever # Send your command to the battle server and get an answer back $answer = $Client->Command($cmd); # jump out of the loop if the server tells you to stop last if $answer =~ m/^STOP/; # Now here you decide the next command based on your answer # This can be as simple/complicated as you like # For Insane the next command is simply to SHOOT $cmd = "SHOOT $name " . int(1 + rand(8)); } # End of forever loop # Now why did we stop if ($answer =~ m/KILLED\s*(\S*)/) { print "You were killed by $1\n"; } elsif ($answer =~ m/WINNER/) { print "You won this round\n"; } elsif ($answer =~ m/DRAW/) { print "You fought this round to a draw\n"; } else { print "Wierd, this shouldn't happen: $answer"; }