#!/usr/bin/perl # Implements the Gandhi tank. # Passive resistance is the key. # 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 = 'Gandhi'; # Register your tank. This is how you use an object in perl. $Client->Register($name); # Initialize the first command $cmd = 'WAIT'; # 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 Gandhi the next command is simply to WAIT $cmd = 'WAIT'; } # 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"; }