Games::Solitaire::Verify::Move - a class wrapper for an individual


Games-Solitaire-Verify documentation Contained in the Games-Solitaire-Verify distribution.

Index


Code Index:

NAME

Top

Games::Solitaire::Verify::Move - a class wrapper for an individual Solitaire move.

VERSION

Top

Version 0.01

SYNOPSIS

Top

    use Games::Solitaire::Verify::Move;

    my $move1 = Games::Solitaire::Verify::Move->new(
        {
            fcs_string => "Move a card from stack 0 to the foundations",
            game => "freecell",
        },
    );

FUNCTIONS

Top

METHODS

Top

$move->source_type()

Accessor for the solitaire card game's board layout's type - "stack", "freecell", etc. used in the layout.

$move->dest_type()

Accessor for the destination type - "stack", "freecell", "destination".

$move->source()

The index number of the source.

$move->dest()

The index number of the destination.

$move->num_cards()

Number of cards affects - only relevant for a stack-to-stack move usually.

AUTHOR

Top

Shlomi Fish, <shlomif at iglu.org.il>

BUGS

Top

Please report any bugs or feature requests to bug-games-solitaire-verifysolution-move at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Games-Solitaire-Verify. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

Top

You can find documentation for this module with the perldoc command.

    perldoc Games::Solitaire::Verify




You can also look for information at:

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=Games-Solitaire-Verify

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/Games-Solitaire-Verify

* CPAN Ratings

http://cpanratings.perl.org/d/Games-Solitaire-Verify

* Search CPAN

http://search.cpan.org/dist/Games-Solitaire-Verify

ACKNOWLEDGEMENTS

Top

COPYRIGHT & LICENSE

Top


Games-Solitaire-Verify documentation Contained in the Games-Solitaire-Verify distribution.
package Games::Solitaire::Verify::Move;

use warnings;
use strict;

our $VERSION = '0.0901';

use base 'Games::Solitaire::Verify::Base';

use Games::Solitaire::Verify::Exception;

__PACKAGE__->mk_acc_ref([qw(
    source_type
    dest_type
    source
    dest
    num_cards
    _game
    )]);

sub _from_fcs_string
{
    my ($self, $str) = @_;

    if ($str =~ m{\AMove a card from stack (\d+) to the foundations\z})
    {
        my $source = $1;
        
        $self->source_type("stack");
        $self->dest_type("foundation");

        $self->source($source);
    }
    elsif ($str =~ m{\AMove a card from freecell (\d+) to the foundations\z})
    {
        my $source = $1;
        
        $self->source_type("freecell");
        $self->dest_type("foundation");

        $self->source($source);
    }
    elsif ($str =~ m{\AMove a card from freecell (\d+) to stack (\d+)\z})
    {
        my ($source, $dest) = ($1, $2);
        
        $self->source_type("freecell");
        $self->dest_type("stack");

        $self->source($source);
        $self->dest($dest);
    }
    elsif ($str =~ m{\AMove a card from stack (\d+) to freecell (\d+)\z})
    {
        my ($source, $dest) = ($1, $2);
        
        $self->source_type("stack");
        $self->dest_type("freecell");

        $self->source($source);
        $self->dest($dest);
    }
    elsif ($str =~ m{\AMove (\d+) cards from stack (\d+) to stack (\d+)\z})
    {
        my ($num_cards, $source, $dest) = ($1, $2, $3);

        $self->source_type("stack");
        $self->dest_type("stack");

        $self->source($source);
        $self->dest($dest);
        $self->num_cards($num_cards);
    }
    elsif ($str =~ m{\AMove the sequence on top of Stack (\d+) to the foundations\z})
    {
        my $source = $1;
        
        $self->source_type("stack_seq");
        $self->dest_type("foundation");

        $self->source($source);
    }    
    else
    {
        Games::Solitaire::Verify::Exception::Parse::FCS->throw(
            error => "Cannot parse 'FCS' String",
        );
    }
}

sub _init
{
    my ($self, $args) = @_;

    $self->_game($args->{game});

    if (exists($args->{fcs_string}))
    {
        return $self->_from_fcs_string($args->{fcs_string});
    }
}

1; # End of Games::Solitaire::Verify::Move