From ce013cfad91705e8a26010a3a8e34a3de0745798 Mon Sep 17 00:00:00 2001 From: kbrannen Date: Sun, 21 May 2023 15:12:41 -0500 Subject: [PATCH 1/3] added checkers for perl --- 23_Checkers/perl/README.md | 6 + 23_Checkers/perl/checkers.pl | 343 +++++++++++++++++++++++++++++++++++ 2 files changed, 349 insertions(+) create mode 100755 23_Checkers/perl/checkers.pl diff --git a/23_Checkers/perl/README.md b/23_Checkers/perl/README.md index e69c8b81..4323cf4a 100644 --- a/23_Checkers/perl/README.md +++ b/23_Checkers/perl/README.md @@ -1,3 +1,9 @@ Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html) Conversion to [Perl](https://www.perl.org/) + +Note: This version has lines and columns numbers to help you with choosing the cell +to move from and to, so you don't have to continually count. It also puts a "." only for +blank cells you can move to, which I think makes for a more pleasing look and makes +it easier to play. If you want the original behavior, start the program with an arg +of "-o" for the original behavior. diff --git a/23_Checkers/perl/checkers.pl b/23_Checkers/perl/checkers.pl new file mode 100755 index 00000000..9e87f1fe --- /dev/null +++ b/23_Checkers/perl/checkers.pl @@ -0,0 +1,343 @@ +#!/usr/bin/perl + +# Boxing program in Perl +# Started with checkers.annotated.bas +# Translated by Kevin Brannen (kbrannen) + +use strict; +use warnings; + +# globals +# +# The current move: (rating, current x, current y, new x, new y) +# 'rating' represents how good the move is; higher is better. +my @r = (-99); # (4); # Start with minimum score +# The board. Pieces are represented by numeric values: +# +# - 0 = empty square +# - -1,-2 = X (-1 for regular piece, -2 for king) +# - 1,2 = O (1 for regular piece, 2 for king) +# +# This program's player ("me") plays X. +my @s; # (7,7) +# chars to print for the board, add 2 to the board value as an index to the char +my @chars = ("X*", "X", ".", "O", "O*"); +my $g = -1; # constant holding -1 +my $winner = ""; +my $upgrade = shift(@ARGV) // ""; +$upgrade = $upgrade eq "-o" ? 0 : 1; + +##### + +print "\n"; +print " " x 32, "CHECKERS\n"; +print " " x 15, "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n\n\n"; + + +print "THIS IS THE GAME OF CHECKERS. THE COMPUTER IS X,\n"; +print "AND YOU ARE O. THE COMPUTER WILL MOVE FIRST.\n"; +print "SQUARES ARE REFERRED TO BY A COORDINATE SYSTEM.\n"; +print "(0,0) IS THE LOWER LEFT CORNER\n"; +print "(0,7) IS THE UPPER LEFT CORNER\n"; +print "(7,0) IS THE LOWER RIGHT CORNER\n"; +print "(7,7) IS THE UPPER RIGHT CORNER\n"; +print "THE COMPUTER WILL TYPE '+TO' WHEN YOU HAVE ANOTHER\n"; +print "JUMP. TYPE TWO NEGATIVE NUMBERS IF YOU CANNOT JUMP.\n\n\n"; + +# Initialize the board. Data is 2 length-wise strips repeated. +my @data = (); +for (1 .. 32) { push(@data, (1,0,1,0,0,0,-1,0, 0,1,0,0,0,-1,0,-1)); } +for my $x (0 .. 7) +{ + for my $y (0 .. 7) + { + $s[$x][$y] = shift(@data); + } +} + +# Start of game loop. First, my turn. +while (1) +{ + + # For each square on the board, search for one of my pieces + # and if it can make the best move so far, store that move in 'r' + for my $x (0 .. 7) + { + for my $y (0 .. 7) + { + # Skip if this is empty or an opponent's piece + next if ($s[$x][$y] > -1); + + # If this is one of my ordinary pieces, analyze possible + # forward moves. + if ($s[$x][$y] == -1) + { + for (my $a = -1 ; $a <= 1 ; $a +=2) + { + $b = $g; + find_move($x, $y, $a, $b); + } + } + + # If this is one of my kings, analyze possible forward + # and backward moves. + if ($s[$x][$y] == -2) + { + for (my $a = -1 ; $a <= 1 ; $a += 2) + { + for (my $b = -1 ; $a <= 1 ; $b += 2) { find_move($x, $y, $a, $b); } + } + } + } + } + + + if ($r[0] == -99) # Game is lost if no move could be found. + { + $winner = "you"; + last; + } + + # Print the computer's move. (Note: chr$(30) is an ASCII RS + # (record separator) code; probably no longer relevant.) + print "FROM $r[1],$r[2] TO $r[3],$r[4] "; + $r[0] = -99; + + # Make the computer's move. If the piece finds its way to the + # end of the board, crown it. + LOOP1240: { + if ($r[4] == 0) + { + $s[$r[3]][$r[4]] = -2; + last LOOP1240; + } + $s[$r[3]][$r[4]] = $s[$r[1]][$r[2]]; + $s[$r[1]][$r[2]] = 0; + + # If the piece has jumped 2 squares, it means the computer has + # taken an opponents' piece. + if (abs($r[1] - $r[3]) == 2) + { + $s [($r[1]+$r[3])/2] [($r[2]+$r[4])/2] = 0; # Delete the opponent's piece + + # See if we can jump again. Evaluate all possible moves. + my $x = $r[3]; + my $y = $r[4]; + for (my $a = -2 ; $a <= 2 ; $a += 4) + { + if ($s[$x][$y] == -1) + { + $b = -2; + eval_move($x, $y, $a, $b); + } + if ($s[$x][$y] == -2) + { + for (my $b = -2 ; $b <= 2 ; $b += 4) { eval_move($x, $y, $a, $b); } + } + } + + # If we've found a move, go back and make that one as well + if ($r[0] != -99) + { + print "TO $r[3], $r[4] "; + $r[0] = -99; + next LOOP1240; + } + } + } # LOOP1240 + + # Now, print the board + print "\n\n\n"; + for (my $y = 7 ; $y >= 0 ; $y--) + { + my $line = ""; + $line = "$y|" if ($upgrade); + for my $x (0 .. 7) + { + my $c = $chars[$s[$x][$y] + 2]; + $c = ' ' if ($upgrade && (($y % 2 == 0 && $x % 2 == 1) || ($y % 2 == 1 && $x % 2 == 0))); + $line = tab($line, 5*$x+7, $c); + } + print $line; + print " \n\n"; + } + print " _ _ _ _ _ _ _ _\n" if ($upgrade); + print " 0 1 2 3 4 5 6 7\n" if ($upgrade); + print "\n"; + + # Check if either player is out of pieces. If so, announce the + # winner. + my ($z, $t) = (0, 0); + for my $x (0 .. 7) + { + for my $y (0 .. 7) + { + if ($s[$x][$y] == 1 || $s[$x][$y] == 2) { $z = 1; } + if ($s[$x][$y] == -1 || $s[$x][$y] == -2) { $t = 1; } + } + } + if ($z != 1) { $winner = "comp"; last; } + if ($t != 1) { $winner = "you"; last; } + + # Prompt the player for their move. + ($z, $t) = (0, 0); + my ($x, $y, $e, $h, $a, $b); + do { + print "FROM: "; + chomp(my $ans = <>); + ($e,$h) = split(/[, ]/, $ans); + $x = $e; + $y = $h; + } while ($s[$x][$y] <= 0); + do { + print "TO: "; + chomp(my $ans = <>); + ($a,$b) = split(/[, ]/, $ans); + $x = $a; + $y = $b; + } while (!($s[$x][$y] == 0 && abs($a-$e) <= 2 && abs($a-$e) == abs($b-$h))); + + LOOP1750: { + # Make the move and stop unless it might be a jump. + $s[$a][$b] = $s[$e][$h]; + $s[$e][$h] = 0; + if (abs($e-$a) != 2) { last LOOP1750; } + + # Remove the piece jumped over + $s[($e+$a)/2][($h+$b)/2] = 0; + + # Prompt for another move; -1 means player can't, so I've won. + # Keep prompting until there's a valid move or the player gives + # up. + my ($a1, $b1); + do { + print "+TO "; + chomp(my $ans = <>); + ($a1,$b1) = split(/[, ]/, $ans); + if ($a1 < 0) { last LOOP1750; } + } while ($s[$a1][$b1] != 0 || abs($a1-$a) != 2 || abs($b1-$b) != 2); + + # Update the move variables to correspond to the next jump + $e = $a; + $h = $b; + $a = $a1; + $b = $b1; + } + + # If the player has reached the end of the board, crown this piece + if ($b == 7) { $s[$a][$b] = 2; } + + # And play the next turn. +} + +# Endgame: +print "\n", ($winner eq "you" ? "YOU" : "I"), " WIN\n"; +exit(0); + +########################################### + +# deal with basic's tab() for line positioning +# line = line string we're starting with +# pos = position to start writing +# s = string to write +# returns the resultant string, which might not have been changed +sub tab +{ + my ($line, $pos, $s) = @_; + my $len = length($line); + # if curser is past position, do nothing + if ($len <= $pos) { $line .= " " x ($pos - $len) . $s; } + return $line; +} + +# Analyze a move from (x,y) to (x+a, y+b) and schedule it if it's +# the best candidate so far. +sub find_move +{ + my ($x, $y, $a, $b) = @_; + my $u = $x+$a; + my $v = $y+$b; + + # Done if it's off the board + return if ($u < 0 || $u > 7 || $v < 0 || $ v> 7); + + # Consider the destination if it's empty + eval_jump($x, $y, $u, $v) if ($s[$u][$v] == 0); + + # If it's got an opponent's piece, jump it instead + if ($s[$u][$v] > 0) + { + + # Restore u and v, then return if it's off the board + $u += $a; + $v += $b; + return if ($u < 0 || $v < 0 || $u > 7 || $v > 7); + + # Otherwise, consider u,v + eval_jump($x, $y, $u, $v) if ($s[$u][$v] == 0); + } +} + +# Evaluate jumping (x,y) to (u,v). +# +# Computes a score for the proposed move and if it's higher +# than the best-so-far move, uses that instead by storing it +# and its score in @r. +sub eval_jump +{ + my ($x, $y, $u, $v) = @_; + + # q is the score; it starts at 0 + my $q = 0; + + # +2 if it promotes this piece + $q += 2 if ($v == 0 && $s[$x][$y] == -1); + + # +5 if it takes an opponent's piece + $q += 5 if (abs($y-$v) == 2); + + # -2 if the piece is moving away from the top boundary + $q -= 2 if ($y == 7); + + # +1 for putting the piece against a vertical boundary + $q++ if ($u == 0 || $u == 7); + + for (my $c = -1 ; $c <= 1 ; $c += 2) + { + next if ($u+$c < 0 || $u+$c > 7 || $v+$g < 0); + + # +1 for each adjacent friendly piece + if ($s[$u+$c][$v+$g] < 0) + { + $q++; + next; + } + + # Prevent out-of-bounds testing + next if ($u-$c < 0 || $u-$c > 7 || $v-$g > 7); + + # -2 for each opponent piece that can now take this piece here + $q -= 2 if ($s[$u+$c][$v+$g] > 0 && ($s[$u-$c][$v-$g] == 0 || ($u-$c == $x && $v-$g == $y))); + } + + # Use this move if it's better than the previous best + if ($q > $r[0]) + { + $r[0] = $q; + $r[1] = $x; + $r[2] = $y; + $r[3] = $u; + $r[4] = $v; + } +} + +# If (u,v) is in the bounds, evaluate it as a move using +# the sub at 910, so storing eval in @r. +sub eval_move +{ + my ($x, $y, $a, $b) = @_; + my $u = $x+$a; + my $v = $y+$b; + return if ($u < 0 || $u > 7 || $v < 0 || $v > 7); + eval_jump($x, $y, $u, $v) if ($s[$u][$v] == 0 && $s[$x+$a/2][$y+$b/2] > 0); +} From b45ad8544c3b67c0c5751f1a25436b68fcba41aa Mon Sep 17 00:00:00 2001 From: kbrannen Date: Sun, 21 May 2023 15:14:10 -0500 Subject: [PATCH 2/3] fixed typo --- 23_Checkers/perl/checkers.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/23_Checkers/perl/checkers.pl b/23_Checkers/perl/checkers.pl index 9e87f1fe..94643f76 100755 --- a/23_Checkers/perl/checkers.pl +++ b/23_Checkers/perl/checkers.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -# Boxing program in Perl +# Checkers program in Perl # Started with checkers.annotated.bas # Translated by Kevin Brannen (kbrannen) From 1ae84a67df0bb5d4f92f218160ab43518168824c Mon Sep 17 00:00:00 2001 From: kbrannen Date: Sun, 21 May 2023 15:33:25 -0500 Subject: [PATCH 3/3] cleaned up --- 23_Checkers/perl/checkers.pl | 134 +++++++++++++++++++---------------- 1 file changed, 71 insertions(+), 63 deletions(-) diff --git a/23_Checkers/perl/checkers.pl b/23_Checkers/perl/checkers.pl index 94643f76..46b8f2d4 100755 --- a/23_Checkers/perl/checkers.pl +++ b/23_Checkers/perl/checkers.pl @@ -11,7 +11,7 @@ use warnings; # # The current move: (rating, current x, current y, new x, new y) # 'rating' represents how good the move is; higher is better. -my @r = (-99); # (4); # Start with minimum score +my @ratings = (-99); # (4); # Start with minimum score # The board. Pieces are represented by numeric values: # # - 0 = empty square @@ -19,10 +19,10 @@ my @r = (-99); # (4); # Start with minimum score # - 1,2 = O (1 for regular piece, 2 for king) # # This program's player ("me") plays X. -my @s; # (7,7) +my @board; # (7,7) # chars to print for the board, add 2 to the board value as an index to the char my @chars = ("X*", "X", ".", "O", "O*"); -my $g = -1; # constant holding -1 +my $neg1 = -1; # constant holding -1 my $winner = ""; my $upgrade = shift(@ARGV) // ""; $upgrade = $upgrade eq "-o" ? 0 : 1; @@ -42,7 +42,8 @@ print "(0,7) IS THE UPPER LEFT CORNER\n"; print "(7,0) IS THE LOWER RIGHT CORNER\n"; print "(7,7) IS THE UPPER RIGHT CORNER\n"; print "THE COMPUTER WILL TYPE '+TO' WHEN YOU HAVE ANOTHER\n"; -print "JUMP. TYPE TWO NEGATIVE NUMBERS IF YOU CANNOT JUMP.\n\n\n"; +print "JUMP. TYPE TWO NEGATIVE NUMBERS IF YOU CANNOT JUMP.\n"; +print "ENTER YOUR MOVE POSITION LIKE '0 0' OR '0,0'.\n\n\n"; # Initialize the board. Data is 2 length-wise strips repeated. my @data = (); @@ -51,7 +52,7 @@ for my $x (0 .. 7) { for my $y (0 .. 7) { - $s[$x][$y] = shift(@data); + $board[$x][$y] = shift(@data); } } @@ -66,22 +67,22 @@ while (1) for my $y (0 .. 7) { # Skip if this is empty or an opponent's piece - next if ($s[$x][$y] > -1); + next if ($board[$x][$y] > -1); # If this is one of my ordinary pieces, analyze possible # forward moves. - if ($s[$x][$y] == -1) + if ($board[$x][$y] == -1) { for (my $a = -1 ; $a <= 1 ; $a +=2) { - $b = $g; + $b = $neg1; find_move($x, $y, $a, $b); } } # If this is one of my kings, analyze possible forward # and backward moves. - if ($s[$x][$y] == -2) + if ($board[$x][$y] == -2) { for (my $a = -1 ; $a <= 1 ; $a += 2) { @@ -92,7 +93,7 @@ while (1) } - if ($r[0] == -99) # Game is lost if no move could be found. + if ($ratings[0] == -99) # Game is lost if no move could be found. { $winner = "you"; last; @@ -100,47 +101,47 @@ while (1) # Print the computer's move. (Note: chr$(30) is an ASCII RS # (record separator) code; probably no longer relevant.) - print "FROM $r[1],$r[2] TO $r[3],$r[4] "; - $r[0] = -99; + print "FROM $ratings[1],$ratings[2] TO $ratings[3],$ratings[4] "; + $ratings[0] = -99; # Make the computer's move. If the piece finds its way to the # end of the board, crown it. LOOP1240: { - if ($r[4] == 0) + if ($ratings[4] == 0) { - $s[$r[3]][$r[4]] = -2; + $board[$ratings[3]][$ratings[4]] = -2; last LOOP1240; } - $s[$r[3]][$r[4]] = $s[$r[1]][$r[2]]; - $s[$r[1]][$r[2]] = 0; + $board[$ratings[3]][$ratings[4]] = $board[$ratings[1]][$ratings[2]]; + $board[$ratings[1]][$ratings[2]] = 0; # If the piece has jumped 2 squares, it means the computer has # taken an opponents' piece. - if (abs($r[1] - $r[3]) == 2) + if (abs($ratings[1] - $ratings[3]) == 2) { - $s [($r[1]+$r[3])/2] [($r[2]+$r[4])/2] = 0; # Delete the opponent's piece + $board [($ratings[1]+$ratings[3])/2] [($ratings[2]+$ratings[4])/2] = 0; # Delete the opponent's piece # See if we can jump again. Evaluate all possible moves. - my $x = $r[3]; - my $y = $r[4]; + my $x = $ratings[3]; + my $y = $ratings[4]; for (my $a = -2 ; $a <= 2 ; $a += 4) { - if ($s[$x][$y] == -1) + if ($board[$x][$y] == -1) { $b = -2; eval_move($x, $y, $a, $b); } - if ($s[$x][$y] == -2) + if ($board[$x][$y] == -2) { for (my $b = -2 ; $b <= 2 ; $b += 4) { eval_move($x, $y, $a, $b); } } } # If we've found a move, go back and make that one as well - if ($r[0] != -99) + if ($ratings[0] != -99) { - print "TO $r[3], $r[4] "; - $r[0] = -99; + print "TO $ratings[3], $ratings[4] "; + $ratings[0] = -99; next LOOP1240; } } @@ -154,7 +155,7 @@ while (1) $line = "$y|" if ($upgrade); for my $x (0 .. 7) { - my $c = $chars[$s[$x][$y] + 2]; + my $c = $chars[$board[$x][$y] + 2]; $c = ' ' if ($upgrade && (($y % 2 == 0 && $x % 2 == 1) || ($y % 2 == 1 && $x % 2 == 0))); $line = tab($line, 5*$x+7, $c); } @@ -172,8 +173,8 @@ while (1) { for my $y (0 .. 7) { - if ($s[$x][$y] == 1 || $s[$x][$y] == 2) { $z = 1; } - if ($s[$x][$y] == -1 || $s[$x][$y] == -2) { $t = 1; } + if ($board[$x][$y] == 1 || $board[$x][$y] == 2) { $z = 1; } + if ($board[$x][$y] == -1 || $board[$x][$y] == -2) { $t = 1; } } } if ($z != 1) { $winner = "comp"; last; } @@ -183,39 +184,33 @@ while (1) ($z, $t) = (0, 0); my ($x, $y, $e, $h, $a, $b); do { - print "FROM: "; - chomp(my $ans = <>); - ($e,$h) = split(/[, ]/, $ans); + ($e,$h) = get_pos("FROM:"); $x = $e; $y = $h; - } while ($s[$x][$y] <= 0); + } while ($board[$x][$y] <= 0); do { - print "TO: "; - chomp(my $ans = <>); - ($a,$b) = split(/[, ]/, $ans); + ($a,$b) = get_pos("TO:"); $x = $a; $y = $b; - } while (!($s[$x][$y] == 0 && abs($a-$e) <= 2 && abs($a-$e) == abs($b-$h))); + } while (!($board[$x][$y] == 0 && abs($a-$e) <= 2 && abs($a-$e) == abs($b-$h))); LOOP1750: { # Make the move and stop unless it might be a jump. - $s[$a][$b] = $s[$e][$h]; - $s[$e][$h] = 0; + $board[$a][$b] = $board[$e][$h]; + $board[$e][$h] = 0; if (abs($e-$a) != 2) { last LOOP1750; } # Remove the piece jumped over - $s[($e+$a)/2][($h+$b)/2] = 0; + $board[($e+$a)/2][($h+$b)/2] = 0; # Prompt for another move; -1 means player can't, so I've won. # Keep prompting until there's a valid move or the player gives # up. my ($a1, $b1); do { - print "+TO "; - chomp(my $ans = <>); - ($a1,$b1) = split(/[, ]/, $ans); + ($a1,$b1) = get_pos("+TO:"); if ($a1 < 0) { last LOOP1750; } - } while ($s[$a1][$b1] != 0 || abs($a1-$a) != 2 || abs($b1-$b) != 2); + } while ($board[$a1][$b1] != 0 || abs($a1-$a) != 2 || abs($b1-$b) != 2); # Update the move variables to correspond to the next jump $e = $a; @@ -225,7 +220,7 @@ while (1) } # If the player has reached the end of the board, crown this piece - if ($b == 7) { $s[$a][$b] = 2; } + if ($b == 7) { $board[$a][$b] = 2; } # And play the next turn. } @@ -236,6 +231,19 @@ exit(0); ########################################### +# make sure we get a 2 value position +sub get_pos +{ + my $prompt = shift; + my ($p1, $p2); + do { + print "$prompt "; + chomp(my $ans = <>); + ($p1,$p2) = split(/[, ]/, $ans); + } while (!defined($p1) || !defined($p2) || $p1 < -1 || $p2 < -1 || $p1 > 7 || $p2 > 7); + return ($p1,$p2); +} + # deal with basic's tab() for line positioning # line = line string we're starting with # pos = position to start writing @@ -243,10 +251,10 @@ exit(0); # returns the resultant string, which might not have been changed sub tab { - my ($line, $pos, $s) = @_; + my ($line, $pos, $str) = @_; my $len = length($line); # if curser is past position, do nothing - if ($len <= $pos) { $line .= " " x ($pos - $len) . $s; } + if ($len <= $pos) { $line .= " " x ($pos - $len) . $str; } return $line; } @@ -262,10 +270,10 @@ sub find_move return if ($u < 0 || $u > 7 || $v < 0 || $ v> 7); # Consider the destination if it's empty - eval_jump($x, $y, $u, $v) if ($s[$u][$v] == 0); + eval_jump($x, $y, $u, $v) if ($board[$u][$v] == 0); # If it's got an opponent's piece, jump it instead - if ($s[$u][$v] > 0) + if ($board[$u][$v] > 0) { # Restore u and v, then return if it's off the board @@ -274,7 +282,7 @@ sub find_move return if ($u < 0 || $v < 0 || $u > 7 || $v > 7); # Otherwise, consider u,v - eval_jump($x, $y, $u, $v) if ($s[$u][$v] == 0); + eval_jump($x, $y, $u, $v) if ($board[$u][$v] == 0); } } @@ -282,7 +290,7 @@ sub find_move # # Computes a score for the proposed move and if it's higher # than the best-so-far move, uses that instead by storing it -# and its score in @r. +# and its score in @ratings. sub eval_jump { my ($x, $y, $u, $v) = @_; @@ -291,7 +299,7 @@ sub eval_jump my $q = 0; # +2 if it promotes this piece - $q += 2 if ($v == 0 && $s[$x][$y] == -1); + $q += 2 if ($v == 0 && $board[$x][$y] == -1); # +5 if it takes an opponent's piece $q += 5 if (abs($y-$v) == 2); @@ -304,40 +312,40 @@ sub eval_jump for (my $c = -1 ; $c <= 1 ; $c += 2) { - next if ($u+$c < 0 || $u+$c > 7 || $v+$g < 0); + next if ($u+$c < 0 || $u+$c > 7 || $v+$neg1 < 0); # +1 for each adjacent friendly piece - if ($s[$u+$c][$v+$g] < 0) + if ($board[$u+$c][$v+$neg1] < 0) { $q++; next; } # Prevent out-of-bounds testing - next if ($u-$c < 0 || $u-$c > 7 || $v-$g > 7); + next if ($u-$c < 0 || $u-$c > 7 || $v-$neg1 > 7); # -2 for each opponent piece that can now take this piece here - $q -= 2 if ($s[$u+$c][$v+$g] > 0 && ($s[$u-$c][$v-$g] == 0 || ($u-$c == $x && $v-$g == $y))); + $q -= 2 if ($board[$u+$c][$v+$neg1] > 0 && ($board[$u-$c][$v-$neg1] == 0 || ($u-$c == $x && $v-$neg1 == $y))); } # Use this move if it's better than the previous best - if ($q > $r[0]) + if ($q > $ratings[0]) { - $r[0] = $q; - $r[1] = $x; - $r[2] = $y; - $r[3] = $u; - $r[4] = $v; + $ratings[0] = $q; + $ratings[1] = $x; + $ratings[2] = $y; + $ratings[3] = $u; + $ratings[4] = $v; } } # If (u,v) is in the bounds, evaluate it as a move using -# the sub at 910, so storing eval in @r. +# the sub at 910, so storing eval in @ratings. sub eval_move { my ($x, $y, $a, $b) = @_; my $u = $x+$a; my $v = $y+$b; return if ($u < 0 || $u > 7 || $v < 0 || $v > 7); - eval_jump($x, $y, $u, $v) if ($s[$u][$v] == 0 && $s[$x+$a/2][$y+$b/2] > 0); + eval_jump($x, $y, $u, $v) if ($board[$u][$v] == 0 && $board[$x+$a/2][$y+$b/2] > 0); }