Commits

Shlomi Fish committed b56f4e3

Extracted the check_state_begin() function.

In the process, I had to convert fcs_duplicate_state() to receive pointers
instead of the actual structures. The code is much cleaner now.

Extracted fc_solve_sfs_check_state_begin() from the sfs_check_state_begin()
macro.

git-svn-id: file:///home/shlomif/Backup/svn-dumps/google-code/svnsync-repos/fc-solve/branches/extract-ansi-c-macros-into-functions@1410 e7e8a897-7ba4-4ee7-b36f-f4c66519b19a

Comments (0)

Files changed (6)

fc-solve/source/freecell.c

  * sequences_are_built_by - the type of sequences of this board.
  * */
 
+int fc_solve_sfs_check_state_begin(
+    fc_solve_hard_thread_t * hard_thread,
+    fcs_state_extra_info_t * * out_ptr_new_state_val,
+    fcs_state_t * * out_ptr_new_state_key,
+    fcs_state_extra_info_t * ptr_state_val,
+    fcs_move_stack_t * moves
+    )
+{
+    fcs_state_extra_info_t * ptr_new_state_val;
+
+    fcs_state_ia_alloc_into_var(ptr_new_state_val, hard_thread);
+    *(out_ptr_new_state_key) = ptr_new_state_val->key;
+    fcs_duplicate_state(
+            (*(out_ptr_new_state_key)),
+            ptr_new_state_val,
+            ptr_state_val->key, 
+            ptr_state_val
+    );
+    /* Some A* and BFS parameters that need to be initialized in
+     * the derived state.
+     * */
+    ptr_new_state_val->parent_val = ptr_state_val;
+    ptr_new_state_val->moves_to_parent = moves;
+    /* Make sure depth is consistent with the game graph.
+     * I.e: the depth of every newly discovered state is derived from
+     * the state from which it was discovered. */
+    ptr_new_state_val->depth = ptr_new_state_val->depth + 1;
+    /* Mark this state as a state that was not yet visited */
+    ptr_new_state_val->visited = 0;
+    /* It's a newly created state which does not have children yet. */
+    ptr_new_state_val->num_active_children = 0;
+    memset(ptr_new_state_val->scan_visited, '\0',
+        sizeof(ptr_new_state_val->scan_visited)
+        );
+    fcs_move_stack_reset(moves);
+
+    *out_ptr_new_state_val = ptr_new_state_val;
+
+    return 0;
+}
+
 /*
  * This function tries to move stack cards that are present at the
  * top of stacks to the foundations.

fc-solve/source/intrface.c

 
     state_copy_ptr_key = state_copy_ptr_val->key;
 
-    fcs_duplicate_state(*state_copy_ptr_key, *state_copy_ptr_val,
-            (*(init_state_val->key)), *init_state_val
+    fcs_duplicate_state(state_copy_ptr_key, state_copy_ptr_val,
+            ((init_state_val->key)), init_state_val
             );
 
     {

fc-solve/source/lib.c

              * state to it before state is canonized
              * */
             fcs_duplicate_state(
-                user->running_state.s,
-                user->running_state.info,
-                user->state.s,
-                user->state.info
+                &(user->running_state.s),
+                &(user->running_state.info),
+                &(user->state.s),
+                &(user->state.info)
                 );
 
             fc_solve_canonize_state(

fc-solve/source/move.c

     fcs_move_stack_alloc_into_var(temp_moves);
 
     fcs_duplicate_state(
-            dynamic_state.s, dynamic_state.info,
-            *(init_state_val->key), *init_state_val
+            &(dynamic_state.s), &(dynamic_state.info),
+            (init_state_val->key), init_state_val
             );
 #ifdef INDIRECT_STACK_STATES
     for(a=0;a<stacks_num;a++)

fc-solve/source/state.h

         (state).stacks[(ds)].num_cards++;  \
     }
 
