Acme-RTB

 view release on metacpan or  search on metacpan

RTB/RTB.pm  view on Meta::CPAN


=head1 NAME

Acme::RTB - Perl extension for building realtimebattle bots

=head1 SYNOPSIS

  use Acme::RTB;
  my $robot = Acme::RTB->new({  Name    => 'Anarion PerlBot 1.0',
                                Colour  => 'ff0000 ff0000',
                                Log     => '/home/anarion/perl/rtb/robot.log'} );

  $robot->Start;

=head1 DESCRIPTION

This module will allow you to create bots for battling with realtimebattle.
L<http://realtimebattle.sourceforge.net/>

=head1 METHODS

=over 4

=head2 new

=back

First create an object, you should pass a hashref with the Name, Colour and if you
will the logfile.

  my $robot = Acme::RTB->new({  Name    => 'Anarion PerlBot 1.0',
                                Colour  => 'ff0000 ff0000',
                                Log     => '/home/anarion/perl/rtb/robot.log'} );


=over 4

=head2 modify_action

=back

With this method you can change all the actions that your bot do when it recieves
a msg from the server, the possible actions are:

RTB/RTB.pm  view on Meta::CPAN


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.

=head1 EXAMPLES

My hello botworld:

  use Acme::RTB;
  my $robot = Acme::RTB->new({  Name    => 'Anarion PerlBot 1.0',
                                Colour  => 'ff0000 ff0000',
                                Log     => '/home/anarion/perl/rtb/robot.log'} );

  $robot->Start;


Example two:

#!/usr/bin/perl

use strict;
use warnings;
use lib "/home/anarion/perl/rtb";

use Acme::RTB;

my $robot = Acme::RTB->new({    Name    => 'Killer Montses',
                                Colour  => 'ff0000 ff0000',
                                Log     => '/home/anarion/perl/rtb/anarion.log'} );


$robot->modify_action(  Radar           => \&my_radar    );

$robot->modify_action(  GameStarts      => \&my_gamestart);

$robot->modify_action(  Collision       => \&my_collision);

$robot->Start;

RTB/RTB.pm  view on Meta::CPAN


sub new
{
        my ($class, $options) = @_;
        my $self = {    Name    => $options->{Name} || "RTB v$VERSION",
                        Colour  => $options->{Colour} || 'ff0000 ff0000',
                        Log     => $options->{Log} };
        if($options->{Log})
        {
                open(LOG,">$options->{Log}")
                        or die "Cant write to logfile: $options->{Log}: $!";
                LOG->autoflush(1);
        }

        my $obj = bless $self,$class;
        $obj->RobotOption(3,1); # Use Select
        $obj->RobotOption(1,1); # Rotation reached
        return $obj
}

###

RTB/t/1.t  view on Meta::CPAN

# Insert your test code below, the Test::More module is use()ed here so read
# its man page ( perldoc Test::More ) for help writing this test script.

use strict;
use warnings;

my $rand;
$rand.=chr(rand(25)+65) for 1..10;
my $robot = Acme::RTB->new({    Name    => 'Anarion PerlBot 1.0',
                                Colour  => 'ff0000 ff0000',
                                Log     => "/tmp/$$-$rand.log"} );

ok( $robot );
ok( $robot->modify_action(  Radar           => \&my_radar    ) );
ok( $robot->RotateAmount(7, 0.5, 2) );

sub my_radar { }
unlink("/tmp/$$-$rand.log");



( run in 0.585 second using v1.01-cache-2.11-cpan-b61123c0432 )