Commits

Shlomi Fish committed fb79793

Reenable the non-debondt delta_states.c

Comments (0)

Files changed (5)

fc-solve/source/CMakeLists.txt

     "States Type ('INDIRECT_STACK_STATES', 'COMPACT_STATES' or 'DEBUG_STATES'). No need to usually change.")
 SET (FCS_ENABLE_RCS_STATES CACHE BOOL "Whether to use RCS-like states (requires a STATES_TYPE of COMPACT_STATES")
 SET (FCS_ENABLE_DBM_SOLVER CACHE BOOL "Whether to build the DBM solver")
+SET (FCS_DISABLE_DEBONDT_DELTA_STATES CACHE BOOL "Debondt Delta States")
 SET (FCS_DBM_BACKEND "bdb" CACHE STRING "Type of DBM backend.")
 SET (FCS_DBM_TREE_BACKEND "libavl2" CACHE STRING "Type of DBM tree backend.")
 SET (IA_STATE_PACKS_GROW_BY 32 CACHE STRING "Amount to Grow State Packs By")
 SET (DEBONDT_DELTA_STATES )
 IF (FCS_ENABLE_DBM_SOLVER)
     FIND_LIBRARY(LIBGMP_LIB gmp)
-    ADD_DEFINITIONS("-DFCS_DEBONDT_DELTA_STATES=1")
-    SET (DEBONDT_DELTA_STATES 1)
+    IF (FCS_DISABLE_DEBONDT_DELTA_STATES)
+    ELSE (FCS_DISABLE_DEBONDT_DELTA_STATES)
+        ADD_DEFINITIONS("-DFCS_DEBONDT_DELTA_STATES=1")
+        SET (DEBONDT_DELTA_STATES 1)
+    ENDIF (FCS_DISABLE_DEBONDT_DELTA_STATES)
 
     SET (DBM_BACKEND_MODULES )
     SET (DBM_LIBS "pthread")
 
 IF (FCS_WITH_TEST_SUITE)
 
+    SET (MYENV )
+    IF (DEBONDT_DELTA_STATES)
+        SET (MYENV "FCS_DEBONDT=1")
+    ENDIF (DEBONDT_DELTA_STATES)
     ADD_CUSTOM_TARGET(
         "test"
+        ${MYENV}
         "perl" "${CMAKE_CURRENT_SOURCE_DIR}/run-tests.pl"
     )
 

fc-solve/source/Tatzer

 my $build_docs = 1;
 my $with_dbm_solver;
 my $max_num_stacks;
+my $disable_debondt;
 
 my $google_stack_storage;
 my $google_state_storage;
     'scan-buckets-num=i' => \$scan_buckets_num,
     'build-docs!' => \$build_docs,
     'num-stacks=i' => \$max_num_stacks,
+    'disable-debondt!' => \$disable_debondt,
 ) or
     die "Wrong options";
 
         ? ("-DFCS_ENABLE_DBM_SOLVER=1", "-DFCS_DBM_BACKEND=$with_dbm_solver",)
         : ()
     ),
+    ($disable_debondt ? ("-DFCS_DISABLE_DEBONDT_DELTA_STATES=1") : ()),
 );
 
 

