User Control Panel
Advertisements

HELP US, HELP YOU!

4-Level Tic Tac Toe

 
Post new topic   Reply to topic    Bot Depot Forum Index -> Commands
View unanswered posts
Author Message
Cer
Upgraded Agent
Upgraded Agent


Joined: 03 Feb 2004
Posts: 3776
Location: Michigan
Reputation: 146.9
votes: 4

PostPosted: Wed Mar 16, 2005 1:49 am    Post subject: Reply with quote

This command is yet another Tic Tac Toe game. But unlike most other Tic Tac Toe games, this one has multiple difficulty levels.

Recent Leviathan versions "had" a Tic Tac Toe command, that command was this one but it was broken (it's probably existed for months, I just now got around to repairing it Wink ). So replace your commands/games/ttt.pl with the attached file.

QUOTE(Difficulty Levels)
Level 1 -- Computer is totally stupid
€ Computer randomly picks open spaces.
€ Earn 0 points if you win (because it's too easy to be worth any points).

Level 2 -- Computer is slightly smarter
€ 1 in 3 chance computer will block a two-in-a-row from the human.
€ If the computer didn't waste its move blocking yours, it will randomly pick an open space.
€ Earn 25 points for winning (it's still not too hard to defeat the computer).

Level 3 -- You MIGHT win
€ Computer ALWAYS blocks a two-in-a-row from the human.
€ If the computer didn't block a move, it will strategically make its next move
€ Earn 100 points for winning (this one's rather difficult).

Level 4 -- Computer NEVER loses!
€ Computer tries using the strategy of having two ways to win (where the opponent can block one, but not the other, and lose).
€ If its strategy fails, it will strategically make its next move.
€ It will always block two-in-a-row from the human.
€ Earn 1,000 points for winning (it should be impossible or very difficult to win).

Level 4 may be "Computer NEVER loses," but it doesn't mean "Computer ALWAYS wins" -- it either wins, or it forces the game to be a draw. It shouldn't be possible for a human to win. If you do manage to win, reply with how you did it so I can improve the command. Wink


This command may have a few bugs and glitches on it, if you find any of them then please reply here.

I realize a lot of the code is repeated, sometime later I'll go through and clean up the code a bit.

The Code
Code:
#      .   .               <Leviathan><br />#     .:...::     Command Name // !ttt<br />#    .::   ::.     Description // Tic Tac Toe.<br /># ..:;;. ' .;;:..        Usage // !ttt<br />#    .  '''  .     Permissions // Public.<br />#     :;,:,;:         Listener // All<br />#     :     :        Copyright // 2005 AiChaos Inc.<br /><br />sub ttt {<br />          my ($self,$client,$msg) = @_;<br /><br />          # Monospaced font to use.<br />          my $font = 'Courier New';<br /><br />          my $reply;<br /><br />          my %levels = (<br />                    1 => 'Computer is totally stupid',<br />                    2 => 'Computer is slightly smarter',<br />                    3 => 'You <i>MIGHT</i> win',<br />                    4 => 'Computer NEVER loses',<br />          );<br /><br />          # Number of points to reward for beating certain difficulties.<br />          my %pts = (<br />                    1 => 0,<br />                    2 => 25,<br />                    3 => 100,<br />                    4 => 1000,<br />          );<br /><br />          # New game?<br />          if ($chaos->{clients}->{$client}->{callback} !~ /^ttt/i) {<br />                    # Select a difficulty level.<br />                    $chaos->{clients}->{$client}->{callback} = 'ttt';<br />                    $chaos->{clients}->{$client}->{_ttt}->{status} = 'newgame';<br />                    return ":: Tic, Tac, Toe ::\n\n"<br />                              . "Select a difficulty level below (type the NUMBER next to "<br />                              . "the corresponding option):\n\n"<br />                              . "1 - $levels{1}\n"<br />                              . "2 - $levels{2}\n"<br />                              . "3 - $levels{3}\n"<br />                              . "4 - $levels{4}";<br />          }<br /><br />          # If they're JUST now selecting a difficulty.<br />          if ($chaos->{clients}->{$client}->{_ttt}->{status} eq 'newgame') {<br />                    my $num = $msg;<br /><br />                    return "You can only send me a NUMBER as difficulty level (from 1 to 4). Type "<br />                              . "$chaos->{config}->{command}ttt to see the list of difficulty levels."<br />                              if $msg =~ /[^0-9]/;<br /><br />                    return "Bad range. Difficulty levels range from 1 to 4." if ($num < 1 || $num > 4);<br /><br />                    $chaos->{clients}->{$client}->{_ttt}->{level} = $num;<br />                    $chaos->{clients}->{$client}->{_ttt}->{strat} = 0;      # For level 4.<br /><br />                    # Initilization.<br />                    $chaos->{clients}->{$client}->{callback} = "ttt";<br />                    $chaos->{clients}->{$client}->{_ttt}->{status} = "playing";<br />                    $chaos->{clients}->{$client}->{_ttt}->{a1} = '_';<br />                    $chaos->{clients}->{$client}->{_ttt}->{a2} = '_';<br />                    $chaos->{clients}->{$client}->{_ttt}->{a3} = ' ';<br />                    $chaos->{clients}->{$client}->{_ttt}->{b1} = '_';<br />                    $chaos->{clients}->{$client}->{_ttt}->{b2} = '_';<br />                    $chaos->{clients}->{$client}->{_ttt}->{b3} = ' ';<br />                    $chaos->{clients}->{$client}->{_ttt}->{c1} = '_';<br />                    $chaos->{clients}->{$client}->{_ttt}->{c2} = '_';<br />                    $chaos->{clients}->{$client}->{_ttt}->{c3} = ' ';<br /><br />                    # Return the starting board.<br />                    $reply = "Difficulty Level $chaos->{clients}->{$client}->{_ttt}->{level}\n\n"<br />                              . "  A B C\n"<br />                              . "1 _|_|_\n"<br />                              . "2 _|_|_\n"<br />                              . "3  | | \n\n"<br />                              . "Choose a coordinate (i.e. A2 or C3)";<br />          }<br />          elsif ($chaos->{clients}->{$client}->{_ttt}->{status} eq 'playing') {<br />                    # Quitting?<br />                    if ($msg =~ /quit/i) {<br />                              delete $chaos->{clients}->{$client}->{_ttt};<br />                              delete $chaos->{clients}->{$client}->{callback};<br />                              return "Game has been forfeited by remote player.";<br />                    }<br /><br />                    # Playing the game.<br />                    return "Give me a coordinate!" if length $msg == 0;<br /><br />                    # Make sure their coordinate is valid.<br />                    return "Invalid coordinate: coordinates are 2 characters long (ex. A3)" if length $msg > 2;<br />                    my ($letter,$num) = split(//, $msg, 2);<br />                    return "Invalid coordinate: must be one letter and one number (ex. A3)" if $letter =~ /[^ABCabc]/;<br />                    return "Invalid coordinate: must be one letter and one number (ex. A3)" if $num =~ /[^0-9]/;<br /><br />                    $msg = lc($msg);<br /><br />                    # Array of ways to win.<br />                    my @ways = (<br />                              'a1,b1,c1',<br />                              'a1,b2,c3',<br />                              'a1,a2,a3',<br />                              'a2,b2,c2',<br />                              'a3,b3,c3',<br />                              'b1,b2,b3',<br />                              'c1,b2,a3',<br />                              'c1,c2,c3',<br />                    );<br />                    # Array of all options.<br />                    my @opts = (<br />                              'a1', 'b1', 'c1',<br />                              'a2', 'b2', 'c2',<br />                              'a3', 'b3', 'c3',<br />                    );<br /><br />                    # Make sure the selected place is free.<br />                    if ($chaos->{clients}->{$client}->{_ttt}->{$msg} ne '_' && $chaos->{clients}->{$client}->{_ttt}->{$msg} ne ' ') {<br />                              return "That space is not available!";<br />                    }<br /><br />                    # Draw?<br />                    my $filled = 0;<br />                    foreach my $place (@opts) {<br />                              my $value = $chaos->{clients}->{$client}->{_ttt}->{$place};<br />                              if ($value ne '_' && $value ne ' ') {<br />                                        $filled++;<br />                              }<br />                    }<br />                    if ($filled >= 7) { # 7 now, plus 1 human and 1 computer = 9<br />                              delete $chaos->{clients}->{$client}->{_ttt};<br />                              delete $chaos->{clients}->{$client}->{callback};<br />                              return "This game is a draw.";<br />                    }<br /><br />                    # Mark them in that space.<br />                    $chaos->{clients}->{$client}->{_ttt}->{$msg} = 'X';<br /><br />                    my %marks = (<br />                              a1 => $chaos->{clients}->{$client}->{_ttt}->{a1},<br />                              b1 => $chaos->{clients}->{$client}->{_ttt}->{b1},<br />                              c1 => $chaos->{clients}->{$client}->{_ttt}->{c1},<br />                              a2 => $chaos->{clients}->{$client}->{_ttt}->{a2},<br />                              b2 => $chaos->{clients}->{$client}->{_ttt}->{b2},<br />                              c2 => $chaos->{clients}->{$client}->{_ttt}->{c2},<br />                              a3 => $chaos->{clients}->{$client}->{_ttt}->{a3},<br />                              b3 => $chaos->{clients}->{$client}->{_ttt}->{b3},<br />                              c3 => $chaos->{clients}->{$client}->{_ttt}->{c3},<br />                    );<br /><br />                    # See if somebody won.<br />                    foreach my $win (@ways) {<br />                              last if length $reply > 0;<br />                              my ($a,$b,$c) = split(/\,/, $win, 3);<br />                              my $one = $chaos->{clients}->{$client}->{_ttt}->{$a};<br />                              my $two = $chaos->{clients}->{$client}->{_ttt}->{$b};<br />                              my $three = $chaos->{clients}->{$client}->{_ttt}->{$c};<br /><br />                              # If the three match...<br />                              if ($one eq $two && $one eq $three && $one ne '_' && $one ne ' ') {<br />                                        # Start the reply.<br />                                        $reply = "Difficulty Level $chaos->{clients}->{$client}->{_ttt}->{level}\n\n"<br />                                                  . "  A B C\n"<br />                                                  . "1 $marks{a1}|$marks{b1}|$marks{c1}\n"<br />                                                  . "2 $marks{a2}|$marks{b2}|$marks{c2}\n"<br />                                                  . "3 $marks{a3}|$marks{b3}|$marks{c3}\n\n";<br /><br />                                        if ($one eq 'X') {<br />                                                  # Player wins!<br />                                                  # Give them points.<br />                                                  my $level = $chaos->{clients}->{$client}->{_ttt}->{level};<br />                                                  my $points = $pts{$level};<br />                                                  if ($points > 0) {<br />                                                            &modPoints($client,'+',$points);<br />                                                  }<br /><br />                                                  delete $chaos->{clients}->{$client}->{_ttt};<br />                                                  delete $chaos->{clients}->{$client}->{callback};<br />                                                  $reply .= "Remote Player ($client) has won! Given $points points.";<br />                                        }<br />                                        else {<br />                                                  # Computer wins!<br />                                                  delete $chaos->{clients}->{$client}->{_ttt};<br />                                                  delete $chaos->{clients}->{$client}->{callback};<br />                                                  $reply .= "Local Player (computer) has won!";<br />                                        }<br />                              }<br />                    }<br /><br />                    # Now for the computer's turn.<br />                    my $level = $chaos->{clients}->{$client}->{_ttt}->{level};<br /><br /><br />                    # Level 1 - Randomly pick a spot.<br />                    # Level 2 - Randomly pick spot; and randomly stop a 2-in-a-row from user.<br />                    # Level 3 - Strategically pick spot; always stop a 2-in-a-row from user.<br />                    # Level 4 - Always pick two-way methods; always stop 2-in-a-row from user.<br />                    my $chosen = 0;<br />                    my $give = 200;<br />                    if ($level == 1) {<br />                              # Until a spot is available...<br />                              while ($chosen == 0) {<br />                                        my $choice = $opts [ int(rand(scalar(@opts))) ];<br />                                        my $value = $chaos->{clients}->{$client}->{_ttt}->{$choice};<br /><br />                                        # If available...<br />                                        if ($value eq '_' || $value eq ' ') {<br />                                                  # Set it!<br />                                                  $chosen = 1;<br />                                                  $chaos->{clients}->{$client}->{_ttt}->{$choice} = 'O';<br />                                        }<br />                                        else {<br />                                                  # Try again...<br />                                                  $give--;<br /><br />                                                  if ($give <= 0) {<br />                                                            # Give up.<br />                                                            delete $chaos->{clients}->{$client}->{_ttt};<br />                                                            delete $chaos->{clients}->{$client}->{callback};<br />                                                            return "Unknown error: game has been terminated.";<br />                                                  }<br />                                        }<br />                              }<br />                    }<br />                    elsif ($level == 2) {<br />                              # Probability of stopping a 2-in-a-row: 1 in 3.<br />                              my $stop = int(rand(3)) + 1;<br />                              if ($stop == 1) {<br />                                        # Check for two-in-a-row's from the user.<br />                                        foreach my $path (@ways) {<br />                                                  last if $chosen == 1;<br />                                                  my ($a,$b,$c) = split(/\,/, $path, 3);<br />                                                  my $one = $chaos->{clients}->{$client}->{_ttt}->{$a};<br />                                                  my $two = $chaos->{clients}->{$client}->{_ttt}->{$b};<br />                                                  my $three = $chaos->{clients}->{$client}->{_ttt}->{$c};<br /><br />                                                  # Combinations: 1 & 2, 1 & 3, 2 & 3<br />                                                  if ($one eq 'X' && $one eq $two && $three ne 'O') {<br />                                                            # Steal spot three!<br />                                                            $chaos->{clients}->{$client}->{_ttt}->{$c} = 'O';<br />                                                            $chosen = 1;<br />                                                  }<br />                                                  elsif ($one eq 'X' && $one eq $three && $two ne 'O') {<br />                                                            # Steal spot two!<br />                                                            $chaos->{clients}->{$client}->{_ttt}->{$b} = 'O';<br />                                                            $chosen = 1;<br />                                                  }<br />                                                  elsif ($two eq 'X' && $two eq $three && $one ne 'O') {<br />                                                            # Steal spot one!<br />                                                            $chaos->{clients}->{$client}->{_ttt}->{$a} = 'O';<br />                                                            $chosen = 1;<br />                                                  }<br />                                        }<br />                              }<br /><br />                              # Now randomly choose a spot.<br />                              while ($chosen == 0) {<br />                                        my $choice = $opts [ int(rand(scalar(@opts))) ];<br />                                        my $value = $chaos->{clients}->{$client}->{_ttt}->{$choice};<br /><br />                                        # If available...<br />                                        if ($value eq '_' || $value eq ' ') {<br />                                                  # Set it!<br />                                                  $chosen = 1;<br />                                                  $chaos->{clients}->{$client}->{_ttt}->{$choice} = 'O';<br />                                        }<br />                                        else {<br />                                                  # Try again...<br />                                                  $give--;<br /><br />                                                  if ($give <= 0) {<br />                                                            # Give up.<br />                                                            delete $chaos->{clients}->{$client}->{_ttt};<br />                                                            delete $chaos->{clients}->{$client}->{callback};<br />                                                            return "Unknown error: game has been terminated.";<br />                                                  }<br />                                        }<br />                              }<br />                    }<br />                    elsif ($level == 3) {<br />                              # Always stop two-in-a-row's from the user.<br />                              foreach my $path (@ways) {<br />                                        last if $chosen == 1;<br />                                        my ($a,$b,$c) = split(/\,/, $path, 3);<br />                                        my $one = $chaos->{clients}->{$client}->{_ttt}->{$a};<br />                                        my $two = $chaos->{clients}->{$client}->{_ttt}->{$b};<br />                                        my $three = $chaos->{clients}->{$client}->{_ttt}->{$c};<br /><br />                                        # Combinations: 1 & 2, 1 & 3, 2 & 3<br />                                        if ($one eq 'X' && $one eq $two && $three ne 'O') {<br />                                                  # Steal spot three!<br />                                                  $chaos->{clients}->{$client}->{_ttt}->{$c} = 'O';<br />                                                  $chosen = 1;<br />                                        }<br />                                        elsif ($one eq 'X' && $one eq $three && $two ne 'O') {<br />                                                  # Steal spot two!<br />                                                  $chaos->{clients}->{$client}->{_ttt}->{$b} = 'O';<br />                                                  $chosen = 1;<br />                                        }<br />                                        elsif ($two eq 'X' && $two eq $three && $one ne 'O') {<br />                                                  # Steal spot one!<br />                                                  $chaos->{clients}->{$client}->{_ttt}->{$a} = 'O';<br />                                                  $chosen = 1;<br />                                        }<br />                              }<br /><br />                              # Strategically select a spot.<br />                              foreach my $path (@ways) {<br />                                        last if $chosen == 1;<br />                                        my ($a,$b,$c) = split(/\,/, $path, 3);<br />                                        my $one = $chaos->{clients}->{$client}->{_ttt}->{$a};<br />                                        my $two = $chaos->{clients}->{$client}->{_ttt}->{$b};<br />                                        my $three = $chaos->{clients}->{$client}->{_ttt}->{$c};<br /><br />                                        # Try to find open paths (---, O--, -O-, --O, O-O, OO-, -OO<br />                                        if ($one ne 'X' && $one ne 'O' && $two ne 'X' && $two ne 'O' && $three ne 'X' && $three ne 'O') {<br />                                                  # - - -<br />                                                  # Pick the middle one.<br />                                                  $chaos->{clients}->{$client}->{_ttt}->{$b} = 'O';<br />                                                  $chosen = 1;<br />                                        }<br />                                        elsif ($one eq 'O' && $two ne 'X' && $two ne 'O' && $three ne 'X' && $three ne 'O') {<br />                                                  # O - -<br />                                                  # Steal the third.<br />                                                  $chaos->{clients}->{$client}->{_ttt}->{$c} = 'O';<br />                                                  $chosen = 1;<br />                                        }<br />                                        elsif ($one ne 'X' && $one ne 'O' && $two eq 'O' && $three ne 'X' && $three ne 'O') {<br />                                                  # - O -<br />                                                  # Steal the first.<br />                                                  $chaos->{clients}->{$client}->{_ttt}->{$a} = 'O';<br />                                                  $chosen = 1;<br />                                        }<br />                                        elsif ($one ne 'X' && $one ne 'O' && $two ne 'X' && $two ne 'O' && $three ne 'X') {<br />                                                  # - - O<br />                                                  # Steal the first.<br />                                                  $chaos->{clients}->{$client}->{_ttt}->{$a} = 'O';<br />                                                  $chosen = 1;<br />                                        }<br />                                        elsif ($one eq 'O' && $two ne 'O' && $two ne 'X' && $three eq 'O') {<br />                                                  # O - O<br />                                                  # Finish!<br />                                                  $chaos->{clients}->{$client}->{_ttt}->{$b} = 'O';<br />                                                  $chosen = 1;<br />                                        }<br />                                        elsif ($one eq 'O' && $two eq 'O' && $three ne 'X') {<br />                                                  # O O -<br />                                                  # Finish!<br />                                                  $chaos->{clients}->{$client}->{_ttt}->{$c} = 'O';<br />                                                  $chosen = 1;<br />                                        }<br />                                        elsif ($one ne 'X' && $two eq 'O' && $three eq 'O') {<br />                                                  # - O O<br />                                                  # Finish!<br />                                                  $chaos->{clients}->{$client}->{_ttt}->{$a} = 'O';<br />                                                  $chosen = 1;<br />                                        }<br />                              }<br /><br />                              # If we can't think (or are doomed to not win), pick one randomly again.<br />                              while ($chosen == 0) {<br />                                        my $choice = $opts [ int(rand(scalar(@opts))) ];<br />                                        my $value = $chaos->{clients}->{$client}->{_ttt}->{$choice};<br /><br />                                        # If available...<br />                                        if ($value eq '_' || $value eq ' ') {<br />                                                  # Set it!<br />                                                  $chosen = 1;<br />                                                  $chaos->{clients}->{$client}->{_ttt}->{$choice} = 'O';<br />                                        }<br />                                        else {<br />                                                  # Try again...<br />                                                  $give--;<br /><br />                                                  if ($give <= 0) {<br />                                                            # Give up.<br />                                                            delete $chaos->{clients}->{$client}->{_ttt};<br />                                                            delete $chaos->{clients}->{$client}->{callback};<br />                                                            return "Unknown error: game has been terminated.";<br />                                                  }<br />                                        }<br />                              }<br />                    }<br />                    elsif ($level == 4) {<br />                              # Always stop two-in-a-row's from the user.<br />                              foreach my $path (@ways) {<br />                                        last if $chosen == 1;<br />                                        my ($a,$b,$c) = split(/\,/, $path, 3);<br />                                        my $one = $chaos->{clients}->{$client}->{_ttt}->{$a};<br />                                        my $two = $chaos->{clients}->{$client}->{_ttt}->{$b};<br />                                        my $three = $chaos->{clients}->{$client}->{_ttt}->{$c};<br /><br />                                        # Combinations: 1 & 2, 1 & 3, 2 & 3<br />                                        if ($one eq 'X' && $one eq $two && $three ne 'O') {<br />
[code:1:214cf3362c]                                        if ($one eq 'X' && $one eq $two && $three ne 'O') {<br />                                                  # Steal spot three!<br />                                                  $chaos->{clients}->{$client}->{_ttt}->{$c} = 'O';<br />                                                  $chosen = 1;<br />                                        }<br />                                        elsif ($one eq 'X' && $one eq $three && $two ne 'O') {<br />                                                  # Steal spot two!<br />                                                  $chaos->{clients}->{$client}->{_ttt}->{$b} = 'O';<br />                                                  $chosen = 1;<br />                                        }<br />                                        elsif ($two eq 'X' && $two eq $three && $one ne 'O') {<br />                                                  # Steal spot one!<br />                                                  $chaos->{clients}->{$client}->{_ttt}->{$a} = 'O';<br />                                                  $chosen = 1;<br />                                        }<br />                              }<br /><br />                              # The strategy.<br />                              my @stat = (<br />                                        'a1,c3,a3',<br />                                        'a1,c3,c1',<br />                                        'c1,a3,c3',<br />                                        'c1,a3,a1',<br />                              );<br /><br />                              # See if a strategy is available. If not, we can always prevent the human from winning!<br />                              foreach my $path (@strat) {<br />                                        last if $chosen == 1;<br />                                        my ($a,$b,$c) = split(/\,/, $path, 3);<br />                                        my $one = $chaos->{clients}->{$client}->{_ttt}->{$a};<br />                                        my $two = $chaos->{clients}->{$client}->{_ttt}->{$b};<br />                                        my $three = $chaos->{clients}->{$client}->{_ttt}->{$c};<br /><br />                                        # See if this strategy is going to work first.<br />                                        if ($chaos->{clients}->{$client}->{_ttt}->{strat} == 0) {<br />                                                  if ($one ne 'X' && $two ne 'X' && $three ne 'X') {<br />                                                            # This one looks good.<br />                                                            $chaos->{clients}->{$client}->{_ttt}->{strat} = $path;<br />                                                  }<br />                                                  else {<br />                                                            # No... better luck next time.<br />                                                            $chaos->{clients}->{$client}->{_ttt}->{strat} = 'failed';<br />                                                  }<br />                                        }<br />                              }<br /><br />                              # We can still prevent the human from winning!<br />                              while ($chosen == 0) {<br />                                        my $choice = $opts [ int(rand(scalar(@opts))) ];<br />                                        my $value = $chaos->{clients}->{$client}->{_ttt}->{$choice};<br /><br />                                        # If available...<br />                                        if ($value eq '_' || $value eq ' ') {<br />                                                  # Set it!<br />                                                  $chosen = 1;<br />                                                  $chaos->{clients}->{$client}->{_ttt}->{$choice} = 'O';<br />                                        }<br />                                        else {<br />                                                  # Try again...<br />                                                  $give--;<br /><br />                                                  if ($give <= 0) {<br />                                                            # Give up.<br />                                                            delete $chaos->{clients}->{$client}->{_ttt};<br />                                                            delete $chaos->{clients}->{$client}->{callback};<br />                                                            return "Unknown error: game has been terminated.";<br />                                                  }<br />                                        }<br />                              }<br />                    }<br />                    else {<br />                              $reply = "Not yet implemented." unless length $reply > 0;<br />                    }<br /><br />                    %marks = (<br />                              a1 => $chaos->{clients}->{$client}->{_ttt}->{a1},<br />                              b1 => $chaos->{clients}->{$client}->{_ttt}->{b1},<br />                              c1 => $chaos->{clients}->{$client}->{_ttt}->{c1},<br />                              a2 => $chaos->{clients}->{$client}->{_ttt}->{a2},<br />                              b2 => $chaos->{clients}->{$client}->{_ttt}->{b2},<br />                              c2 => $chaos->{clients}->{$client}->{_ttt}->{c2},<br />                              a3 => $chaos->{clients}->{$client}->{_ttt}->{a3},<br />                              b3 => $chaos->{clients}->{$client}->{_ttt}->{b3},<br />                              c3 => $chaos->{clients}->{$client}->{_ttt}->{c3},<br />                    );<br /><br />                    # See if somebody won.<br />                    foreach my $win (@ways) {<br />                              last if length $reply > 0;<br />                              my ($a,$b,$c) = split(/\,/, $win, 3);<br />                              my $one = $chaos->{clients}->{$client}->{_ttt}->{$a};<br />                              my $two = $chaos->{clients}->{$client}->{_ttt}->{$b};<br />                              my $three = $chaos->{clients}->{$client}->{_ttt}->{$c};<br /><br />                              # If the three match...<br />                              if ($one eq $two && $one eq $three && $one ne '_' && $one ne ' ') {<br />                                        # Start the reply.<br />                                        $reply = "Difficulty Level $chaos->{clients}->{$client}->{_ttt}->{level}\n\n"<br />                                                  . "  A B C\n"<br />                                                  . "1 $marks{a1}|$marks{b1}|$marks{c1}\n"<br />                                                  . "2 $marks{a2}|$marks{b2}|$marks{c2}\n"<br />                                                  . "3 $marks{a3}|$marks{b3}|$marks{c3}\n\n";<br /><br />                                        if ($one eq 'X') {<br />                                                  # Player wins!<br />                                                  # Give them points.<br />                                                  my $level = $chaos->{clients}->{$client}->{_ttt}->{level};<br />                                                  my $points = $pts{$level};<br />                                                  if ($points > 0) {<br />                                                            &modPoints($client,'+',$points);<br />                                                  }<br /><br />                                                  delete $chaos->{clients}->{$client}->{_ttt};<br />                                                  delete $chaos->{clients}->{$client}->{callback};<br />                                                  $reply .= "Remote Player ($client) has won! Given $points points.";<br />                                        }<br />                                        else {<br />                                                  # Computer wins!<br />                                                  delete $chaos->{clients}->{$client}->{_ttt};<br />                                                  delete $chaos->{clients}->{$client}->{callback};<br />                                                  $reply .= "Local Player (computer) has won!";<br />                                        }<br />                              }<br />                    }<br /><br />                    # Write out the board again.<br />                    if (length $reply == 0) {<br />                              my %board = (<br />                                        a1 => $chaos->{clients}->{$client}->{_ttt}->{a1},<br />                                        b1 => $chaos->{clients}->{$client}->{_ttt}->{b1},<br />                                        c1 => $chaos->{clients}->{$client}->{_ttt}->{c1},<br />                                        a2 => $chaos->{clients}->{$client}->{_ttt}->{a2},<br />                                        b2 => $chaos->{clients}->{$client}->{_ttt}->{b2},<br />                                        c2 => $chaos->{clients}->{$client}->{_ttt}->{c2},<br />                                        a3 => $chaos->{clients}->{$client}->{_ttt}->{a3},<br />                                        b3 => $chaos->{clients}->{$client}->{_ttt}->{b3},<br />                                        c3 => $chaos->{clients
_________________
Current Site (2008) http://www.cuvou.com/
Back to top
M4RTIN
Member
Member


Joined: 31 Dec 2004
Posts: 134

Reputation: 19.2Reputation: 19.2

PostPosted: Wed Mar 16, 2005 3:45 pm    Post subject: Reply with quote

Heh, Very nice bit of coding there.

I may use it for my bot.
Back to top
fusioncroc
Newbie
Newbie


Joined: 05 Feb 2005
Posts: 30
Location: England
Reputation: 15.8Reputation: 15.8

PostPosted: Wed Mar 16, 2005 8:21 pm    Post subject: Reply with quote

well done cer good to see yet more good programming from you Smile
Back to top
davidk
Senior Member
Senior Member


Joined: 14 Feb 2004
Posts: 195
Location: United Kingdom, Europe, Earth, Solar system, The Milky Way, The Universe, the 3rd Dimension.
Reputation: 31.1Reputation: 31.1Reputation: 31.1

PostPosted: Wed Mar 16, 2005 10:36 pm    Post subject: Reply with quote

OFF-TOPIC: I just beat level 4!
Back to top
Cer
Upgraded Agent
Upgraded Agent


Joined: 03 Feb 2004
Posts: 3776
Location: Michigan
Reputation: 146.9
votes: 4

PostPosted: Thu Mar 17, 2005 2:20 am    Post subject: Reply with quote

QUOTE(Cer @ Mar 15 2005, 08:49 PM)
If you do manage to win, reply with how you did it so I can improve the command. Wink


QUOTE(davidk @ Mar 16 2005, 05:36 PM)
OFF-TOPIC: I just beat level 4!
[right][snapback]46974[/snapback][/right]


It wasn't off-topic. But after I read through the code, I realized I messed up level 4, the computer picks a good strategy but never acts on it. Razz

So I'll continue working on the code a little. Smile

_________________
Current Site (2008) http://www.cuvou.com/
Back to top
JTW
God Like
God Like


Joined: 07 Mar 2004
Posts: 579
Location: Maidstone
Reputation: 67.1
votes: 4

PostPosted: Sun Mar 20, 2005 9:30 am    Post subject: Reply with quote

I think ive found another bug

Quote:
Difficulty Level 4
             
  A B C
1 x|O|_
2 x|O|_
3 x|x|O
             
Local Player (computer) has won!

But i was playing the X so surley i won?

_________________
"Help us, Help you" - BotDepot
Back to top
mouce
Newbie
Newbie


Joined: 17 May 2005
Posts: 1

Reputation: 11.9

PostPosted: Tue May 17, 2005 2:30 am    Post subject: Reply with quote

Rofl... easy, I just won on level 4 1,000 points. Is there a highscore system?
That would be cool.
Back to top
Cer
Upgraded Agent
Upgraded Agent


Joined: 03 Feb 2004
Posts: 3776
Location: Michigan
Reputation: 146.9
votes: 4

PostPosted: Tue May 17, 2005 11:36 am    Post subject: Reply with quote

QUOTE(mouce @ May 16 2005, 10:30 PM)
Rofl... easy, I just won on level 4 1,000 points. Is there a highscore system?
That would be cool.
[right][snapback]48339[/snapback][/right]


Yeah, I later discovered that the bot picks a strategy but doesn't follow it... so level 4 isn't hard to beat at all.

_________________
Current Site (2008) http://www.cuvou.com/
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: Tue May 17, 2005 5:48 pm    Post subject: Reply with quote

Why didn't you test it Razz?
_________________
~ Josh
[ Need bot hosting on a dedicated server? PM me. ]
Back to top
Cer
Upgraded Agent
Upgraded Agent


Joined: 03 Feb 2004
Posts: 3776
Location: Michigan
Reputation: 146.9
votes: 4

PostPosted: Tue May 17, 2005 6:37 pm    Post subject: Reply with quote

QUOTE(darkmonkey @ May 17 2005, 01:48 PM)
Why didn't you test it Razz?
[right][snapback]48352[/snapback][/right]


Often times my idea of "testing" is so that it appears to work. I.E. it wouldn't have a board with one O and one X and then say the computer won, stuff like that. I just didn't thoroughly test it. Razz

_________________
Current Site (2008) http://www.cuvou.com/
Back to top
jabbic
Newbie
Newbie


Joined: 27 Jul 2005
Posts: 6

Reputation: 9.6Reputation: 9.6Reputation: 9.6Reputation: 9.6Reputation: 9.6Reputation: 9.6Reputation: 9.6Reputation: 9.6Reputation: 9.6

PostPosted: Wed Jul 27, 2005 3:21 pm    Post subject: attachments Reply with quote

how do i download attachments???
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Bot Depot Forum Index -> Commands 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