Skip Menu |

This queue is for tickets about the Games-AlphaBeta CPAN distribution.

Report information
The Basics
Id: 49367
Status: patched
Priority: 0/
Queue: Games-AlphaBeta

People
Owner: STIG [...] cpan.org
Requestors: mhasch-cpanbugs [...] cozap.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.4.6
Fixed in: v0.4.7



Subject: [PATCH] abmove ends game prematurely if best move is to pass
This bug can be verified with the Othello demo which is part of the distribution. If you run othello-demo, you'll see that the game ends while one player is still able to move. According to the rules, a player not able to place a chip must pass, and to pass is consequently handled as a valid move in Games::AlphaBeta::Reversi. The game ends if both players run out of valid moves. G::A::R encodes passing as an undef value. Games::AlphaBeta, however, treats moves with a boolean value of false as a game-over criterion at one point. The actual value of a move should not be used in the abstraction, however. Patch included. As the fix changes the behaviour of othello-demo, t/t.othello has to be updated as well. -Martin
And here is the patch. -Martin
diff -ru Games-AlphaBeta-0.4.6.orig/lib/Games/AlphaBeta.pm Games-AlphaBeta-0.4.6/lib/Games/AlphaBeta.pm --- Games-AlphaBeta-0.4.6.orig/lib/Games/AlphaBeta.pm 2005-10-01 21:19:38.000000000 +0200 +++ Games-AlphaBeta-0.4.6/lib/Games/AlphaBeta.pm 2009-09-02 15:01:01.000000000 +0200 @@ -154,6 +154,7 @@ } my (@moves, $bestmove); + my $bestmove_valid = 0; my $pos = $self->peek_pos; return if $pos->endpos; @@ -173,6 +174,7 @@ print "ab val: $sc" if $self->{debug}; if ($sc > $alpha) { print " > $alpha new best move" if $self->{debug}; + $bestmove_valid = 1; $bestmove = $move; $alpha = $sc; } @@ -180,7 +182,7 @@ } print "$self->{count} visited\n" if $self->{debug}; - return unless $bestmove; + return unless $bestmove_valid; return $self->move($bestmove); } diff -ru Games-AlphaBeta-0.4.6.orig/t/othello.t Games-AlphaBeta-0.4.6/t/othello.t --- Games-AlphaBeta-0.4.6.orig/t/othello.t 2005-10-01 21:19:38.000000000 +0200 +++ Games-AlphaBeta-0.4.6/t/othello.t 2009-09-02 15:05:58.000000000 +0200 @@ -2,7 +2,7 @@ use strict; use warnings; -use Test::More tests => 104; +use Test::More tests => 122; use FindBin qw( $Bin ); use File::Spec::Functions; use Config; @@ -652,3 +652,111 @@ 8 | . . . x x x x . Player 1 to move. + a b c d e f g h + +---------------- + 1 | x o o o o o o o + 2 | x o o o o o o o + 3 | x o o o o o o o + 4 | x o o o o x o o + 5 | x o o o o o x o + 6 | x . o o x x o o + 7 | . . . o x o o o + 8 | . . . x x x x . +Player 2 to move. + + a b c d e f g h + +---------------- + 1 | x o o o o o o o + 2 | x o o o o o o o + 3 | x o o o o o o o + 4 | x o o o o x o o + 5 | x o o o o o x o + 6 | x x x x x x o o + 7 | . . . o x o o o + 8 | . . . x x x x . +Player 1 to move. + + a b c d e f g h + +---------------- + 1 | x o o o o o o o + 2 | x o o o o o o o + 3 | x o o o o o o o + 4 | x o o o o x o o + 5 | x o o o o o x o + 6 | x o x x x x o o + 7 | o . . o x o o o + 8 | . . . x x x x . +Player 2 to move. + + a b c d e f g h + +---------------- + 1 | x o o o o o o o + 2 | x o o o o o o o + 3 | x o o o o o o o + 4 | x o o o o x o o + 5 | x o o o o o x o + 6 | x x x x x x o o + 7 | o . x x x o o o + 8 | . . . x x x x . +Player 1 to move. + + a b c d e f g h + +---------------- + 1 | x o o o o o o o + 2 | x o o o o o o o + 3 | x o o o o o o o + 4 | x o o o o x o o + 5 | x o o o o o x o + 6 | x x x o x x o o + 7 | o . o x x o o o + 8 | . o . x x x x . +Player 2 to move. + + a b c d e f g h + +---------------- + 1 | x o o o o o o o + 2 | x o o o o o o o + 3 | x o o o o o o o + 4 | x o o o o x o o + 5 | x o o o o o x o + 6 | x x x o x x o o + 7 | o . o x x o x o + 8 | . o . x x x x x +Player 1 to move. + + a b c d e f g h + +---------------- + 1 | x o o o o o o o + 2 | x o o o o o o o + 3 | x o o o o o o o + 4 | x o o o o x o o + 5 | x o o o o o x o + 6 | x o o o x x o o + 7 | o o o x x o x o + 8 | . o . x x x x x +Player 2 to move. + + a b c d e f g h + +---------------- + 1 | x o o o o o o o + 2 | x o o o o o o o + 3 | x o o o o o o o + 4 | x o o o o x o o + 5 | x o o o o o x o + 6 | x o o o x x o o + 7 | x o o x x o x o + 8 | x o . x x x x x +Player 1 to move. + + a b c d e f g h + +---------------- + 1 | x o o o o o o o + 2 | x o o o o o o o + 3 | x o o o o o o o + 4 | x o o o o x o o + 5 | x o o o o o x o + 6 | x o o o o x o o + 7 | x o o o x o x o + 8 | x o o x x x x x +Player 2 to move. +
applied