NAME

Freecell::Tableau - Freecell layout.

VERSION

Version 0.01

SYNOPSIS

The Tableau class manages the creation of the Tableau array from both input gameno and the position key and token.

use Freecell::Tableau;

my $tableau = Freecell::Tableau->new()->from_deal($gameno);

-or-

my $tableau = Freecell::Tableau->new()->from_token($key, $token);

EXPORT

none.

SUBROUTINES/METHODS

new()

Initializes the Tableau with 8 columns and 21 rows of 0's

columns 0 .. 3 row 0 are the freecells
columns 4 .. 7 row 0 are the homecells D, C, H, S
columns 0 .. 7 rows 1 .. 20 are the cascades

from_token()

This creates a Tableau from the Key and Token built in to_token().

to_token()

The key for position is created with to_token() which also creates a token array. The token array is needed to rebuild the Tableau from the key. The key is the chr() of each integer in the Tableau.

card->key     A    2    3    4    5    6    7    8    9    T    J    Q    K
  ....0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101
D 0100....    A    B    C    D    E    F    G    H    I    J    K    L    M
C 0101....    Q    R    S    T    U    V    W    X    Y    Z    [    \    ]
H 0110....    a    b    c    d    e    f    g    h    i    j    k    l    m
S 0111....    q    r    s    t    u    v    w    x    y    z    {    |    }

from_string($str)

Given a new() Tableau, it will take an input string from deal($gameno) and populate the Tableau.

TC -> 'C' -> '1' -> x31 <<4 -> ..01.... 
+-> + 'T' -> ':' -> x3a &15 -> ....1010 
    + 64  ->        x40     -> .1...... 
    =                          01011010 = x5a ('Z')

to_string()

Creates a human readable string from Tableau.

from_deal($gameno)

Thanks to http://rosettacode.org/wiki/Deal_cards_for_FreeCell#Perl this generates hands 1 to 1 million with a perl one-liner.

return (($s = ($s * 214013 + 2531011) % 2**31) >> 16 );

play($move)

This will take a generated_nodelist entry and perform the move to create a new Tableau state.

undo($node)

This will undo a call to play().

autoplay($node)

Append to the node all safe moves to home.

notation($node)

During backtrack, the notation is pushed onto the solution array.

generate_nodelist()

Creates a node for all valid plays of a given Tableau.

heuristic

The algorithm is simple.

  • Start with 64.

  • Subtract the rank of all the top home cards.

  • Subtract 1 for each empty freecell and empty column.

  • Add 1 for each sequence break in the cascade e.g. 6C 5H 4S 2C KD QS TH has 3 sequence breaks, one major at 2C because the KD is greater than the 2C.

helper subroutines

  • opposite_colors() - test if two cards are of opposite color

  • rank() - return the rank of a card

  • suit() - return the suit of a card

  • to_card() - convert a numeric tableau card to a two character string

getters and setters for two class variables

  • winxp_opt() - was the --win_xp option specified

  • winxp_warn() - if not, is solution valid for XP

AUTHOR

Shirl Hart, <shirha at cpan.org>

BUGS

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

SUPPORT

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

perldoc Freecell::Tableau

You can also look for information at:

ACKNOWLEDGEMENTS

LICENSE AND COPYRIGHT

Copyright 2013 Shirl Hart.

This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at:

http://www.perlfoundation.org/artistic_license_2_0

Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License. By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license.

If your Modified Version has been derived from a Modified Version made by someone other than you, you are nevertheless required to ensure that your Modified Version complies with the requirements of this license.

This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder.

This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement, then this Artistic License to you shall terminate on the date that such litigation is filed.

Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.