From a580dc5c89f2163580ed425e7a50ad263f1a9738 Mon Sep 17 00:00:00 2001 From: Reiner Herrmann Date: Tue, 25 Jan 2011 14:39:10 +0100 Subject: forgot to add file in last commit :> --- src/table_stacks.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/table_stacks.c 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 +#include +#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; istacks[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; +} + -- cgit v1.2.3