-#define fcs_duplicate_state(dest_key, dest_val, src_key, src_val) \
+#define fcs_duplicate_state(ptr_dest_key, ptr_dest_val, ptr_src_key, ptr_src_val) \
     { \
-    (dest_key) = (src_key); \
-    (dest_val) = (src_val); \
-    (dest_val).key = &(dest_key); \
+    *(ptr_dest_key) = *(ptr_src_key); \
+    *(ptr_dest_val) = *(ptr_src_val); \
+    (ptr_dest_val)->key = ptr_dest_key; \
     }
 
 #define fcs_put_card_in_freecell(state, f, card) \
 #define fcs_push_stack_card_into_stack(state, ds, ss, sc) \
     fcs_push_card_into_stack((state), (ds), fcs_stack_card((state), (ss), (sc)))
 
-#define fcs_duplicate_state(dest_key, dest_val, src_key, src_val) \
+#define fcs_duplicate_state(ptr_dest_key, ptr_dest_val, ptr_src_key, ptr_src_val) \
     { \
-    (dest_key) = (src_key); \
-    (dest_val) = (src_val); \
-    (dest_val).key = &(dest_key); \
+    *(ptr_dest_key) = *(ptr_src_key); \
+    *(ptr_dest_val) = *(ptr_src_val); \
+    (ptr_dest_val)->key = ptr_dest_key; \
     }
 
 #define fcs_put_card_in_freecell(state, f, card) \
 #define fcs_flip_stack_card(state, s, c) \
     (fcs_card_set_flipped(fcs_stack_card(state,s,c), ((fcs_card_t)0) ))
 
-
-#define fcs_duplicate_state(dest_key, dest_val, src_key, src_val) \
+#define fcs_duplicate_state(ptr_dest_key, ptr_dest_val, ptr_src_key, ptr_src_val) \
     { \
-    (dest_key) = (src_key); \
-    (dest_val) = (src_val); \
-    (dest_val).key = &(dest_key); \
-    (dest_val).stacks_copy_on_write_flags = 0; \
+    *(ptr_dest_key) = *(ptr_src_key); \
+    *(ptr_dest_val) = *(ptr_src_val); \
+    (ptr_dest_val)->key = ptr_dest_key; \
+    (ptr_dest_val)->stacks_copy_on_write_flags = 0; \
     }
 
 #define fcs_copy_stack(state_key, state_val, idx, buffer) \

fc-solve/source/tests.h

 #define new_state_key (new_state)
 #define new_state_val (*ptr_new_state_val)
 
-#define sfs_check_state_begin()                                                \
-    fcs_state_ia_alloc_into_var(ptr_new_state_val, hard_thread);    \
-    ptr_new_state_key = ptr_new_state_val->key;                     \
-    fcs_duplicate_state(new_state_key, new_state_val, state_key, state_val);       \
-    /* Some A* and BFS parameters that need to be initialized in               \
-     * the derived state.                                                      \
-     * */                                                                      \
-    ptr_new_state_val->parent_val = ptr_state_val;           \
-    ptr_new_state_val->moves_to_parent = moves;                     \
-    /* Make sure depth is consistent with the game graph.                      \
-     * I.e: the depth of every newly discovered state is derived from          \
-     * the state from which it was discovered. */                              \
-    ptr_new_state_val->depth = ptr_new_state_val->depth + 1; \
-    /* Mark this state as a state that was not yet visited */                  \
-    ptr_new_state_val->visited = 0;                                 \
-    /* It's a newly created state which does not have children yet. */         \
-    ptr_new_state_val->num_active_children = 0;                     \
-    memset(ptr_new_state_val->scan_visited, '\0',                   \
-        sizeof(ptr_new_state_val->scan_visited)                     \
-        );                                                                     \
-    fcs_move_stack_reset(moves);                                               \
+extern int fc_solve_sfs_check_state_begin(
+    fc_solve_hard_thread_t * hard_thread,
+    fcs_state_extra_info_t * * out_ptr_new_state_val,
+    fcs_state_t * * out_ptr_state_key,
+    fcs_state_extra_info_t * ptr_state_val,
+    fcs_move_stack_t * moves
+    );
+
+#define sfs_check_state_begin()                                     \
+    {         \
+        fc_solve_sfs_check_state_begin(hard_thread,  \
+                &ptr_new_state_val,                  \
+                &ptr_new_state_key,                  \
+                ptr_state_val,                       \
+                moves);                              \
+    }
 
 #define sfs_check_state_end()                                             \
 /* The last move in a move stack should be FCS_MOVE_TYPE_CANONIZE         \