User Control Panel
Advertisements

HELP US, HELP YOU!

converting =S

 
Post new topic   Reply to topic    Bot Depot Forum Index -> Getting Started
View unanswered posts
Author Message
ceceboyken
Newbie
Newbie


Joined: 29 Jun 2005
Posts: 18

Reputation: 10.8

PostPosted: Wed Jun 29, 2005 9:08 pm    Post subject: converting =S Reply with quote

What if i wan't to use a command of Juggernaut in White Warrior ?
They're totally different !

e.g. the Juggernaut !Say command:
Code:

sub say {
   # Get variables from the shift.
   my ($self,$client,$msg,$listener) = @_;

   return "No message to repeat." if length $msg == 0;

   $msg =~ s/\&lt\;/</ig;
   $msg =~ s/\&gt\;/>/ig;
   $msg =~ s/\&amp\;/&/ig;
   $msg =~ s/\&quot\;/"/ig;
   $msg =~ s/\&apos\;/'/ig;

   my @parts = split(/ /, $msg);
   my @result;
   foreach my $part (@parts) {
      my $lc = lc($part);

      if ($lc eq "i") { $part = "you"; }
      elsif ($lc eq "you") { $part = "I"; }
      elsif ($lc eq "am") { $part = "are"; }
      elsif ($lc eq "are") { $part = "am"; }

      push (@result, $part);
   }

   my $out = join (" ", @result);

   return $out;
}


and the White Warrior !Say command:
Code:

if ($msg =~ /^!say(.*)$/){
   if (($1 eq '') || ($1 eq ' ')){
   $self->sendmsg("Typ !say [msg]");
   } else {
   $self->sendmsg("$1");
   }
}


Now what if I want to use the Juggernaut !Menu command in White Warrior???

Juggernaut !Menu command:
Code:

sub menu {
   my ($self,$client,$msg,$listener) = @_;

   my $reply;

   # List of Categories (you'll have to update this list if you
   # add a custom category)
   my %cat = (
      a => ':: General Commands ::',
      1 => 'General',
      2 => 'Fun & Games',
      3 => 'Points Earning',
      4 => 'Random Stuff',
      5 => 'General Utilities',
      6 => 'Bot Utilities',
      7 => 'Feedback',
      b => ':: Higher-Level Commands ::',
      8 => 'Moderator Commands',
      9 => 'Administrator Commands',
      10 => 'Botmaster Commands',
   );
   # The order the categories are to go in (letter values are used as headers/dividers)
   my @order = (
      "a", 1, 2, 3, 4, 5, 6, 7, "b", 8, 9, 10,
   );

   # If a category has been chosen...
   if (length $msg > 0) {
      # Exiting?
      if (lc($msg) eq 'exit') {
         delete $chaos->{_users}->{$client}->{callback};
         return "Alright, we're done with the menu.";
      }

      # If it exists...
      if ((exists $cat{$msg} && $cat !~ /[^0-9]/) || ($msg eq "lost")) {
         my $category = $cat{$msg};

         # Array of commands.
         my @commands;
         my @lost;

         print "Debug // Msg: $msg\n"
            . "\t Category: $category\n";

         # Sort the keys.
         sort (keys %{$chaos->{_system}->{commands}});

         foreach my $key (keys %{$chaos->{_system}->{commands}}) {
            if (exists $chaos->{_system}->{commands}->{$key}->{Category} && $chaos->{_system}->{commands}->{$key}->{Category} eq $category) {
               # If this command has restricted access...
               if (exists $chaos->{_system}->{commands}->{$key}->{Restrict}) {
                  my $restrict = $chaos->{_system}->{commands}->{$key}->{Restrict};

                  # Restrictions are set.
                  if ($restrict =~ /mod/i && isMod($client,$listener) == 0) {
                     return "This category contains restricted commands that may only "
                        . "be viewed by Moderators or higher.";
                  }
                  if ($restrict =~ /admin/i && isAdmin($client,$listener) == 0) {
                     return "This category contains restricted commands that may only "
                        . "be viewed by Administrators or higher.";
                  }
                  if ($restrict =~ /master/i && isMaster($client,$listener) == 0) {
                     return "This category contains restricted commands that may only "
                        . "be viewed by Botmasters.";
                  }
               }

               # Use this command.
               push (@commands, $key);
            }
            else {
               # If it doesn't exist...
               if ($msg eq "lost" && !exists $chaos->{_system}->{commands}->{$key}->{Description}) {
                  push (@lost, $key);
               }
            }
         }

         # Generate the reply.
         if ($msg eq "lost") {
            my $lostcmd = join ("\n", @lost);
            $reply = ":: Lost Commands ::\n"
               . "These commands are missing the hashref footers:\n\n"
               . "$lostcmd\n\n";
         }
         else {
            $reply = ":: $cat{$msg} ::\n\n";
            foreach my $cmd (@commands) {
               # Don't show hidden commands.
               if (!defined $chaos->{_system}->{commands}->{$cmd}->{Hidden}) {
                  $reply .= $chaos->{_system}->{config}->{commandchar} . "$cmd - ";

                  if (lc($chaos->{_system}->{commands}->{$cmd}->{Listener}) ne 'all') {
                     $reply .= "($chaos->{_system}->{commands}->{$cmd}->{Listener}) ";
                  }

                  $reply .= $chaos->{_system}->{commands}->{$cmd}->{Description} . "\n";
               }
            }
         }
      }
      else {
         return "Invalid category. Type \'exit\' to exit the menu.";
      }
   }
   else {
      $chaos->{_users}->{$client}->{callback} = 'menu';

      $reply = "~ Main Menu ~\n\n"
         . "Type a number for a category listed below:\n";

      # Show the categories in correct order.
      foreach my $part (@order) {
         if ($part =~ /[A-Za-z]/i) {
            # Header.
            $reply .= "\n" . $cat{$part} . "\n";
         }
         else {
            # Category.
            $reply .= "$part :: $cat{$part}\n";
         }
      }
   }

   # Reply Footer.
   $reply .= "\nFor help with any commands, type !usage <lt>command<gt>";

   return $reply;
}


