/* * This function performs a given move on a state */ void fc_solve_apply_move( fcs_state_extra_info_t * state_val, fcs_internal_move_t move, int freecells_num, int stacks_num, int decks_num GCC_UNUSED ) { fcs_card_t card; fcs_cards_column_t col; fcs_state_t * state_key = state_val->key; switch(fcs_int_move_get_type(move)) { case FCS_MOVE_TYPE_STACK_TO_STACK: { fcs_cards_column_t dest_col; int i; col = fcs_state_get_col(*state_key, fcs_int_move_get_src_stack(move)); dest_col = fcs_state_get_col(*state_key, fcs_int_move_get_dest_stack(move)); for(i=0 ; i<fcs_int_move_get_num_cards_in_seq(move) ; i++) { fcs_col_push_col_card( dest_col, col, fcs_col_len(col) - fcs_int_move_get_num_cards_in_seq(move)+i ); } for(i=0 ; i<fcs_int_move_get_num_cards_in_seq(move) ; i++) { fcs_col_pop_top(col); } } break; case FCS_MOVE_TYPE_FREECELL_TO_STACK: { col = fcs_state_get_col(*state_key, fcs_int_move_get_dest_stack(move)); fcs_col_push_card(col, fcs_freecell_card(*state_key, fcs_int_move_get_src_freecell(move))); fcs_empty_freecell(*state_key, fcs_int_move_get_src_freecell(move)); } break; case FCS_MOVE_TYPE_FREECELL_TO_FREECELL: { card = fcs_freecell_card(*state_key, fcs_int_move_get_src_freecell(move)); fcs_put_card_in_freecell(*state_key, fcs_int_move_get_dest_freecell(move), card); fcs_empty_freecell(*state_key, fcs_int_move_get_src_freecell(move)); } break; case FCS_MOVE_TYPE_STACK_TO_FREECELL: { col = fcs_state_get_col(*state_key, fcs_int_move_get_src_stack(move)); fcs_col_pop_card(col, card); fcs_put_card_in_freecell(*state_key, fcs_int_move_get_dest_freecell(move), card); } break; case FCS_MOVE_TYPE_STACK_TO_FOUNDATION: { col = fcs_state_get_col( *state_key, fcs_int_move_get_src_stack(move) ); fcs_col_pop_top(col); fcs_increment_foundation(*state_key, fcs_int_move_get_foundation(move)); } break; case FCS_MOVE_TYPE_FREECELL_TO_FOUNDATION: { fcs_empty_freecell(*state_key, fcs_int_move_get_src_freecell(move)); fcs_increment_foundation(*state_key, fcs_int_move_get_foundation(move)); } break; case FCS_MOVE_TYPE_SEQ_TO_FOUNDATION: { int i; col = fcs_state_get_col(*state_key, fcs_int_move_get_src_stack(move)); for (i=0 ; i<13 ; i++) { fcs_col_pop_top(col); fcs_increment_foundation(*state_key, fcs_int_move_get_foundation(move)); } } break; #ifndef FCS_WITHOUT_CARD_FLIPPING case FCS_MOVE_TYPE_FLIP_CARD: { col = fcs_state_get_col(*state_key, fcs_int_move_get_src_stack(move)); fcs_col_flip_card(col, fcs_col_len(col)-1); } break; #endif case FCS_MOVE_TYPE_CANONIZE: { fc_solve_canonize_state( state_val, freecells_num, stacks_num ); } break; } }
/* * This function performs a given move on a state */ void fc_solve_apply_move(fcs_state *const ptr_state_key, fcs_state_locs_struct *const locs, const fcs_internal_move move FREECELLS_AND_STACKS_ARGS()) { fcs_cards_column col; const stack_i src = fcs_int_move_get_src(move); const stack_i dest = fcs_int_move_get_dest(move); #define state_key (ptr_state_key) switch (fcs_int_move_get_type(move)) { case FCS_MOVE_TYPE_STACK_TO_STACK: { fcs_col_transfer_cards(fcs_state_get_col(*state_key, dest), fcs_state_get_col(*state_key, src), fcs_int_move_get_num_cards_in_seq(move)); } break; #if MAX_NUM_FREECELLS > 0 case FCS_MOVE_TYPE_FREECELL_TO_STACK: fcs_state_push(state_key, dest, fcs_freecell_card(*state_key, src)); fcs_empty_freecell(*state_key, src); break; case FCS_MOVE_TYPE_FREECELL_TO_FREECELL: { fcs_card card = fcs_freecell_card(*state_key, src); fcs_put_card_in_freecell(*state_key, dest, card); fcs_empty_freecell(*state_key, src); } break; case FCS_MOVE_TYPE_STACK_TO_FREECELL: { col = fcs_state_get_col(*state_key, src); fcs_card card; fcs_col_pop_card(col, card); fcs_put_card_in_freecell(*state_key, dest, card); } break; #endif case FCS_MOVE_TYPE_STACK_TO_FOUNDATION: col = fcs_state_get_col(*state_key, src); fcs_col_pop_top(col); fcs_increment_foundation(*state_key, dest); break; #if MAX_NUM_FREECELLS > 0 case FCS_MOVE_TYPE_FREECELL_TO_FOUNDATION: fcs_empty_freecell(*state_key, src); fcs_increment_foundation(*state_key, dest); break; #endif #ifndef FCS_FREECELL_ONLY case FCS_MOVE_TYPE_SEQ_TO_FOUNDATION: col = fcs_state_get_col(*state_key, src); for (int i = 0; i < 13; i++) { fcs_col_pop_top(col); fcs_increment_foundation(*state_key, dest); } break; #endif case FCS_MOVE_TYPE_CANONIZE: if (locs) { fc_solve_canonize_state_with_locs(state_key, locs PASS_FREECELLS(freecells_num) PASS_STACKS(stacks_num)); } else { fc_solve_canonize_state(state_key PASS_FREECELLS(freecells_num) PASS_STACKS(stacks_num)); } break; } #undef state_key }