summary refs log tree commit diff
path: root/stack.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--stack.h20
1 files changed, 11 insertions, 9 deletions
diff --git a/stack.h b/stack.h
index 4daf6ba..6267f23 100644
--- a/stack.h
+++ b/stack.h
@@ -23,7 +23,9 @@
 
 #include "cards.h"
 
-static Sint8 cardSuit(Sint8 card) {
+typedef Sint8 Card;
+
+static int cardSuit(Card card) {
 	card = abs(card);
 	if (card > Cards_Spade) {
 		return Cards_Spade;
@@ -36,34 +38,34 @@ static Sint8 cardSuit(Sint8 card) {
 	}
 }
 
-static Sint8 cardColor(Sint8 card) {
+static int cardColor(Card card) {
 	return cardSuit(card) == Cards_Diamond || cardSuit(card) == Cards_Heart;
 }
 
-static Sint8 cardRank(Sint8 card) {
+static int cardRank(Card card) {
 	return abs(card) - cardSuit(card);
 }
 
 struct Stack {
 	Uint8 len;
-	Sint8 cards[52];
+	Card cards[52];
 };
 
 static inline void stackClear(struct Stack *stack) {
 	stack->len = 0;
 }
 
-static inline void stackPush(struct Stack *stack, Sint8 card) {
+static inline void stackPush(struct Stack *stack, Card card) {
 	assert(stack->len < 52);
 	stack->cards[stack->len++] = card;
 }
 
-static inline Sint8 stackPop(struct Stack *stack) {
+static inline Card stackPop(struct Stack *stack) {
 	if (!stack->len) return 0;
 	return stack->cards[--stack->len];
 }
 
-static inline Sint8 stackTop(struct Stack *stack) {
+static inline Card stackTop(struct Stack *stack) {
 	if (!stack->len) return 0;
 	return stack->cards[stack->len - 1];
 }
@@ -85,7 +87,7 @@ static inline void stackMoveTo(struct Stack *dst, struct Stack *src, Uint8 n) {
 
 static inline void stackDeck(struct Stack *stack) {
 	stackClear(stack);
-	for (Sint8 i = 1; i <= 52; ++i) {
+	for (Card i = 1; i <= 52; ++i) {
 		stackPush(stack, -i);
 	}
 }
@@ -100,7 +102,7 @@ static inline int randUniform(int bound) {
 static inline void stackShuffle(struct Stack *stack) {
 	for (Uint8 i = stack->len - 1; i > 0; --i) {
 		Uint8 j = randUniform(i + 1);
-		Sint8 x = stack->cards[i];
+		Card x = stack->cards[i];
 		stack->cards[i] = stack->cards[j];
 		stack->cards[j] = x;
 	}