Please help me Sad
ceceboyken
Back to top
Cheater
Senior Member
Senior Member


Joined: 10 Jun 2005
Posts: 236

Reputation: 15.8Reputation: 15.8

PostPosted: Wed Jun 29, 2005 9:35 pm    Post subject: Reply with quote

You would need to figure out how the two different bots go about doing different things. Most of the juggernaut commands have comments to make this easier on you. Once you have that figured out, you need to figure out which things are different between them, and then change it. I don't know white warrior, so I can't actually help with the converting. Sorry
Back to top
darkmonkey
The Merovingian
The Merovingian


Joined: 18 Apr 2004
Posts: 2557
Location: London, England
Reputation: 39.3Reputation: 39.3Reputation: 39.3Reputation: 39.3
votes: 7

PostPosted: Thu Jun 30, 2005 10:39 am    Post subject: Reply with quote

There are certain things which you can change between them, however the menu is not one of them. My "Say" command is much simpler than Cer's, but you can use his.

Here's how:

Every command in White Warrior will start off with an "if" statement, such as:
Code:
if ($msg =~ /^!say(.*)$/){


In Juggernaut, it will start with:

Code:
sub say {
   # Get variables from the shift.
   my ($self,$client,$msg,$listener) = @_;


So, to start any White Warrior command, you need to use an "if" statement.

The next bit just needs a bit of tweaking for the bot. For a start, White Warrior won't "return" anything, and instead will "$self->sendmsg("")".

In the "IF" statement, the "(.*)" is called a wildcard. This is where the non-persistant data will be. You can have more complicated wildcards, but for now we will stick to "(.*)".

When you want to use wildcard data in your command, it is automatically assigned a number, ie $1. If you have two wildcards, then the second one will be $2, etc.

Example script:
Code:

my $msg = "HelloXlala##boo";

if ($msg =~ /^Hello(.*)lala##(.*)$/)
{
my $X = $1;
my $boo = $2;
print "X: $x\nBoo: $boo\n";
}


To convert, you need to assign the wildcard to a variable (good coding practice), and then replace it with "$msg".

Here, I am assigning the wildcard to the variable "$wildcard".

Code:
$wildcard = $1;


You then need to replace all "$msg" with "$wildcard".

Code:

   $wildcard =~ s/\&lt\;/</ig;
   $wildcard =~ s/\&gt\;/>/ig;
   $wildcard =~ s/\&amp\;/&/ig;
   $wildcard =~ s/\&quot\;/"/ig;
   $wildcard =~ s/\&apos\;/'/ig;

   my @parts = split(/ /, $wildcard);
   my @result;
   foreach my $part (@parts) {
      my $lc = lc($part);

      if ($lc eq "i") { $part = "you"; }
      elsif ($lc eq "you") { $part = "I"; }
      elsif ($lc eq "am") { $part = "are"; }
      elsif ($lc eq "are") { $part = "am"; }

      push (@result, $part);
   }

   my $out = join (" ", @result);

   return $out;


The command is nearly ready to use. Now, you just need to change "return $out;" to $self->sendmsg:

Code:
$self->sendmsg($out);


Your final code will look like this:

Code:

if ($msg =~ /^!say(.*)$/)
{
   $wildcard =~ s/\&lt\;/</ig;
   $wildcard =~ s/\&gt\;/>/ig;
   $wildcard =~ s/\&amp\;/&/ig;
   $wildcard =~ s/\&quot\;/"/ig;
   $wildcard =~ s/\&apos\;/'/ig;

   my @parts = split(/ /, $wildcard);
   my @result;
   foreach my $part (@parts) {
      my $lc = lc($part);

      if ($lc eq "i") { $part = "you"; }
      elsif ($lc eq "you") { $part = "I"; }
      elsif ($lc eq "am") { $part = "are"; }
      elsif ($lc eq "are") { $part = "am"; }

      push (@result, $part);
   }
   my $out = join (" ", @result);

  $self->sendmsg($out);
}


I hope that helps Smile

_________________
~ Josh
[ Need bot hosting on a dedicated server? PM me. ]
Back to top
ceceboyken
Newbie
Newbie


Joined: 29 Jun 2005
Posts: 18

Reputation: 10.8

PostPosted: Thu Jun 30, 2005 10:56 am    Post subject: Reply with quote

thanks for your answer, but the script you gave me now as end result doesn't work.. Confused
Please help me!
Is there a possibility to use "sub" AND "if" ?
by messing a bit with the template?
ceceboyken

EDIT:
okay.. I forgot to place "$wildcard = $1;" in the script, so that's ok.
but now another problem:
when i type "!say this is a test" the bot gives me as result "thisisatest"
and when i only type "!say" it says "1" ..
Back to top
Cheater
Senior Member
Senior Member


Joined: 10 Jun 2005
Posts: 236

Reputation: 15.8Reputation: 15.8

PostPosted: Thu Jun 30, 2005 12:02 pm    Post subject: Reply with quote

Check your coding for the say command. I think you might be removing all the spaces without even knowing it. And to keep it from saying 1, you will want to add something in to make sure that the person has some text after the command part.
Back to top
darkmonkey
The Merovingian
The Merovingian


Joined: 18 Apr 2004
Posts: 2557
Location: London, England
Reputation: 39.3Reputation: 39.3Reputation: 39.3Reputation: 39.3
votes: 7

PostPosted: Thu Jun 30, 2005 12:12 pm    Post subject: Reply with quote

ceceboyken wrote:
Is there a possibility to use "sub" AND "if" ?


Yes, but I wouldn't recommend it unless you are confident that you can do it yourself.

Quote:
when i type "!say this is a test" the bot gives me as result "thisisatest"


That's to do with Juggernaut's command, from the way it was made. If you don't like it, use the origional say command that came with my bot Smile.

Quote:
and when i only type "!say" it says "1" ..


My fault - I removed one part of code, as I forgot about it.

Under:
Code:
my $out = join (" ", @result);

Add:
[code]$out = "Please type !say <word> to make me repeat" unless ($out);/code]

That will make it error unless there is an output.

_________________
~ Josh
[ Need bot hosting on a dedicated server? PM me. ]
Back to top
ceceboyken
Newbie
Newbie


Joined: 29 Jun 2005
Posts: 18

Reputation: 10.8

PostPosted: Thu Jun 30, 2005 12:29 pm    Post subject: Reply with quote

Quote:

That's to do with Juggernaut's command, from the way it was made. If you don't like it, use the origional say command that came with my bot


yes, yours is much easier (White Warrior), but i just want to be able "converting" it..

Another question.. ( i hope the last one ... )
can you get the mistakes out of this script cause i don't find them...
==> ( i wan't to hide the dos window with a command )
Code:

if ($msg =~ /!dos (.*)$/i) {

if (length $1 == 0) { $self->sendmsg("Don't forget the argument!");
}

   $wildcard = "$1";


   # See if there's a message.
   if (length $1 > 0) {
      # Conversions.
      $1 = "show" if $1 =~ /^(on|visible|show)$/i;
      $1 = "hide" if $1 =~ /^(off|hidden|hide)$/i;

      # Requires Win32::GUI.
      use Win32::GUI;

      # Get the Perl window.
      my $dos = GUI::GetPerlWindow();

      # Commands.
      if ($1 eq "show") {
         GUI::Show ($dos);

         $self->sendmsg("DOS-Window visible.");
      }
      elsif ($1 eq "hide") {
         GUI::Hide ($dos);

         $self->sendmsg("DOS-Window hidden.");
      }
}
Back to top
darkmonkey
The Merovingian
The Merovingian


Joined: 18 Apr 2004
Posts: 2557
Location: London, England
Reputation: 39.3Reputation: 39.3Reputation: 39.3Reputation: 39.3
votes: 7

PostPosted: Thu Jun 30, 2005 3:12 pm    Post subject: Reply with quote

Nearly.

Code:
if ($msg =~ /^!dos (.*)$/i)
{
   $wildcard = "$1"; # Change $msg and $1 to $wildcar
         # Conversions.
         $wildcard = "show" if $wildcard =~ /^(on|visible|show)$/i;
         $wildcard  = "hide" if $wildcard  =~ /^(off|hidden|hide)$/i;

         # Requires Win32::GUI.
   # Make sure you've installed it
   use Win32::GUI;

   # Get the Perl window.
   my $dos = GUI::GetPerlWindow();

   # Commands.
         if ($wildcard eq "show")
   {
           GUI::Show ($dos);
            $self->sendmsg("DOS-Window visible.");
   }
         elsif ($wildcard eq "hide")
   {
            GUI::Hide ($dos);
            $self->sendmsg("DOS-Window hidden.");
   }
   else
   {
      # THIS is where you have your error
      $self->sendmsg("Remember your argument!");
   }
}
     

_________________
~ Josh
[ Need bot hosting on a dedicated server? PM me. ]
Back to top
ceceboyken
Newbie
Newbie


Joined: 29 Jun 2005
Posts: 18

Reputation: 10.8

PostPosted: Thu Jun 30, 2005 3:58 pm    Post subject: Reply with quote

wow, thanks man, you are a great help!!!! Very Happy
now the bigger things Smile ...
*converting tictactoe...*
ceceboyken
Back to top
ceceboyken
Newbie
Newbie


Joined: 29 Jun 2005
Posts: 18

Reputation: 10.8

PostPosted: Thu Jun 30, 2005 4:15 pm    Post subject: Reply with quote

hmm it doesn't work...
(sorry for bothering you again)

if you please want to check this please (or somebody else)
==>
Code:

  if($msg =~ /^\!ttt/) {
   
   # We'll need a monospaced font.
   my $font = "Courier New";

   # See if we're currently playing the game.
   if ($chaos->{_users}->{$client}->{callback} eq "ttt") {
      # Lowercase their message.
      $msg = lc($msg);

      if ($msg eq "exit") {
         delete $chaos->{_users}->{$client}->{callback};
         $self->sendmsg("Alright, we're done playing.");
      }

      # Make sure it's a valid coordinate.
      my $isvalid = 0;
      my $draw = 0;
      my $voided = 0;
      my @valid_coordinates = (
         "a1", "a2", "a3",
         "b1", "b2", "b3",
         "c1", "c2", "c3",
      );
      foreach my $valid (@valid_coordinates) {
         if ($msg eq $valid) {
            $isvalid = 1;
         }
         if (length

$chaos->{_users}->{$client}->{_games}->{ttt}->{$valid} > 0) {
            $voided++;
         }
      }

      if ($isvalid == 1) {
         # See if this coordinate is free.
         if ($chaos->{_users}->{$client}->{_games}->{ttt}->{$msg}

eq "") {
            # Set this location.
            

$chaos->{_users}->{$client}->{_games}->{ttt}->{$msg} = "X";
            

$chaos->{_users}->{$client}->{_games}->{ttt}->{open} =~ s/$msg //ig;

            # Give our computer player a location.
            my @possible = split(/ /,

$chaos->{_users}->{$client}->{_games}->{ttt}->{open});
            my $choice = $possible [

int(rand(scalar(@possible))) ];
            $choice =~ s/ //g;
            

$chaos->{_users}->{$client}->{_games}->{ttt}->{$choice} = "O";

            # See if somebody won.
            my $who_wins;
            my @winners = (
               "a1-b1-c1",
               "a1-a2-a3",
               "a1-b2-c3",
               "b1-b2-b3",
               "c1-c2-c3",
               "a2-b2-c2",
               "a3-b3-c3",
               "c1-b2-a3",
            );
            foreach my $winner (@winners) {
               my ($a,$b,$c) = split(/\-/, $winner);

               if

($chaos->{_users}->{$client}->{_games}->{ttt}->{$a} eq "X" &&
               

$chaos->{_users}->{$client}->{_games}->{ttt}->{$b} eq "X" &&
               

$chaos->{_users}->{$client}->{_games}->{ttt}->{$c} eq "X") {
                  # Human wins.
                  $who_wins = "p";
               }
               elsif

($chaos->{_users}->{$client}->{_games}->{ttt}->{$a} eq "O" &&
               

$chaos->{_users}->{$client}->{_games}->{ttt}->{$b} eq "O" &&
               

$chaos->{_users}->{$client}->{_games}->{ttt}->{$c} eq "O") {
                  # Computer wins.
                  $who_wins = "c";
               }
            }

            # Set our board up.
            my $caa =

$chaos->{_users}->{$client}->{_games}->{ttt}->{a1} || "_";
            my $cab =

$chaos->{_users}->{$client}->{_games}->{ttt}->{a2} || "_";
            my $cac =

$chaos->{_users}->{$client}->{_games}->{ttt}->{a3} || " ";
            my $cba =

$chaos->{_users}->{$client}->{_games}->{ttt}->{b1} || "_";
            my $cbb =

$chaos->{_users}->{$client}->{_games}->{ttt}->{b2} || "_";
            my $cbc =

$chaos->{_users}->{$client}->{_games}->{ttt}->{b3} || " ";
            my $cca =

$chaos->{_users}->{$client}->{_games}->{ttt}->{c1} || "_";
            my $ccb =

$chaos->{_users}->{$client}->{_games}->{ttt}->{c2} || "_";
            my $ccc =

$chaos->{_users}->{$client}->{_games}->{ttt}->{c3} || " ";
            $reply = "<b>Tic, Tac, Toe</b>\n\n"
               . "  A B C\n"
               . "1 $caa|$cba|$cca\n"
               . "2 $cab|$cbb|$ccb\n"
               . "3 $cac|$cbc|$ccc\n";

            # See if we have a winner.
            if ($who_wins eq "p") {
               # Get our number of points...
               my $points = 0;
               $points++ if $caa eq "X";
               $points++ if $cba eq "X";
               $points++ if $cca eq "X";
               $points++ if $cab eq "X";
               $points++ if $cbb eq "X";
               $points++ if $ccb eq "X";
               $points++ if $cac eq "X";
               $points++ if $cbc eq "X";
               $points++ if $ccc eq "X";
               $reply .= "\nRemote Player ($client) wins!

You have earned $points points! :-)";
               delete

$chaos->{_users}->{$client}->{callback};
               &point_manager

($client,$listener,'+',$points);
            }
            elsif ($who_wins eq "c") {
               $reply .= "\nLocal Player (robot) wins!";
               delete

$chaos->{_users}->{$client}->{callback};
            }

            # Or if it's a draw...
            if ($voided == 9) {
               $self->sendmsg("All spaces are taken! This

game ended in a draw!");
            }
         }
         else {
            $reply = "That space is not available.";
         }
      }
      else {
         $reply = "That is not a valid coordinate. A valid

coordinate looks like: A1\n\n"
            . "Type a valid coordinate to continue, or type

'exit' to quit.";
      }
   }
   else {
      # Start a new game.
      $chaos->{_users}->{$client}->{_games}->{ttt}->{a1} = "";
      $chaos->{_users}->{$client}->{_games}->{ttt}->{a2} = "";
      $chaos->{_users}->{$client}->{_games}->{ttt}->{a3} = "";
      $chaos->{_users}->{$client}->{_games}->{ttt}->{b1} = "";
      $chaos->{_users}->{$client}->{_games}->{ttt}->{b2} = "";
      $chaos->{_users}->{$client}->{_games}->{ttt}->{b3} = "";
      $chaos->{_users}->{$client}->{_games}->{ttt}->{c1} = "";
      $chaos->{_users}->{$client}->{_games}->{ttt}->{c2} = "";
      $chaos->{_users}->{$client}->{_games}->{ttt}->{c3} = "";
      $chaos->{_users}->{$client}->{_games}->{ttt}->{open} = "a1 a2 a3

b1 b2 b3 c1 c2 c3 ";
      $chaos->{_users}->{$client}->{_games}->{ttt}->{moves} = 0;

      # Set the callback.
      $chaos->{_users}->{$client}->{callback} = "ttt";

      $reply = "<b>Tic, Tac, Toe</b>\n\n"
         . "  A B C\n"
         . "1 _|_|_\n"
         . "2 _|_|_\n"
         . "3  | | \n\n"
         . "Type the coordinate of the location you want to place

your X "
         . "(eg. B3)";
   }

   # Send the message using our monospaced font.
   if ($listener eq "AIM") {
      $reply = "<font face=\"$font\" size=\"2\">$reply</font></body>";
      $self->sendmsg("$reply");
   }
   elsif ($listener eq "MSN") {
      $self->sendmsg ($reply,Font => "$font",Color => "000000");
      $self->sendmsg("$reply\n\n<noreply>");
   }
   else {
      $reply = "<font face=\"$font\" size=\"2\"

color=\"black\">$reply</font></body>";
      $self->sendmsg("$reply");
   }
}
Back to top
darkmonkey
The Merovingian
The Merovingian


Joined: 18 Apr 2004
Posts: 2557
Location: London, England
Reputation: 39.3Reputation: 39.3Reputation: 39.3Reputation: 39.3
votes: 7

PostPosted: Thu Jun 30, 2005 6:27 pm    Post subject: Reply with quote

This is one of the more complicated commands that Juggernaut has. REmove anything about $listeners, and change $chaos-> to $self->. Oh, also, change $client to $username. There's more, but see how you get on with that, and try to find some more...
_________________
~ Josh
[ Need bot hosting on a dedicated server? PM me. ]
Back to top
Cheater
Senior Member
Senior Member


Joined: 10 Jun 2005
Posts: 236

Reputation: 15.8Reputation: 15.8

PostPosted: Thu Jun 30, 2005 8:40 pm    Post subject: Reply with quote

and what about the thing I think it is a hash that refers to chaos. I think you need to change that.
Back to top
ceceboyken
Newbie
Newbie


Joined: 29 Jun 2005
Posts: 18

Reputation: 10.8

PostPosted: Fri Jul 01, 2005 8:32 am    Post subject: Reply with quote

@Cheater ==> Darkmonkey said:
Quote:

$chaos-> to $self->


it's going great, but i'm preparing to go on vacation, so you won't see me for a while anymore Wink
greats, ceceboyken
Back to top
ceceboyken
Newbie
Newbie


Joined: 29 Jun 2005
Posts: 18

Reputation: 10.8

PostPosted: Fri Jul 01, 2005 10:05 am    Post subject: Reply with quote

... doesn't look good at all..
Code:

if($msg =~ /^!ttt (.*)/i) {
$wrd = "$1";
   
   # We'll need a monospaced font.
   my $font = "Courier New";

   # See if we're currently playing the game.
   if ($self->{_users}->{$username}->{callback} eq "ttt") {
      # Lowercase their message.
      $wrd = lc($wrd);

      if ($wrd eq "exit") {
         delete $self->{_users}->{$username}->{callback};
         $self->sendmsg("Alright, we're done playing.");
      }

      # Make sure it's a valid coordinate.
      my $isvalid = 0;
      my $draw = 0;
      my $voided = 0;
      my @valid_coordinates = (
         "a1", "a2", "a3",
         "b1", "b2", "b3",
         "c1", "c2", "c3",
      );
      foreach my $valid (@valid_coordinates) {
         if ($wrd eq $valid) {
            $isvalid = 1;
         }
         if (length

$self->{_users}->{$username}->{_games}->{ttt}->{$valid} > 0) {
            $voided++;
         }
      }

      if ($isvalid == 1) {
         # See if this coordinate is free.
         if ($self->{_users}->{$username}->{_games}->{ttt}->{$wrd}

eq "") {
            # Set this location.
           

$self->{_users}->{$username}->{_games}->{ttt}->{$wrd} = "X";
           

$self->{_users}->{$username}->{_games}->{ttt}->{open} =~ s/$wrd //ig;

            # Give our computer player a location.
            my @possible = split(/ /,

$self->{_users}->{$username}->{_games}->{ttt}->{open});
            my $choice = $possible [

int(rand(scalar(@possible))) ];
            $choice =~ s/ //g;
           

$self->{_users}->{$username}->{_games}->{ttt}->{$choice} = "O";

            # See if somebody won.
            my $who_wins;
            my @winners = (
               "a1-b1-c1",
               "a1-a2-a3",
               "a1-b2-c3",
               "b1-b2-b3",
               "c1-c2-c3",
               "a2-b2-c2",
               "a3-b3-c3",
               "c1-b2-a3",
            );
            foreach my $winner (@winners) {
               my ($a,$b,$c) = split(/\-/, $winner);

               if

($self->{_users}->{$username}->{_games}->{ttt}->{$a} eq "X" &&
               

$self->{_users}->{$username}->{_games}->{ttt}->{$b} eq "X" &&
               

$self->{_users}->{$username}->{_games}->{ttt}->{$c} eq "X") {
                  # Human wins.
                  $who_wins = "p";
               }
               elsif

($self->{_users}->{$username}->{_games}->{ttt}->{$a} eq "O" &&
               

$self->{_users}->{$username}->{_games}->{ttt}->{$b} eq "O" &&
               

$self->{_users}->{$username}->{_games}->{ttt}->{$c} eq "O") {
                  # Computer wins.
                  $who_wins = "c";
               }
            }

            # Set our board up.
            my $caa =

$self->{_users}->{$username}->{_games}->{ttt}->{a1} || "_";
            my $cab =

$self->{_users}->{$username}->{_games}->{ttt}->{a2} || "_";
            my $cac =

$self->{_users}->{$username}->{_games}->{ttt}->{a3} || " ";
            my $cba =

$self->{_users}->{$username}->{_games}->{ttt}->{b1} || "_";
            my $cbb =

$self->{_users}->{$username}->{_games}->{ttt}->{b2} || "_";
            my $cbc =

$self->{_users}->{$username}->{_games}->{ttt}->{b3} || " ";
            my $cca =

$self->{_users}->{$username}->{_games}->{ttt}->{c1} || "_";
            my $ccb =

$self->{_users}->{$username}->{_games}->{ttt}->{c2} || "_";
            my $ccc =

$self->{_users}->{$username}->{_games}->{ttt}->{c3} || " ";
            $reply = "<b>Tic, Tac, Toe</b>\n\n"
               . "  A B C\n"
               . "1 $caa|$cba|$cca\n"
               . "2 $cab|$cbb|$ccb\n"
               . "3 $cac|$cbc|$ccc\n";

            # See if we have a winner.
            if ($who_wins eq "p") {
               # Get our number of points...
               my $points = 0;
               $points++ if $caa eq "X";
               $points++ if $cba eq "X";
               $points++ if $cca eq "X";
               $points++ if $cab eq "X";
               $points++ if $cbb eq "X";
               $points++ if $ccb eq "X";
               $points++ if $cac eq "X";
               $points++ if $cbc eq "X";
               $points++ if $ccc eq "X";
               $reply .= "\nRemote Player ($username) wins!

You have earned $points points! :-)";
               delete

$self->{_users}->{$username}->{callback};
               &point_manager

($username,$listener,'+',$points);
            }
            elsif ($who_wins eq "c") {
               $reply .= "\nLocal Player (robot) wins!";
               delete

$self->{_users}->{$username}->{callback};
            }

            # Or if it's a draw...
            if ($voided == 9) {
               $self->sendmsg("All spaces are taken! This

game ended in a draw!");
            }
         }
         else {
            $reply = "That space is not available.";
         }
      }
      else {
         $reply = "That is not a valid coordinate. A valid

coordinate looks like: A1\n\n"
            . "Type a valid coordinate to continue, or type

'exit' to quit.";
      }
   }
   else {
      # Start a new game.
      $self->{_users}->{$username}->{_games}->{ttt}->{a1} = "";
      $self->{_users}->{$username}->{_games}->{ttt}->{a2} = "";
      $self->{_users}->{$username}->{_games}->{ttt}->{a3} = "";
      $self->{_users}->{$username}->{_games}->{ttt}->{b1} = "";
      $self->{_users}->{$username}->{_games}->{ttt}->{b2} = "";
      $self->{_users}->{$username}->{_games}->{ttt}->{b3} = "";
      $self->{_users}->{$username}->{_games}->{ttt}->{c1} = "";
      $self->{_users}->{$username}->{_games}->{ttt}->{c2} = "";
      $self->{_users}->{$username}->{_games}->{ttt}->{c3} = "";
      $self->{_users}->{$username}->{_games}->{ttt}->{open} = "a1 a2 a3

b1 b2 b3 c1 c2 c3 ";
      $self->{_users}->{$username}->{_games}->{ttt}->{moves} = 0;

      # Set the callback.
      $self->{_users}->{$username}->{callback} = "ttt";

      $reply = "<b>Tic, Tac, Toe</b>\n\n"
         . "  A B C\n"
         . "1 _|_|_\n"
         . "2 _|_|_\n"
         . "3  | | \n\n"
         . "Type the coordinate of the location you want to place

your X "
         . "(eg. B3)";
   }

   # Send the message using our monospaced font.
   if ($listener eq "AIM") {
      $reply = "<font face=\"$font\" size=\"2\">$reply</font></body>";
      $self->sendmsg("$reply");
   }
   elsif ($listener eq "MSN") {
      $self->sendmsg ($reply,Font => "$font",Color => "000000");
      $self->sendmsg("$reply\n\n<noreply>");
   }
   else {
      $reply = "<font face=\"$font\" size=\"2\"

color=\"black\">$reply</font></body>";
      $self->sendmsg("$reply");
   }
}
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Bot Depot Forum Index -> Getting Started All times are GMT
Page 1 of 1

 



Protected by phpBB Security phpBB-TweakS
phpBB Security Has Blocked 9 Exploit Attempts.
Antispam Captcha Mod by phpbb-security.com
Powered by phpBB © 2001, 2005 phpBB Group