]> git.cworth.org Git - kub/commitdiff
Implement card_group_is_run with one loop instead of two.
authorCarl Worth <cworth@cworth.org>
Mon, 29 Jan 2007 15:19:33 +0000 (07:19 -0800)
committerCarl Worth <cworth@cworth.org>
Mon, 29 Jan 2007 15:19:33 +0000 (07:19 -0800)
It's simpler to just implement a single check for color in the same
loop that's examining the color of every card. We don't need to
check every pair of cards for matching color as we were in the old
loop.

kub.c

diff --git a/kub.c b/kub.c
index 299eb07667a8892489a34df9c7d226780d442131..aec86bee557348ae318c7614bf8a7fa6dc6a9889 100644 (file)
--- a/kub.c
+++ b/kub.c
@@ -84,19 +84,20 @@ static int card_group_is_run(card_group_t *card_group)
 {
     int i;
     int lowest = 14, highest = 0;
+    color_t run_color;
+
     if (card_group->num_cards > 13 || card_group->num_cards < 3)
     {
        return 0;
     }
-    for (i = 0; i < card_group->num_cards - 1; ++i)
+
+    run_color = card_group->cards[i].color;
+
+    for (i = 0; i < card_group->num_cards; i++)
     {
-       if (card_group->cards[i].color != card_group->cards[i + 1].color)
-       {
+       if (card_group->cards[i].color != run_color)
            return 0;
-       }
-    }
-    for (i = 0; i < card_group->num_cards; ++i)
-    {
+
        if (card_group->cards[i].number > highest)
        {
            highest = card_group->cards[i].number;