~ubuntu-branches/ubuntu/saucy/freecell-solver/saucy

« back to all changes in this revision

Viewing changes to freecell.c

  • Committer: Bazaar Package Importer
  • Author(s): RISKO Gergely
  • Date: 2009-03-15 23:42:21 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090315234221-sx95hxyfyfgi0pja
Tags: 2.16.0-1
* Imported Upstream version 2.16.0 (closes: #518440)
* cmake is the new buildsystem

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * freecell.c - The various movement tests performed by Freecell Solver
3
3
 *
4
 
 * Written by Shlomi Fish (shlomif@vipe.technion.ac.il), 2000-2001
 
4
 * Written by Shlomi Fish ( http://www.shlomifish.org/ ), 2000-2001
5
5
 *
6
6
 * This file is in the public domain (it's uncopyrighted).
7
7
 */
32
32
#include "dmalloc.h"
33
33
#endif
34
34
 
35
 
#define state_with_locations (*ptr_state_with_locations)
36
 
#define state (ptr_state_with_locations->s)
37
 
#define new_state_with_locations (*ptr_new_state_with_locations)
38
 
#define new_state (ptr_new_state_with_locations->s)
39
 
 
40
 
 
41
35
#ifndef min
42
36
#define min(a,b) (((a)<(b))?(a):(b))
43
37
#endif
55
49
 * This function tries to move stack cards that are present at the
56
50
 * top of stacks to the foundations.
57
51
 * */
58
 
int freecell_solver_sfs_move_top_stack_cards_to_founds(
59
 
        freecell_solver_soft_thread_t * soft_thread,
60
 
        fcs_state_with_locations_t * ptr_state_with_locations,
 
52
int fc_solve_sfs_move_top_stack_cards_to_founds(
 
53
        fc_solve_soft_thread_t * soft_thread,
 
54
        fcs_state_t * ptr_state_key,
 
55
        fcs_state_extra_info_t * ptr_state_val,
61
56
        int num_freestacks,
62
57
        int num_freecells,
63
58
        fcs_derived_states_list_t * derived_states_list,
135
130
 * This test moves single cards that are present in the freecells to
136
131
 * the foundations.
137
132
 * */
138
 
int freecell_solver_sfs_move_freecell_cards_to_founds(
139
 
        freecell_solver_soft_thread_t * soft_thread,
140
 
        fcs_state_with_locations_t * ptr_state_with_locations,
 
133
int fc_solve_sfs_move_freecell_cards_to_founds(
 
134
        fc_solve_soft_thread_t * soft_thread,
 
135
        fcs_state_t * ptr_state_key,
 
136
        fcs_state_extra_info_t * ptr_state_val,
141
137
        int num_freestacks,
142
138
        int num_freecells,
143
139
        fcs_derived_states_list_t * derived_states_list,
191
187
    return FCS_STATE_IS_NOT_SOLVEABLE;
192
188
}
193
189
 
194
 
int freecell_solver_sfs_move_freecell_cards_on_top_of_stacks(
195
 
        freecell_solver_soft_thread_t * soft_thread,
196
 
        fcs_state_with_locations_t * ptr_state_with_locations,
 
190
int fc_solve_sfs_move_freecell_cards_on_top_of_stacks(
 
191
        fc_solve_soft_thread_t * soft_thread,
 
192
        fcs_state_t * ptr_state_key,
 
193
        fcs_state_extra_info_t * ptr_state_val,
197
194
        int num_freestacks,
198
195
        int num_freecells,
199
196
        fcs_derived_states_list_t * derived_states_list,
357
354
 
358
355
 
359
356
 
360
 
int freecell_solver_sfs_move_non_top_stack_cards_to_founds(
361
 
        freecell_solver_soft_thread_t * soft_thread,
362
 
        fcs_state_with_locations_t * ptr_state_with_locations,
 
357
int fc_solve_sfs_move_non_top_stack_cards_to_founds(
 
358
        fc_solve_soft_thread_t * soft_thread,
 
359
        fcs_state_t * ptr_state_key,
 
360
        fcs_state_extra_info_t * ptr_state_val,
363
361
        int num_freestacks,
364
362
        int num_freecells,
365
363
        fcs_derived_states_list_t * derived_states_list,
498
496
 
499
497
 
500
498
 
501
 
int freecell_solver_sfs_move_stack_cards_to_a_parent_on_the_same_stack(
502
 
        freecell_solver_soft_thread_t * soft_thread,
503
 
        fcs_state_with_locations_t * ptr_state_with_locations,
 
499
int fc_solve_sfs_move_stack_cards_to_a_parent_on_the_same_stack(
 
500
        fc_solve_soft_thread_t * soft_thread,
 
501
        fcs_state_t * ptr_state_key,
 
502
        fcs_state_extra_info_t * ptr_state_val,
504
503
        int num_freestacks,
505
504
        int num_freecells,
506
505
        fcs_derived_states_list_t * derived_states_list,
791
790
#undef ds
792
791
 
793
792
 
794
 
int freecell_solver_sfs_move_stack_cards_to_different_stacks(
795
 
        freecell_solver_soft_thread_t * soft_thread,
796
 
        fcs_state_with_locations_t * ptr_state_with_locations,
 
793
int fc_solve_sfs_move_stack_cards_to_different_stacks(
 
794
        fc_solve_soft_thread_t * soft_thread,
 
795
        fcs_state_t * ptr_state_key,
 
796
        fcs_state_extra_info_t * ptr_state_val,
797
797
        int num_freestacks,
798
798
        int num_freecells,
799
799
        fcs_derived_states_list_t * derived_states_list,
805
805
    int check;
806
806
 
807
807
    int stack, c, cards_num, a, dc, ds,b;
 
808
    
808
809
    int is_seq_in_dest;
809
810
    fcs_card_t card, temp_card, this_card, prev_card;
810
811
    fcs_card_t dest_below_card, dest_card;
814
815
    int state_freecells_num;
815
816
    int state_stacks_num;
816
817
    int sequences_are_built_by;
 
818
    char * positions_by_rank;
 
819
    int positions_by_rank_size;
 
820
    char * pos_idx_to_check;
 
821
    int decks_num;
817
822
 
818
823
    fcs_move_t temp_move;
819
824
 
820
825
    tests_define_accessors();
821
826
 
 
827
    decks_num = instance->decks_num;
822
828
    state_freecells_num = instance->freecells_num;
823
829
    state_stacks_num = instance->stacks_num;
824
830
    sequences_are_built_by = instance->sequences_are_built_by;
825
831
 
 
832
    /* We need 2 chars per card - one for the stack and one 
 
833
     * for the card_idx.
 
834
     *
 
835
     * We also need it times 13 for each of the ranks.
 
836
     *
 
837
     * We need (4*decks_num+1) slots to hold the cards plus a 
 
838
     * (-1,-1) (= end) padding.
 
839
     * */
 
840
    positions_by_rank_size =
 
841
        (sizeof(positions_by_rank[0]) * 2 * 13) * 
 
842
        ((decks_num << 2) + 1)
 
843
        ;
 
844
 
 
845
    positions_by_rank = malloc(positions_by_rank_size);
 
846
 
 
847
    memset(positions_by_rank, -1, positions_by_rank_size);
 
848
 
 
849
    {
 
850
        char * positions_by_rank_slots[13];
 
851
 
 
852
        /* Initialize the pointers to the first available slots */
 
853
        for(c=0;c<13;c++)
 
854
        {
 
855
            positions_by_rank_slots[c] = &positions_by_rank[
 
856
                (((decks_num << 2)+1) << 1) * c
 
857
            ];
 
858
        }
 
859
 
 
860
        /* Populate positions_by_rank by looping over the stacks and indices
 
861
         * looking for the cards and filling them. */
 
862
    
 
863
        for(ds=0;ds<state_stacks_num;ds++)
 
864
        {
 
865
            dest_cards_num = fcs_stack_len(state, ds);
 
866
            for(dc=0;dc<dest_cards_num;dc++)
 
867
            {
 
868
                dest_card = fcs_stack_card(state, ds, dc);
 
869
                is_seq_in_dest = 0;
 
870
                if (dest_cards_num - 1 > dc)
 
871
                {
 
872
                    dest_below_card = fcs_stack_card(state, ds, dc+1);
 
873
                    if (fcs_is_parent_card(dest_below_card, dest_card))
 
874
                    {
 
875
                        is_seq_in_dest = 1;
 
876
                    }
 
877
                }
 
878
                if (!is_seq_in_dest)
 
879
                {
 
880
                    *(positions_by_rank_slots[fcs_card_card_num(dest_card)-1]++) = ds;
 
881
                    *(positions_by_rank_slots[fcs_card_card_num(dest_card)-1]++) = dc;
 
882
                }
 
883
            }
 
884
        }
 
885
    }
 
886
 
826
887
    /* Now let's try to move a card from one stack to the other     *
827
888
     * Note that it does not involve moving cards lower than king   *
828
889
     * to empty stacks                                              */
853
914
            card = fcs_stack_card(state, stack, c);
854
915
 
855
916
            /* Make sure the card is not flipped or else we can't move it */
856
 
            if (fcs_card_get_flipped(card) == 0)
857
 
            {
858
 
                for(ds=0 ; ds<state_stacks_num; ds++)
859
 
                {
860
 
                    if (ds != stack)
861
 
                    {
862
 
                        dest_cards_num = fcs_stack_len(state, ds);
863
 
                        for(dc=0;dc<dest_cards_num;dc++)
864
 
                        {
865
 
                            dest_card = fcs_stack_card(state, ds, dc);
866
 
 
867
 
                            if (fcs_is_parent_card(card, dest_card))
868
 
                            {
869
 
                                /* Corresponding cards - see if it is feasible to move
870
 
                                   the source to the destination. */
871
 
 
872
 
                                is_seq_in_dest = 0;
873
 
                                if (dest_cards_num - 1 > dc)
874
 
                                {
875
 
                                    dest_below_card = fcs_stack_card(state, ds, dc+1);
876
 
                                    if (fcs_is_parent_card(dest_below_card, dest_card))
877
 
                                    {
878
 
                                        is_seq_in_dest = 1;
879
 
                                    }
880
 
                                }
881
 
 
882
 
                                if (! is_seq_in_dest)
883
 
                                {
884
 
                                    num_cards_to_relocate = dest_cards_num - dc - 1 + cards_num - seq_end - 1;
885
 
 
886
 
                                    freecells_to_fill = min(num_cards_to_relocate, num_freecells);
887
 
 
888
 
                                    num_cards_to_relocate -= freecells_to_fill;
889
 
 
890
 
                                    if (instance->empty_stacks_fill == FCS_ES_FILLED_BY_ANY_CARD)
891
 
                                    {
892
 
                                        freestacks_to_fill = min(num_cards_to_relocate, num_freestacks);
893
 
 
894
 
                                        num_cards_to_relocate -= freestacks_to_fill;
895
 
                                    }
896
 
                                    else
897
 
                                    {
898
 
                                        freestacks_to_fill = 0;
899
 
                                    }
900
 
 
901
 
                                    if ((num_cards_to_relocate == 0) &&
902
 
                                       (calc_max_sequence_move(num_freecells-freecells_to_fill, num_freestacks-freestacks_to_fill) >=
903
 
                                        seq_end - c + 1))
904
 
                                    {
905
 
                                        /* We can move it */
906
 
                                        int from_which_stack;
907
 
 
908
 
                                        sfs_check_state_begin()
909
 
 
910
 
 
911
 
                                        /* Fill the freecells with the top cards */
912
 
 
913
 
                                        my_copy_stack(stack);
914
 
                                        my_copy_stack(ds);
915
 
 
916
 
                                        for(a=0 ; a<freecells_to_fill ; a++)
917
 
                                        {
918
 
                                            /* Find a vacant freecell */
919
 
                                            for(b=0;b<state_freecells_num;b++)
920
 
                                            {
921
 
                                                if (fcs_freecell_card_num(new_state, b) == 0)
922
 
                                                {
923
 
                                                    break;
924
 
                                                }
925
 
                                            }
926
 
 
927
 
                                            if (fcs_stack_len(new_state, ds) == dc+1)
928
 
                                            {
929
 
                                                from_which_stack = stack;
930
 
                                            }
931
 
                                            else
932
 
                                            {
933
 
                                                from_which_stack = ds;
934
 
                                            }
935
 
                                            my_copy_stack(from_which_stack);
936
 
                                            
937
 
                                            fcs_pop_stack_card(new_state, from_which_stack, temp_card);
938
 
 
939
 
                                            fcs_put_card_in_freecell(new_state, b, temp_card);
940
 
 
941
 
                                            fcs_move_set_type(temp_move,FCS_MOVE_TYPE_STACK_TO_FREECELL);
942
 
                                            fcs_move_set_src_stack(temp_move,from_which_stack);
943
 
                                            fcs_move_set_dest_freecell(temp_move,b);
944
 
                                            fcs_move_stack_push(moves, temp_move);
945
 
 
946
 
                                            fcs_flip_top_card(from_which_stack);
947
 
                                        }
948
 
 
949
 
                                        /* Fill the free stacks with the cards below them */
950
 
                                        for(a=0; a < freestacks_to_fill ; a++)
951
 
                                        {
952
 
                                            /*  Find a vacant stack */
953
 
                                            for(b=0;b<state_stacks_num;b++)
954
 
                                            {
955
 
                                                if (fcs_stack_len(new_state, b) == 0)
956
 
                                                {
957
 
                                                    break;
958
 
                                                }
959
 
                                            }
960
 
 
961
 
                                            if (fcs_stack_len(new_state, ds) == dc+1)
962
 
                                            {
963
 
                                                from_which_stack = stack;
964
 
                                            }
965
 
                                            else
966
 
                                            {
967
 
                                                from_which_stack = ds;
968
 
                                            }
969
 
                                            
970
 
                                            my_copy_stack(b);
971
 
                                            fcs_pop_stack_card(new_state, from_which_stack, temp_card);
972
 
                                            fcs_push_card_into_stack(new_state, b, temp_card);
973
 
                                            fcs_move_set_type(temp_move,FCS_MOVE_TYPE_STACK_TO_STACK);
974
 
                                            fcs_move_set_src_stack(temp_move,from_which_stack);
975
 
                                            fcs_move_set_dest_stack(temp_move,b);
976
 
                                            fcs_move_set_num_cards_in_seq(temp_move,1);
977
 
                                            fcs_move_stack_push(moves, temp_move);
978
 
 
979
 
                                            fcs_flip_top_card(from_which_stack);
980
 
                                        }
981
 
 
982
 
                                        for(a=c ; a <= seq_end ; a++)
983
 
                                        {
984
 
                                            fcs_push_stack_card_into_stack(new_state, ds, stack, a);
985
 
                                        }
986
 
 
987
 
                                        for(a=0; a < seq_end-c+1 ;a++)
988
 
                                        {
989
 
                                            fcs_pop_stack_card(new_state, stack, temp_card);
990
 
                                        }
991
 
                                        fcs_move_set_type(temp_move,FCS_MOVE_TYPE_STACK_TO_STACK);
992
 
                                        fcs_move_set_src_stack(temp_move,stack);
993
 
                                        fcs_move_set_dest_stack(temp_move,ds);
994
 
                                        fcs_move_set_num_cards_in_seq(temp_move,seq_end-c+1);
995
 
                                        fcs_move_stack_push(moves, temp_move);
996
 
 
997
 
                                        fcs_flip_top_card(stack);
998
 
 
999
 
                                        sfs_check_state_end()
1000
 
                                    }
1001
 
                                }
1002
 
                            }
1003
 
                        }
1004
 
                    }
 
917
            if (fcs_card_get_flipped(card))
 
918
            {
 
919
                continue;
 
920
            }
 
921
 
 
922
            /* Skip if it's a King - nothing to put it on. */
 
923
            if (fcs_card_card_num(card) == 13)
 
924
            {
 
925
                continue;
 
926
            }
 
927
 
 
928
            for(pos_idx_to_check = &positions_by_rank[
 
929
                (((decks_num << 2)+1) << 1) * (fcs_card_card_num(card))
 
930
                ] 
 
931
                ;
 
932
                ((*pos_idx_to_check) >= 0)
 
933
                ;
 
934
               )
 
935
            {
 
936
                ds = *(pos_idx_to_check)++;
 
937
                dc = *(pos_idx_to_check)++;
 
938
 
 
939
                if (ds == stack)
 
940
                {
 
941
                    continue;
 
942
                }
 
943
                dest_cards_num = fcs_stack_len(state, ds);
 
944
                dest_card = fcs_stack_card(state, ds, dc);
 
945
 
 
946
                if (! fcs_is_parent_card(card, dest_card))
 
947
                {
 
948
                    continue;
 
949
                }
 
950
 
 
951
                num_cards_to_relocate = dest_cards_num - dc - 1 + cards_num - seq_end - 1;
 
952
 
 
953
                freecells_to_fill = min(num_cards_to_relocate, num_freecells);
 
954
 
 
955
                num_cards_to_relocate -= freecells_to_fill;
 
956
 
 
957
                if (instance->empty_stacks_fill == FCS_ES_FILLED_BY_ANY_CARD)
 
958
                {
 
959
                    freestacks_to_fill = min(num_cards_to_relocate, num_freestacks);
 
960
 
 
961
                    num_cards_to_relocate -= freestacks_to_fill;
 
962
                }
 
963
                else
 
964
                {
 
965
                    freestacks_to_fill = 0;
 
966
                }
 
967
 
 
968
                if ((num_cards_to_relocate == 0) &&
 
969
                   (calc_max_sequence_move(num_freecells-freecells_to_fill, num_freestacks-freestacks_to_fill) >=
 
970
                    seq_end - c + 1))
 
971
                {
 
972
                    /* We can move it */
 
973
                    int from_which_stack;
 
974
 
 
975
                    sfs_check_state_begin()
 
976
 
 
977
 
 
978
                    /* Fill the freecells with the top cards */
 
979
 
 
980
                    my_copy_stack(stack);
 
981
                    my_copy_stack(ds);
 
982
 
 
983
                    for(a=0 ; a<freecells_to_fill ; a++)
 
984
                    {
 
985
                        /* Find a vacant freecell */
 
986
                        for(b=0;b<state_freecells_num;b++)
 
987
                        {
 
988
                            if (fcs_freecell_card_num(new_state, b) == 0)
 
989
                            {
 
990
                                break;
 
991
                            }
 
992
                        }
 
993
 
 
994
                        if (fcs_stack_len(new_state, ds) == dc+1)
 
995
                        {
 
996
                            from_which_stack = stack;
 
997
                        }
 
998
                        else
 
999
                        {
 
1000
                            from_which_stack = ds;
 
1001
                        }
 
1002
                        my_copy_stack(from_which_stack);
 
1003
                        
 
1004
                        fcs_pop_stack_card(new_state, from_which_stack, temp_card);
 
1005
 
 
1006
                        fcs_put_card_in_freecell(new_state, b, temp_card);
 
1007
 
 
1008
                        fcs_move_set_type(temp_move,FCS_MOVE_TYPE_STACK_TO_FREECELL);
 
1009
                        fcs_move_set_src_stack(temp_move,from_which_stack);
 
1010
                        fcs_move_set_dest_freecell(temp_move,b);
 
1011
                        fcs_move_stack_push(moves, temp_move);
 
1012
 
 
1013
                        fcs_flip_top_card(from_which_stack);
 
1014
                    }
 
1015
 
 
1016
                    /* Fill the free stacks with the cards below them */
 
1017
                    for(a=0; a < freestacks_to_fill ; a++)
 
1018
                    {
 
1019
                        /*  Find a vacant stack */
 
1020
                        for(b=0;b<state_stacks_num;b++)
 
1021
                        {
 
1022
                            if (fcs_stack_len(new_state, b) == 0)
 
1023
                            {
 
1024
                                break;
 
1025
                            }
 
1026
                        }
 
1027
 
 
1028
                        if (fcs_stack_len(new_state, ds) == dc+1)
 
1029
                        {
 
1030
                            from_which_stack = stack;
 
1031
                        }
 
1032
                        else
 
1033
                        {
 
1034
                            from_which_stack = ds;
 
1035
                        }
 
1036
                        
 
1037
                        my_copy_stack(b);
 
1038
                        fcs_pop_stack_card(new_state, from_which_stack, temp_card);
 
1039
                        fcs_push_card_into_stack(new_state, b, temp_card);
 
1040
                        fcs_move_set_type(temp_move,FCS_MOVE_TYPE_STACK_TO_STACK);
 
1041
                        fcs_move_set_src_stack(temp_move,from_which_stack);
 
1042
                        fcs_move_set_dest_stack(temp_move,b);
 
1043
                        fcs_move_set_num_cards_in_seq(temp_move,1);
 
1044
                        fcs_move_stack_push(moves, temp_move);
 
1045
 
 
1046
                        fcs_flip_top_card(from_which_stack);
 
1047
                    }
 
1048
 
 
1049
                    for(a=c ; a <= seq_end ; a++)
 
1050
                    {
 
1051
                        fcs_push_stack_card_into_stack(new_state, ds, stack, a);
 
1052
                    }
 
1053
 
 
1054
                    for(a=0; a < seq_end-c+1 ;a++)
 
1055
                    {
 
1056
                        fcs_pop_stack_card(new_state, stack, temp_card);
 
1057
                    }
 
1058
                    fcs_move_set_type(temp_move,FCS_MOVE_TYPE_STACK_TO_STACK);
 
1059
                    fcs_move_set_src_stack(temp_move,stack);
 
1060
                    fcs_move_set_dest_stack(temp_move,ds);
 
1061
                    fcs_move_set_num_cards_in_seq(temp_move,seq_end-c+1);
 
1062
                    fcs_move_stack_push(moves, temp_move);
 
1063
 
 
1064
                    fcs_flip_top_card(stack);
 
1065
 
 
1066
                    sfs_check_state_end()
1005
1067
                }
1006
1068
            }
1007
1069
        }
1008
1070
    }
1009
1071
 
 
1072
    free (positions_by_rank);
 
1073
 
1010
1074
    return FCS_STATE_IS_NOT_SOLVEABLE;
1011
1075
}
1012
1076
 
1013
1077
 
1014
1078
 
1015
 
int freecell_solver_sfs_move_sequences_to_free_stacks(
1016
 
        freecell_solver_soft_thread_t * soft_thread,
1017
 
        fcs_state_with_locations_t * ptr_state_with_locations,
 
1079
int fc_solve_sfs_move_sequences_to_free_stacks(
 
1080
        fc_solve_soft_thread_t * soft_thread,
 
1081
        fcs_state_t * ptr_state_key,
 
1082
        fcs_state_extra_info_t * ptr_state_val,
1018
1083
        int num_freestacks,
1019
1084
        int num_freecells,
1020
1085
        fcs_derived_states_list_t * derived_states_list,
1255
1320
 
1256
1321
 
1257
1322
 
1258
 
int freecell_solver_sfs_move_freecell_cards_to_empty_stack(
1259
 
        freecell_solver_soft_thread_t * soft_thread,
1260
 
        fcs_state_with_locations_t * ptr_state_with_locations,
 
1323
int fc_solve_sfs_move_freecell_cards_to_empty_stack(
 
1324
        fc_solve_soft_thread_t * soft_thread,
 
1325
        fcs_state_t * ptr_state_key,
 
1326
        fcs_state_extra_info_t * ptr_state_val,
1261
1327
        int num_freestacks,
1262
1328
        int num_freecells,
1263
1329
        fcs_derived_states_list_t * derived_states_list,
1326
1392
    return FCS_STATE_IS_NOT_SOLVEABLE;
1327
1393
}
1328
1394
 
1329
 
int freecell_solver_sfs_move_cards_to_a_different_parent(
1330
 
        freecell_solver_soft_thread_t * soft_thread,
1331
 
        fcs_state_with_locations_t * ptr_state_with_locations,
 
1395
int fc_solve_sfs_move_cards_to_a_different_parent(
 
1396
        fc_solve_soft_thread_t * soft_thread,
 
1397
        fcs_state_t * ptr_state_key,
 
1398
        fcs_state_extra_info_t * ptr_state_val,
1332
1399
        int num_freestacks,
1333
1400
        int num_freecells,
1334
1401
        fcs_derived_states_list_t * derived_states_list,
1548
1615
 
1549
1616
 
1550
1617
 
1551
 
int freecell_solver_sfs_empty_stack_into_freecells(
1552
 
        freecell_solver_soft_thread_t * soft_thread,
1553
 
        fcs_state_with_locations_t * ptr_state_with_locations,
 
1618
int fc_solve_sfs_empty_stack_into_freecells(
 
1619
        fc_solve_soft_thread_t * soft_thread,
 
1620
        fcs_state_t * ptr_state_key,
 
1621
        fcs_state_extra_info_t * ptr_state_val,
1554
1622
        int num_freestacks,
1555
1623
        int num_freecells,
1556
1624
        fcs_derived_states_list_t * derived_states_list,
1624
1692
 
1625
1693
}
1626
1694
 
1627
 
int freecell_solver_sfs_yukon_do_nothing(
1628
 
        freecell_solver_soft_thread_t * soft_thread,
1629
 
        fcs_state_with_locations_t * ptr_state_with_locations,
 
1695
int fc_solve_sfs_yukon_do_nothing(
 
1696
        fc_solve_soft_thread_t * soft_thread,
 
1697
        fcs_state_t * ptr_state_key,
 
1698
        fcs_state_extra_info_t * ptr_state_val,
1630
1699
        int num_freestacks,
1631
1700
        int num_freecells,
1632
1701
        fcs_derived_states_list_t * derived_states_list,
1636
1705
    return FCS_STATE_IS_NOT_SOLVEABLE;
1637
1706
}
1638
1707
 
1639
 
int freecell_solver_sfs_yukon_move_card_to_parent(
1640
 
        freecell_solver_soft_thread_t * soft_thread,
1641
 
        fcs_state_with_locations_t * ptr_state_with_locations,
 
1708
int fc_solve_sfs_yukon_move_card_to_parent(
 
1709
        fc_solve_soft_thread_t * soft_thread,
 
1710
        fcs_state_t * ptr_state_key,
 
1711
        fcs_state_extra_info_t * ptr_state_val,
1642
1712
        int num_freestacks,
1643
1713
        int num_freecells,
1644
1714
        fcs_derived_states_list_t * derived_states_list,
1713
1783
    return FCS_STATE_IS_NOT_SOLVEABLE;
1714
1784
}
1715
1785
 
1716
 
int freecell_solver_sfs_yukon_move_kings_to_empty_stack(
1717
 
        freecell_solver_soft_thread_t * soft_thread,
1718
 
        fcs_state_with_locations_t * ptr_state_with_locations,
 
1786
int fc_solve_sfs_yukon_move_kings_to_empty_stack(
 
1787
        fc_solve_soft_thread_t * soft_thread,
 
1788
        fcs_state_t * ptr_state_key,
 
1789
        fcs_state_extra_info_t * ptr_state_val,
1719
1790
        int num_freestacks,
1720
1791
        int num_freecells,
1721
1792
        fcs_derived_states_list_t * derived_states_list,
1787
1858
    Let's try to deal the Gypsy-type Talon.
1788
1859
 
1789
1860
  */
1790
 
int freecell_solver_sfs_deal_gypsy_talon(
1791
 
        freecell_solver_soft_thread_t * soft_thread,
1792
 
        fcs_state_with_locations_t * ptr_state_with_locations,
 
1861
int fc_solve_sfs_deal_gypsy_talon(
 
1862
        fc_solve_soft_thread_t * soft_thread,
 
1863
        fcs_state_t * ptr_state_key,
 
1864
        fcs_state_extra_info_t * ptr_state_val,
1793
1865
        int num_freestacks,
1794
1866
        int num_freecells,
1795
1867
        fcs_derived_states_list_t * derived_states_list,
1834
1906
}
1835
1907
 
1836
1908
 
1837
 
int freecell_solver_sfs_get_card_from_klondike_talon(
1838
 
        freecell_solver_soft_thread_t * soft_thread,
1839
 
        fcs_state_with_locations_t * ptr_state_with_locations,
 
1909
int fc_solve_sfs_get_card_from_klondike_talon(
 
1910
        fc_solve_soft_thread_t * soft_thread,
 
1911
        fcs_state_t * ptr_state_key,
 
1912
        fcs_state_extra_info_t * ptr_state_val,
1840
1913
        int num_freestacks,
1841
1914
        int num_freecells,
1842
1915
        fcs_derived_states_list_t * derived_states_list,
1978
2051
       
1979
2052
#endif
1980
2053
 
1981
 
int freecell_solver_sfs_atomic_move_card_to_empty_stack(
1982
 
        freecell_solver_soft_thread_t * soft_thread,
1983
 
        fcs_state_with_locations_t * ptr_state_with_locations,
 
2054
int fc_solve_sfs_atomic_move_card_to_empty_stack(
 
2055
        fc_solve_soft_thread_t * soft_thread,
 
2056
        fcs_state_t * ptr_state_key,
 
2057
        fcs_state_extra_info_t * ptr_state_val,
1984
2058
        int num_freestacks,
1985
2059
        int num_freecells,
1986
2060
        fcs_derived_states_list_t * derived_states_list,
2063
2137
    return FCS_STATE_IS_NOT_SOLVEABLE;
2064
2138
}
2065
2139
 
2066
 
int freecell_solver_sfs_atomic_move_card_to_parent(
2067
 
        freecell_solver_soft_thread_t * soft_thread,
2068
 
        fcs_state_with_locations_t * ptr_state_with_locations,
 
2140
int fc_solve_sfs_atomic_move_card_to_parent(
 
2141
        fc_solve_soft_thread_t * soft_thread,
 
2142
        fcs_state_t * ptr_state_key,
 
2143
        fcs_state_extra_info_t * ptr_state_val,
2069
2144
        int num_freestacks,
2070
2145
        int num_freecells,
2071
2146
        fcs_derived_states_list_t * derived_states_list,
2139
2214
    return FCS_STATE_IS_NOT_SOLVEABLE;
2140
2215
}
2141
2216
 
2142
 
int freecell_solver_sfs_atomic_move_card_to_freecell(
2143
 
        freecell_solver_soft_thread_t * soft_thread,
2144
 
        fcs_state_with_locations_t * ptr_state_with_locations,
 
2217
int fc_solve_sfs_atomic_move_card_to_freecell(
 
2218
        fc_solve_soft_thread_t * soft_thread,
 
2219
        fcs_state_t * ptr_state_key,
 
2220
        fcs_state_extra_info_t * ptr_state_val,
2145
2221
        int num_freestacks,
2146
2222
        int num_freecells,
2147
2223
        fcs_derived_states_list_t * derived_states_list,
2213
2289
    return FCS_STATE_IS_NOT_SOLVEABLE;
2214
2290
}
2215
2291
 
2216
 
int freecell_solver_sfs_atomic_move_freecell_card_to_parent(
2217
 
        freecell_solver_soft_thread_t * soft_thread,
2218
 
        fcs_state_with_locations_t * ptr_state_with_locations,
 
2292
int fc_solve_sfs_atomic_move_freecell_card_to_parent(
 
2293
        fc_solve_soft_thread_t * soft_thread,
 
2294
        fcs_state_t * ptr_state_key,
 
2295
        fcs_state_extra_info_t * ptr_state_val,
2219
2296
        int num_freestacks,
2220
2297
        int num_freecells,
2221
2298
        fcs_derived_states_list_t * derived_states_list,
2286
2363
    return FCS_STATE_IS_NOT_SOLVEABLE;
2287
2364
}
2288
2365
 
2289
 
int freecell_solver_sfs_atomic_move_freecell_card_to_empty_stack(
2290
 
        freecell_solver_soft_thread_t * soft_thread,
2291
 
        fcs_state_with_locations_t * ptr_state_with_locations,
 
2366
int fc_solve_sfs_atomic_move_freecell_card_to_empty_stack(
 
2367
        fc_solve_soft_thread_t * soft_thread,
 
2368
        fcs_state_t * ptr_state_key,
 
2369
        fcs_state_extra_info_t * ptr_state_val,
2292
2370
        int num_freestacks,
2293
2371
        int num_freecells,
2294
2372
        fcs_derived_states_list_t * derived_states_list,
2380
2458
#undef new_state
2381
2459
 
2382
2460
 
2383
 
freecell_solver_solve_for_state_test_t freecell_solver_sfs_tests[FCS_TESTS_NUM] =
 
2461
fc_solve_solve_for_state_test_t fc_solve_sfs_tests[FCS_TESTS_NUM] =
2384
2462
{
2385
 
    freecell_solver_sfs_move_top_stack_cards_to_founds,
2386
 
    freecell_solver_sfs_move_freecell_cards_to_founds,
2387
 
    freecell_solver_sfs_move_freecell_cards_on_top_of_stacks,
2388
 
    freecell_solver_sfs_move_non_top_stack_cards_to_founds,
2389
 
    freecell_solver_sfs_move_stack_cards_to_different_stacks,
2390
 
    freecell_solver_sfs_move_stack_cards_to_a_parent_on_the_same_stack,
2391
 
    freecell_solver_sfs_move_sequences_to_free_stacks,
2392
 
    freecell_solver_sfs_move_freecell_cards_to_empty_stack,
2393
 
    freecell_solver_sfs_move_cards_to_a_different_parent,
2394
 
    freecell_solver_sfs_empty_stack_into_freecells,
2395
 
    freecell_solver_sfs_simple_simon_move_sequence_to_founds,
2396
 
    freecell_solver_sfs_simple_simon_move_sequence_to_true_parent,
2397
 
    freecell_solver_sfs_simple_simon_move_whole_stack_sequence_to_false_parent,
2398
 
    freecell_solver_sfs_simple_simon_move_sequence_to_true_parent_with_some_cards_above,
2399
 
    freecell_solver_sfs_simple_simon_move_sequence_with_some_cards_above_to_true_parent,
2400
 
    freecell_solver_sfs_simple_simon_move_sequence_with_junk_seq_above_to_true_parent_with_some_cards_above,
2401
 
    freecell_solver_sfs_simple_simon_move_whole_stack_sequence_to_false_parent_with_some_cards_above,
2402
 
    freecell_solver_sfs_simple_simon_move_sequence_to_parent_on_the_same_stack,
2403
 
    freecell_solver_sfs_atomic_move_card_to_empty_stack,
2404
 
    freecell_solver_sfs_atomic_move_card_to_parent,
2405
 
    freecell_solver_sfs_atomic_move_card_to_freecell,
2406
 
    freecell_solver_sfs_atomic_move_freecell_card_to_parent,
2407
 
    freecell_solver_sfs_atomic_move_freecell_card_to_empty_stack,
 
2463
    fc_solve_sfs_move_top_stack_cards_to_founds,
 
2464
    fc_solve_sfs_move_freecell_cards_to_founds,
 
2465
    fc_solve_sfs_move_freecell_cards_on_top_of_stacks,
 
2466
    fc_solve_sfs_move_non_top_stack_cards_to_founds,
 
2467
    fc_solve_sfs_move_stack_cards_to_different_stacks,
 
2468
    fc_solve_sfs_move_stack_cards_to_a_parent_on_the_same_stack,
 
2469
    fc_solve_sfs_move_sequences_to_free_stacks,
 
2470
    fc_solve_sfs_move_freecell_cards_to_empty_stack,
 
2471
    fc_solve_sfs_move_cards_to_a_different_parent,
 
2472
    fc_solve_sfs_empty_stack_into_freecells,
 
2473
    fc_solve_sfs_simple_simon_move_sequence_to_founds,
 
2474
    fc_solve_sfs_simple_simon_move_sequence_to_true_parent,
 
2475
    fc_solve_sfs_simple_simon_move_whole_stack_sequence_to_false_parent,
 
2476
    fc_solve_sfs_simple_simon_move_sequence_to_true_parent_with_some_cards_above,
 
2477
    fc_solve_sfs_simple_simon_move_sequence_with_some_cards_above_to_true_parent,
 
2478
    fc_solve_sfs_simple_simon_move_sequence_with_junk_seq_above_to_true_parent_with_some_cards_above,
 
2479
    fc_solve_sfs_simple_simon_move_whole_stack_sequence_to_false_parent_with_some_cards_above,
 
2480
    fc_solve_sfs_simple_simon_move_sequence_to_parent_on_the_same_stack,
 
2481
    fc_solve_sfs_atomic_move_card_to_empty_stack,
 
2482
    fc_solve_sfs_atomic_move_card_to_parent,
 
2483
    fc_solve_sfs_atomic_move_card_to_freecell,
 
2484
    fc_solve_sfs_atomic_move_freecell_card_to_parent,
 
2485
    fc_solve_sfs_atomic_move_freecell_card_to_empty_stack,
2408
2486
#if 0
2409
 
    freecell_solver_sfs_move_top_stack_cards_to_founds,
2410
 
    freecell_solver_sfs_yukon_move_card_to_parent,
2411
 
    freecell_solver_sfs_yukon_move_kings_to_empty_stack,
2412
 
    freecell_solver_sfs_yukon_do_nothing,
2413
 
    freecell_solver_sfs_yukon_do_nothing,
 
2487
    fc_solve_sfs_move_top_stack_cards_to_founds,
 
2488
    fc_solve_sfs_yukon_move_card_to_parent,
 
2489
    fc_solve_sfs_yukon_move_kings_to_empty_stack,
 
2490
    fc_solve_sfs_yukon_do_nothing,
 
2491
    fc_solve_sfs_yukon_do_nothing,
2414
2492
#endif
2415
 
    freecell_solver_sfs_yukon_do_nothing,
2416
 
    freecell_solver_sfs_yukon_do_nothing
 
2493
    fc_solve_sfs_yukon_do_nothing,
 
2494
    fc_solve_sfs_yukon_do_nothing
2417
2495
#ifdef FCS_WITH_TALONS
2418
2496
        ,
2419
 
    freecell_solver_sfs_deal_gypsy_talon,
2420
 
    freecell_solver_sfs_get_card_from_klondike_talon
 
2497
    fc_solve_sfs_deal_gypsy_talon,
 
2498
    fc_solve_sfs_get_card_from_klondike_talon
2421
2499
#endif
2422
2500
};