diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/table_stacks.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/table_stacks.c b/src/table_stacks.c new file mode 100644 index 0000000..9a32977 --- /dev/null +++ b/src/table_stacks.c @@ -0,0 +1,33 @@ +#include <stdlib.h> +#include <assert.h> +#include "table_stacks.h" +#include "card_stack.h" +#include "card.h" +#include "game.h" + +const uint8_t get_stack_idx_for_card(const table_stacks_t* stack_list, const card c) +{ + assert(stack_list != NULL); + + uint8_t idx = NUM_TABLE_STACKS; + uint8_t old_diff = MAX_CARD; + + for(int i=0; i<NUM_TABLE_STACKS; i++) + { + card stackcard = card_stack_upper_card(&stack_list->stacks[i]); + uint8_t new_diff = c - stackcard; + assert(new_diff != 0); + + if(new_diff < 0) // open card smaller than card on current stack + continue; + + if(new_diff < old_diff) + { + old_diff = new_diff; + idx = i; + } + } + + return idx; +} + |