fc-solve/source/delta_states.c

         fcs_cards_column_t col
         )
 {
-    int num_cards;
 #ifndef FCS_FREECELL_ONLY
-    int sequences_are_built_by;
+    int sequences_are_built_by = self->sequences_are_built_by;
 #endif
 
-
-#ifndef FCS_FREECELL_ONLY
-    sequences_are_built_by = self->sequences_are_built_by;
-#endif
+    int num_cards;
     for (num_cards = fcs_col_len(col); num_cards >= 2; num_cards--)
     {
         fcs_card_t child_card = fcs_col_get_card(col, num_cards-1);
 #endif
         )
 {
-    int col_idx;
-    int max_num_cards;
-
     fc_solve_delta_stater_t * self = SMALLOC1(self);
 
 #ifndef FCS_FREECELL_ONLY
 
     self->_init_state = init_state;
 
-    max_num_cards = 0;
-    for (col_idx = 0 ; col_idx < num_columns; col_idx++)
+    int max_num_cards = 0;
+    for (int col_idx = 0 ; col_idx < num_columns; col_idx++)
     {
-        int num_cards;
-
-        num_cards = fc_solve_get_column_orig_num_cards(self, fcs_state_get_col(*init_state, col_idx));
+        const int num_cards = fc_solve_get_column_orig_num_cards(self, fcs_state_get_col(*init_state, col_idx));
 
         if (num_cards > max_num_cards)
         {
 } fc_solve_column_encoding_composite_t;
 
 static void fc_solve_get_column_encoding_composite(
-        fc_solve_delta_stater_t * self,
-        int col_idx,
-        fc_solve_column_encoding_composite_t * ret
+        fc_solve_delta_stater_t * const self,
+        const int col_idx,
+        fc_solve_column_encoding_composite_t * const ret
         )
 {
-    fcs_state_t * derived;
-    fcs_cards_column_t col;
-    int num_orig_cards;
-    int col_len;
-    int num_derived_cards;
-    int num_cards_in_seq;
-    fcs_card_t init_card;
-    fc_solve_bit_writer_t bit_w;
-    int i;
-
-    derived = self->_derived_state;
-    col = fcs_state_get_col(*derived, col_idx);
+    fcs_state_t * const derived = self->_derived_state;
+    fcs_cards_column_t col = fcs_state_get_col(*derived, col_idx);
 
-    num_orig_cards = fc_solve_get_column_orig_num_cards(self, col);
-    col_len = fcs_col_len(col);
-    num_derived_cards = col_len - num_orig_cards;
+    const int num_orig_cards = fc_solve_get_column_orig_num_cards(self, col);
+    const int col_len = fcs_col_len(col);
+    const int num_derived_cards = col_len - num_orig_cards;
 
-    num_cards_in_seq = num_derived_cards;
-    init_card = fc_solve_empty_card;
+    int num_cards_in_seq = num_derived_cards;
+    fcs_card_t init_card = fc_solve_empty_card;
 
     if ((num_orig_cards == 0) && num_derived_cards)
     {
         num_cards_in_seq--;
     }
 
+    fc_solve_bit_writer_t bit_w;
     /* Prepare the encoding. */
     fc_solve_bit_writer_init(&bit_w, ret->enc);
 
         fc_solve_bit_writer_write(&bit_w, 6, init_card);
     }
 
-    for (i=col_len-num_cards_in_seq ; i<col_len; i++)
+    for (int i=col_len-num_cards_in_seq ; i<col_len; i++)
     {
 #define GET_SUIT_BIT(card) (( (fcs_card_suit(card)) & 0x2 ) >> 1 )
 
         )
 {
     fcs_card_t freecells[MAX_NUM_FREECELLS];
-    int i, j, min_idx;
-    fcs_state_t * derived;
-    int num_freecells;
-    fcs_card_t min_card;
 
-    derived = self->_derived_state;
-    num_freecells = self->num_freecells;
+    fcs_state_t * const derived = self->_derived_state;
+    const int num_freecells = self->num_freecells;
 
-    for (i=0 ; i < num_freecells ; i++)
+    for (int i=0 ; i < num_freecells ; i++)
     {
         freecells[i] = fcs_freecell_card(*derived, i);
     }
 
+
     /* Sort the freecells using selection-sort. */
-    for (i=0 ; i < num_freecells ; i++)
+    for (int i=0 ; i < num_freecells ; i++)
     {
-        min_idx = i;
-        for (j=i+1 ; j < num_freecells ; j++)
+        int min_idx = i;
+        fcs_card_t min_card;
+        for (int j=i+1 ; j < num_freecells ; j++)
         {
             if (freecells[j] < freecells[min_idx])
             {
 }
 
 static void fc_solve_delta_stater_encode_composite(
-        fc_solve_delta_stater_t * self,
-        fc_solve_bit_writer_t * bit_w
+        fc_solve_delta_stater_t * const self,
+        fc_solve_bit_writer_t * const bit_w
         )
 {
     int cols_indexes[MAX_NUM_STACKS];
     fc_solve_column_encoding_composite_t cols[MAX_NUM_STACKS];
     fcs_state_t * derived;
-    int i, swap_int;
+    int swap_int;
     int num_columns;
 
     derived = self->_derived_state;
 
     num_columns = self->num_columns;
-    for ( i=0 ; i < num_columns ; i++)
+    for (int  i=0 ; i < num_columns ; i++)
     {
         cols_indexes[i] = i;
         fc_solve_get_column_encoding_composite(self, i, &(cols[i]));
         int new_non_orig_cols_indexes_count;
 
         /* Filter the new_non_orig_cols_indexes */
-        for (new_non_orig_cols_indexes_count = 0, i=0; i < num_columns ; i++)
+        new_non_orig_cols_indexes_count = 0;
+        for (int i = 0 ; i < num_columns ; i++)
         {
             if (cols[cols_indexes[i]].type == COL_TYPE_ENTIRELY_NON_ORIG)
             {
         {
             int c;
 
-#define b i
 #define COMP_BY(idx) (fcs_col_get_card(fcs_state_get_col((*derived), (idx)), 0))
 #define ITEM_IDX(idx) (new_non_orig_cols_indexes[idx])
 #define COMP_BY_IDX(idx) (COMP_BY(ITEM_IDX(idx)))
 
-            for (b=1 ; b < new_non_orig_cols_indexes_count ; b++)
+            for (int b=1 ; b < new_non_orig_cols_indexes_count ; b++)
             {
                 for (c = b; (c>0) && (COMP_BY_IDX(c-1) > COMP_BY_IDX(c)) ; c--)
                 {
         }
 
         {
-            int sorted_idx;
-            for ( i=0 , sorted_idx = 0; i < num_columns ; i++)
+            for (int i=0 , sorted_idx = 0; i < num_columns ; i++)
             {
                 if (cols[cols_indexes[i]].type == COL_TYPE_ENTIRELY_NON_ORIG)
                 {
     }
 
     fc_solve_get_freecells_encoding(self, bit_w);
-    for ( i=0 ; i < num_columns ; i++)
+    for ( int i=0 ; i < num_columns ; i++)
     {
         fc_solve_column_encoding_composite_t * col_enc;
         fcs_uchar_t * enc;
 }
 
 static GCC_INLINE void fc_solve_delta_stater_decode_into_state_proto(
-        fc_solve_delta_stater_t * delta_stater,
         enum fcs_dbm_variant_type_t local_variant,
+        fc_solve_delta_stater_t * delta_stater,
         const fcs_uchar_t * const enc_state,
         fcs_state_keyval_pair_t * ret
         IND_BUF_T_PARAM(indirect_stacks_buffer)
 }
 
 #ifdef INDIRECT_STACK_STATES
-#define fc_solve_delta_stater_decode_into_state(delta_stater, enc_state, state_ptr, indirect_stacks_buffer) fc_solve_delta_stater_decode_into_state_proto(delta_stater, enc_state, state_ptr, indirect_stacks_buffer)
+#define fc_solve_delta_stater_decode_into_state(delta_stater, enc_state, state_ptr, indirect_stacks_buffer) fc_solve_delta_stater_decode_into_state_proto(local_variant, delta_stater, enc_state, state_ptr, indirect_stacks_buffer)
 #else
-#define fc_solve_delta_stater_decode_into_state(delta_stater, enc_state, state_ptr, indirect_stacks_buffer) fc_solve_delta_stater_decode_into_state_proto(delta_stater, enc_state, state_ptr)
+#define fc_solve_delta_stater_decode_into_state(delta_stater, enc_state, state_ptr, indirect_stacks_buffer) fc_solve_delta_stater_decode_into_state_proto(local_variant, delta_stater, enc_state, state_ptr)
 #endif
 
 static GCC_INLINE void fc_solve_delta_stater_encode_into_buffer(
 
 static GCC_INLINE void fcs_init_and_encode_state(
     fc_solve_delta_stater_t * delta_stater,
+    enum fcs_dbm_variant_type_t local_variant,
     fcs_state_keyval_pair_t * state,
     fcs_encoded_state_buffer_t * enc_state
 )

fc-solve/source/t/delta-states-test.c

 
 #include <tap.h>
 
+#ifndef FCS_COMPILE_DEBUG_FUNCTIONS
 #define FCS_COMPILE_DEBUG_FUNCTIONS
+#endif
+
 #include "../card.c"
 #include "../card_compare_lookups.c"
 #include "../app_str.c"
     char * as_str;
     DECLARE_IND_BUF_T(new_derived_indirect_stacks_buffer)
     fcs_state_locs_struct_t locs;
+    enum fcs_dbm_variant_type_t local_variant = FCS_DBM_VARIANT_2FC_FREECELL;
 
     fc_solve_init_locs(&locs);
 
     return verdict;
 }
 
-int main_tests()
+static int main_tests(void)
 {
+    enum fcs_dbm_variant_type_t local_variant = FCS_DBM_VARIANT_2FC_FREECELL;
     {
         fcs_state_keyval_pair_t s;
         fc_solve_delta_stater_t delta;
         char * s;
 
         s = fc_solve_user_INTERNAL_delta_states_enc_and_dec(
+            local_variant,
                 (
                  "Foundations: H-0 C-0 D-0 S-0 \n"
                  "Freecells:        \n"
 
         fcs_init_and_encode_state(
             delta,
+            local_variant,
             &derived_state,
             &first_enc_state
             );
 
         fcs_init_and_encode_state(
             delta,
+            local_variant,
             &derived_state,
             &second_enc_state
             );
         fcs_encoded_state_buffer_t first_enc_state;
         fcs_init_and_encode_state(
             delta,
+            local_variant,
             &derived_state,
             &first_enc_state
             );
         fcs_encoded_state_buffer_t second_enc_state;
         fcs_init_and_encode_state(
             delta,
+            local_variant,
             &derived_state,
             &second_enc_state
             );
 
 int main(int argc, char * argv[])
 {
-    plan_tests(28);
+    plan_tests(25);
     main_tests();
     return exit_status();
 }

fc-solve/source/t/t/fc-solve-output.t

 {
 
     my $WS = ' ';
-    my $needle = <<"EOF";
+    my $debondt_needle = <<"EOF";
 Success!
 --------
 Foundations: H-T C-8 D-A S-J$WS
 END
 EOF
 
+    my $non_debondt_needle = <<"EOF";
+Success!
+--------
+Foundations: H-T C-8 D-A S-J$WS
+Freecells:      7D
+: 3D
+: 4D
+: 5D
+: 6D
+: 2D KD QS JH TC 9D
+: KH QC JD
+: KC QH
+: KS QD JC TD 9C 8D
+
+==
+Column 4 -> Freecell 0
+--------
+Foundations: H-T C-8 D-A S-J$WS
+Freecells:  7D  9D
+: 3D
+: 4D
+: 5D
+: 6D
+: 2D KD QS JH TC
+: KH QC JD
+: KC QH
+: KS QD JC TD 9C 8D
+
+==
+Column 4 -> Column 5
+--------
+Foundations: H-T C-8 D-A S-J$WS
+Freecells:  7D  9D
+: 3D
+: 4D
+: 5D
+: 6D
+: 2D KD QS JH
+: KH QC JD TC
+: KC QH
+: KS QD JC TD 9C 8D
+
+==
+Freecell 1 -> Column 5
+--------
+Foundations: H-T C-8 D-A S-J$WS
+Freecells:      7D
+: 3D
+: 4D
+: 5D
+: 6D
+: 2D KD QS JH
+: KH QC JD TC 9D
+: KC QH
+: KS QD JC TD 9C 8D
+
+==
+Column 4 -> Foundation 0
+--------
+Foundations: H-J C-8 D-A S-J$WS
+Freecells:      7D
+: 3D
+: 4D
+: 5D
+: 6D
+: 2D KD QS
+: KH QC JD TC 9D
+: KC QH
+: KS QD JC TD 9C 8D
+
+==
+Column 4 -> Foundation 3
+--------
+Foundations: H-J C-8 D-A S-Q$WS
+Freecells:      7D
+: 3D
+: 4D
+: 5D
+: 6D
+: 2D KD
+: KH QC JD TC 9D
+: KC QH
+: KS QD JC TD 9C 8D
+
+==
+Column 4 -> Freecell 0
+--------
+Foundations: H-K C-K D-K S-K$WS
+Freecells:$WS$WS$WS$WS$WS$WS$WS$WS
+:$WS
+:$WS
+:$WS
+:$WS
+:$WS
+:$WS
+:$WS
+:$WS
+
+==
+END
+EOF
+
+    my $needle = $ENV{FCS_DEBONDT} ? $debondt_needle : $non_debondt_needle;
     my $dbm_output = trap_dbm(
         {
             board_fn =>