summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorReiner Herrmann <reiner@reiner-h.de>2011-01-25 14:39:10 +0100
committerReiner Herrmann <reiner@reiner-h.de>2011-01-25 14:39:10 +0100
commita580dc5c89f2163580ed425e7a50ad263f1a9738 (patch)
treeb67fa84db1d088909a611a98be27923836a46ae5 /src
parent3f9465630fe3eab4d42568809786e2a070ac536e (diff)
forgot to add file in last commit :>
Diffstat (limited to 'src')
-rw-r--r--src/table_stacks.c33
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;
+}
+