summaryrefslogtreecommitdiff
path: root/src/card_stack.c
diff options
context:
space:
mode:
authorReiner Herrmann <reiner@reiner-h.de>2011-01-25 16:12:37 +0100
committerReiner Herrmann <reiner@reiner-h.de>2011-01-25 16:12:37 +0100
commita659f7d045f9107dbb41d7bbf0694cc7a5c7a589 (patch)
tree9fb891d7e3874811a090a8a846856a04622b80a9 /src/card_stack.c
parentc7181ee943069bde7f5d468d11ee63c3a535980d (diff)
parent80eead4f5ab998a0e6b678f8c1c0fcd969d6b07c (diff)
Merge branch 'master' of ssh://icarus-git/~git/oxen
Diffstat (limited to 'src/card_stack.c')
-rw-r--r--src/card_stack.c40
1 files changed, 35 insertions, 5 deletions
diff --git a/src/card_stack.c b/src/card_stack.c
index 13b14dd..f3bd217 100644
--- a/src/card_stack.c
+++ b/src/card_stack.c
@@ -2,6 +2,10 @@
#include <assert.h>
#include <stdlib.h>
+/**
+ * Calculates the points of a card stack. This will be the sum of the points of all cards contained in the card stack.
+ * @param[in] cs The card stack fir which the points will be calculated
+*/
uint32_t card_stack_get_points(const card_stack_t *cs)
{
assert(cs != NULL);
@@ -17,11 +21,15 @@ uint32_t card_stack_get_points(const card_stack_t *cs)
return points;
}
-const card card_stack_upper_card(const card_stack_t *cs)
+/**
+ * Determines the uppermost card on a card stack. The card will not be removed from the stack.
+ * @param[in] cs The card stack from which the uppermost card will be retrieved
+*/
+const card card_stack_top(const card_stack_t *cs)
{
assert(cs != NULL);
- for(int i=0; i<MAX_CARD_STACK_SIZE; i++)
+ for(int i = 0; i < MAX_CARD_STACK_SIZE; i++)
{
card cur = cs->cards[MAX_CARD_STACK_SIZE-1-i];
if(cur != 0)
@@ -31,13 +39,35 @@ const card card_stack_upper_card(const card_stack_t *cs)
return 0;
}
-void card_stack_clear(card_stack_t *cs, const card new_card)
+/**
+ * Places a card on top of a card stack.
+ * @param[in] cs The card stack to place the card on
+ * @param[in] c The card to place
+*/
+void card_stack_push(card_stack_t *cs, const card c)
{
assert(cs != NULL);
- for(int i=0; i<MAX_CARD_STACK_SIZE; i++)
+ for(int i = 0; i < MAX_CARD_STACK_SIZE; i++)
+ {
+ if(cs->cards[i] != 0)
+ continue;
+ cs->cards[i] = c;
+ break;
+ }
+}
+
+/**
+ * Replaces a card stack with a single card. All cards within the card stack will be removed adn the first card will be set to a given card.
+ * @param[in] cs The card stack to replace
+ * @param[in] new_card The new first card
+*/
+void card_stack_replace(card_stack_t *cs, const card new_card)
+{
+ assert(cs != NULL);
+
+ for(int i = 0; i < MAX_CARD_STACK_SIZE; i++)
cs->cards[i] = 0;
cs->cards[0] = new_card;
}
-