Skip to content

Instantly share code, notes, and snippets.

@gnuvince
Created August 3, 2010 04:03
Show Gist options
  • Save gnuvince/505810 to your computer and use it in GitHub Desktop.
Save gnuvince/505810 to your computer and use it in GitHub Desktop.
/*
* Compare two cards and return:
* < 0 if a is smaller than b
* 0 if a is equal to b
* > 0 if a is greater than b
*/
int CardCompare(const Card* a, const Card* b) {
if (a == NULL)
return 1;
if (b == NULL)
return -1;
return a->rank - b->rank;
}
/*
* Returns whether a card has valid values for its
* rank and suit.
*/
int CardIsValid(const Card* c) {
return c != NULL &&
(c->rank >= Deuce && c->rank <= Ace &&
c->suit >= Club && c->suit <= Spade);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment