2021
1972
free(talon_temp->s.talon);
2022
1973
free(talon_temp);
2024
fcs_move_stack_destroy(moves);
2026
1975
return FCS_STATE_IS_NOT_SOLVEABLE;
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,
1986
fcs_derived_states_list_t * derived_states_list,
1990
tests_declare_accessors();
1991
int empty_stacks_filled_by, state_stacks_num;
1992
int stack, cards_num;
1993
fcs_card_t card, temp_card;
1994
fcs_move_t temp_move;
1996
int empty_stack_idx;
1998
tests_define_accessors();
2000
if (num_freestacks == 0)
2002
return FCS_STATE_IS_NOT_SOLVEABLE;
2005
state_stacks_num = instance->stacks_num;
2007
for(empty_stack_idx=0;empty_stack_idx<state_stacks_num;empty_stack_idx++)
2009
if (fcs_stack_len(state, empty_stack_idx) == 0)
2015
empty_stacks_filled_by = instance->empty_stacks_fill;
2017
if (empty_stacks_filled_by == FCS_ES_FILLED_BY_NONE)
2019
return FCS_STATE_IS_NOT_SOLVEABLE;
2024
for(stack=0;stack<state_stacks_num;stack++)
2026
cards_num = fcs_stack_len(state, stack);
2029
card = fcs_stack_card(state, stack, cards_num-1);
2030
if ((empty_stacks_filled_by == FCS_ES_FILLED_BY_KINGS_ONLY) &&
2031
(fcs_card_card_num(card) != 13))
2037
sfs_check_state_begin();
2039
my_copy_stack(stack);
2041
fcs_pop_stack_card(new_state, stack, temp_card);
2044
my_copy_stack(empty_stack_idx);
2046
fcs_push_card_into_stack(new_state, empty_stack_idx, card);
2048
fcs_move_set_type(temp_move, FCS_MOVE_TYPE_STACK_TO_STACK);
2049
fcs_move_set_src_stack(temp_move, stack);
2050
fcs_move_set_dest_stack(temp_move, empty_stack_idx);
2051
fcs_move_set_num_cards_in_seq(temp_move, 1);
2053
fcs_move_stack_push(moves, temp_move);
2055
fcs_move_set_type(temp_move,FCS_MOVE_TYPE_CANONIZE);
2056
fcs_move_stack_push(moves, temp_move);
2058
sfs_check_state_end()
2063
return FCS_STATE_IS_NOT_SOLVEABLE;
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,
2071
fcs_derived_states_list_t * derived_states_list,
2075
tests_declare_accessors();
2076
int state_stacks_num;
2077
int stack, cards_num, ds, ds_cards_num;
2078
fcs_card_t card, dest_card, temp_card;
2079
fcs_move_t temp_move;
2081
int sequences_are_built_by;
2083
tests_define_accessors();
2085
state_stacks_num = instance->stacks_num;
2087
sequences_are_built_by = instance->sequences_are_built_by;
2090
for(stack=0;stack<state_stacks_num;stack++)
2092
cards_num = fcs_stack_len(state, stack);
2095
card = fcs_stack_card(state, stack, cards_num-1);
2097
for(ds=0;ds<state_stacks_num;ds++)
2104
ds_cards_num = fcs_stack_len(state, ds);
2105
if (ds_cards_num > 0)
2107
dest_card = fcs_stack_card(state, ds, ds_cards_num-1);
2108
if (fcs_is_parent_card(card, dest_card))
2112
sfs_check_state_begin();
2114
my_copy_stack(stack);
2117
fcs_pop_stack_card(new_state, stack, temp_card);
2119
fcs_push_card_into_stack(new_state, ds, card);
2121
fcs_move_set_type(temp_move, FCS_MOVE_TYPE_STACK_TO_STACK);
2122
fcs_move_set_src_stack(temp_move, stack);
2123
fcs_move_set_dest_stack(temp_move, ds);
2124
fcs_move_set_num_cards_in_seq(temp_move, 1);
2126
fcs_move_stack_push(moves, temp_move);
2128
fcs_move_set_type(temp_move,FCS_MOVE_TYPE_CANONIZE);
2129
fcs_move_stack_push(moves, temp_move);
2131
sfs_check_state_end()
2139
return FCS_STATE_IS_NOT_SOLVEABLE;
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,
2147
fcs_derived_states_list_t * derived_states_list,
2151
tests_declare_accessors();
2152
int state_stacks_num;
2153
int state_freecells_num;
2154
int stack, cards_num, ds;
2155
fcs_card_t card, temp_card;
2156
fcs_move_t temp_move;
2158
int sequences_are_built_by;
2160
tests_define_accessors();
2162
state_stacks_num = instance->stacks_num;
2163
state_freecells_num = instance->freecells_num;
2165
sequences_are_built_by = instance->sequences_are_built_by;
2167
if (num_freecells == 0)
2169
return FCS_STATE_IS_NOT_SOLVEABLE;
2172
for(ds=0;ds<state_freecells_num;ds++)
2174
if (fcs_freecell_card_num(state, ds) == 0)
2182
for(stack=0;stack<state_stacks_num;stack++)
2184
cards_num = fcs_stack_len(state, stack);
2187
card = fcs_stack_card(state, stack, cards_num-1);
2191
sfs_check_state_begin();
2193
my_copy_stack(stack);
2195
fcs_pop_stack_card(new_state, stack, temp_card);
2197
fcs_put_card_in_freecell(new_state, ds, card);
2199
fcs_move_set_type(temp_move, FCS_MOVE_TYPE_STACK_TO_FREECELL);
2200
fcs_move_set_src_stack(temp_move, stack);
2201
fcs_move_set_dest_freecell(temp_move, ds);
2203
fcs_move_stack_push(moves, temp_move);
2205
fcs_move_set_type(temp_move,FCS_MOVE_TYPE_CANONIZE);
2206
fcs_move_stack_push(moves, temp_move);
2208
sfs_check_state_end()
2213
return FCS_STATE_IS_NOT_SOLVEABLE;
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,
2221
fcs_derived_states_list_t * derived_states_list,
2225
tests_declare_accessors();
2226
int state_stacks_num, state_freecells_num;
2227
int fc, ds, ds_cards_num;
2228
fcs_card_t card, dest_card;
2229
fcs_move_t temp_move;
2231
int sequences_are_built_by;
2233
tests_define_accessors();
2235
state_stacks_num = instance->stacks_num;
2236
state_freecells_num = instance->freecells_num;
2238
sequences_are_built_by = instance->sequences_are_built_by;
2243
for(fc=0;fc<state_freecells_num;fc++)
2245
card = fcs_freecell_card(state, fc);
2246
if (fcs_card_card_num(card) == 0)
2251
for(ds=0;ds<state_stacks_num;ds++)
2253
ds_cards_num = fcs_stack_len(state, ds);
2254
if (ds_cards_num > 0)
2256
dest_card = fcs_stack_card(state, ds, ds_cards_num-1);
2257
if (fcs_is_parent_card(card, dest_card))
2261
sfs_check_state_begin();
2265
fcs_empty_freecell(new_state, fc);
2267
fcs_push_card_into_stack(new_state, ds, card);
2269
fcs_move_set_type(temp_move, FCS_MOVE_TYPE_FREECELL_TO_STACK);
2270
fcs_move_set_src_freecell(temp_move, fc);
2271
fcs_move_set_dest_stack(temp_move, ds);
2272
fcs_move_set_num_cards_in_seq(temp_move, 1);
2274
fcs_move_stack_push(moves, temp_move);
2276
fcs_move_set_type(temp_move,FCS_MOVE_TYPE_CANONIZE);
2277
fcs_move_stack_push(moves, temp_move);
2279
sfs_check_state_end()
2286
return FCS_STATE_IS_NOT_SOLVEABLE;
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,
2294
fcs_derived_states_list_t * derived_states_list,
2298
tests_declare_accessors();
2299
int state_stacks_num, state_freecells_num;
2302
fcs_move_t temp_move;
2304
int sequences_are_built_by, empty_stacks_filled_by;
2306
tests_define_accessors();
2308
moves = hard_thread->reusable_move_stack;
2309
indirect_stacks_buffer = hard_thread->indirect_stacks_buffer;
2311
state_stacks_num = instance->stacks_num;
2312
state_freecells_num = instance->freecells_num;
2314
sequences_are_built_by = instance->sequences_are_built_by;
2316
if (num_freestacks == 0)
2318
return FCS_STATE_IS_NOT_SOLVEABLE;
2321
empty_stacks_filled_by = instance->empty_stacks_fill;
2323
if (empty_stacks_filled_by == FCS_ES_FILLED_BY_NONE)
2325
return FCS_STATE_IS_NOT_SOLVEABLE;
2328
for(ds=0;ds<state_stacks_num;ds++)
2330
if (fcs_stack_len(state, ds) == 0)
2336
for(fc=0;fc<state_freecells_num;fc++)
2338
card = fcs_freecell_card(state, fc);
2339
if (fcs_card_card_num(card) == 0)
2344
if ((empty_stacks_filled_by == FCS_ES_FILLED_BY_KINGS_ONLY) &&
2345
(fcs_card_card_num(card) != 13))
2351
sfs_check_state_begin();
2355
fcs_empty_freecell(new_state, fc);
2357
fcs_push_card_into_stack(new_state, ds, card);
2359
fcs_move_set_type(temp_move, FCS_MOVE_TYPE_FREECELL_TO_STACK);
2360
fcs_move_set_src_freecell(temp_move, fc);
2361
fcs_move_set_dest_stack(temp_move, ds);
2362
fcs_move_set_num_cards_in_seq(temp_move, 1);
2364
fcs_move_stack_push(moves, temp_move);
2366
fcs_move_set_type(temp_move,FCS_MOVE_TYPE_CANONIZE);
2367
fcs_move_stack_push(moves, temp_move);
2369
sfs_check_state_end()
2373
return FCS_STATE_IS_NOT_SOLVEABLE;
2033
2377
#undef state_with_locations
2035
2379
#undef new_state_with_locations