From 81bbb4b5fce757d0be8166cc44d2a15a2d9f247b Mon Sep 17 00:00:00 2001 From: Mario Kilies Date: Tue, 4 Jan 2011 03:41:55 +0100 Subject: cardpoints(): Rewritten code that is more readable. Changed return values from int to uint32_t. Added display initialization to main(). --- src/common.c | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) (limited to 'src/common.c') diff --git a/src/common.c b/src/common.c index d676f12..89841c4 100644 --- a/src/common.c +++ b/src/common.c @@ -1,31 +1,25 @@ #include "common.h" +#include -int cardpoints(card c) +uint32_t cardpoints(const card c) { - int rem = c % 10; - int div = c / 10; - - if(rem == div) - return (rem==5)?7:5; - - if(rem == 5) - return 2; - else if(rem == 0) - return 3; - - return 1; + assert(c > 0 && c <= 105); + if (55 == c) return 7; // Card 55 is worth of 7 points + if (c % 11 == 0) return 5; // Cards that are multiples of 11 are worth 5 points + if (c % 10 == 0) return 3; // ... 10 are worth 3 points + if (c % 5 == 0) return 2; // ... 5 are worth 2 points + return 1; // All other cards are worth 1 point } -int stackpoints(cardstack s) +uint32_t stackpoints(const cardstack s) { - int points = 0; - for(int i=0; i 0) - points += cardpoints(cur); + if(s[i] > 0) + points += cardpoints(s[i]); } return points; } - -- cgit v1.2.3