From 248e66cdb112b4881f7a56c6508f3ef61ea7e3cb Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Sun, 24 Mar 2019 00:08:11 -0400 Subject: Factor out suit, color and rank functions I plan to implement other solitaire games. --- stack.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'stack.h') diff --git a/stack.h b/stack.h index e85c43f..a635e8c 100644 --- a/stack.h +++ b/stack.h @@ -19,6 +19,30 @@ #include #include +#include + +#include "cards.h" + +static Sint8 cardSuit(Sint8 card) { + card = abs(card); + if (card > Cards_Spade) { + return Cards_Spade; + } else if (card > Cards_Heart) { + return Cards_Heart; + } else if (card > Cards_Diamond) { + return Cards_Diamond; + } else { + return Cards_Club; + } +} + +static Sint8 cardColor(Sint8 card) { + return cardSuit(card) == Cards_Diamond || cardSuit(card) == Cards_Heart; +} + +static Sint8 cardRank(Sint8 card) { + return abs(card) - cardSuit(card); +} struct Stack { Uint8 len; -- cgit 1.4.1