Commits

Anonymous committed aaf038b

Convert another move to an object.

Comments (0)

Files changed (3)

abc-path/Games-ABC_Path-Solver/MANIFEST

 lib/Games/ABC_Path/Solver/Base.pm
 lib/Games/ABC_Path/Solver/Board.pm
 lib/Games/ABC_Path/Solver/Move/LastRemainingCellForLetter.pm
+lib/Games/ABC_Path/Solver/Move/LettersNotInVicinity.pm
 lib/Games/ABC_Path/Solver/Move.pm
 lib/Games/ABC_Path/Solver.pm
 Makefile.PL

abc-path/Games-ABC_Path-Solver/lib/Games/ABC_Path/Solver/Board.pm

 
 use Games::ABC_Path::Solver::Move;
 use Games::ABC_Path::Solver::Move::LastRemainingCellForLetter;
+use Games::ABC_Path::Solver::Move::LettersNotInVicinity;
 
 my $ABCP_VERDICT_NO = 0;
 my $ABCP_VERDICT_MAYBE = 1;
                 {
                     $self->_set_verdict($neighbour_letter, $x, $y, $ABCP_VERDICT_NO);
                     $self->_add_move(
-                        Games::ABC_Path::Solver::Move->new(
+                        Games::ABC_Path::Solver::Move::LettersNotInVicinity->new(
                             {
-                                text => sprintf(
-                                    "%s cannot be at (%d,%d) due to lack of vicinity from %s.", 
-                                    $letters[$neighbour_letter], 
-                                    $x+1,$y+1, 
-                                    $letters[$letter]
-                                ),
+                                vars =>
+                                {
+                                    target => $neighbour_letter,
+                                    coords => [$x,$y],
+                                    source => $letter,
+                                },
                             }
                         )
                     );

abc-path/Games-ABC_Path-Solver/lib/Games/ABC_Path/Solver/Move/LettersNotInVicinity.pm

+package Games::ABC_Path::Solver::Move::LettersNotInVicinity;
+
+use strict;
+use warnings;
+
+use base 'Games::ABC_Path::Solver::Move';
+
+=head1 NAME
+
+Games::ABC_Path::Solver::Move::LettersNotInVicinity - an ABC Path move
+that indicates that letters are not in vicinity to one another in a certain
+cell.
+
+=head1 VERSION
+
+Version 0.0.1
+
+=cut
+
+our $VERSION = '0.0.1';
+
+=head1 SYNOPSIS
+
+    use Games::ABC_Path::Solver::Move::LettersNotInVicinity;
+
+    my $move = Games::ABC_Path::Solver::Move::LettersNotInVicinity->new(
+        {
+            vars =>
+            {
+                target => 6
+                coords => [1,2],
+                source => 5,
+            },
+        }
+    );
+
+=head1 DESCRIPTION
+
+This is a move that indicates that the C<'letter'> has the last remaining cell
+as C<'coords'>.
+
+=cut
+
+sub _get_text {
+    my $self = shift;
+
+    my $text = $self->_format;
+
+    $text =~ s/%\((\w+)\)\{(\w+)\}/
+        $self->_expand_format($1,$2)
+        /ge;
+
+    return $text;
+}
+
+sub _format {
+    return "%(target){letter} cannot be at %(coords){coords} due to lack of vicinity from %(source){letter}.";
+}
+
+1;
+