/*
 *	File:			cards.h
 *	Purpose:		Declaration of functions and macros to manipulate cards.
 *	Created:		17 Nov 88
 *	Last Modified:	29 May 89
 *	Comments:
 *
 *		NUM_CARD_DENOMS allows us to use shorter decks, like 9-A for euchre.
 *		Simply set NUM_CARD_DENOMS to 6 and change the ranks[] in cards.c.
 *
 *	History:
 *		17 Nov 88	Created.
 *		29 May 89	Added NUM_CARD_DENOMS.
 */

# ifndef cards_defined
# define cards_defined

# define	MAXCARDS			52		/* number of cards in the deck */
# define	NUM_CARD_DENOMS 	13		/* # card denominations (ranks) */

# define	card(x)         ((x) % NUM_CARD_DENOMS)
# define	suit(x)         ((x) / NUM_CARD_DENOMS)
# define	rank(x)         (ranks[card(x)])
# define	color(x)        (suits[suit(x)])

/*
 *	Use new_deck when starting a new game. Use pick to draw cards from the
 *	deck for each card to be dealt. Use throw to put a card in the discard
 *	pile. crandom is provided as a convenience.
 *
 *	If pick finds no cards left in the deck, it will shuffle the discard
 *	pile and make that the new deck.
 *
 *	Both the draw pile and the discard pile are exported for display
 *	purposes only (i.e. some game may want to display the discard pile).
 *	Don't change their contents.
 */

/*
 *	Structure of a pile of cards.
 */

typedef struct {
	int		next_card;				/* index of next card to be drawn */
	int		last_card;				/* index of last card of pile */
	int		pile_card[MAXCARDS];	/* the cards in the pile */
	} PILE;

extern PILE draw_pile, discard_pile;

extern char ranks[];
extern char suits[];


/*
 *	new_deck - shuffles a full deck and makes it available in draw_pile
 *			   where cards can be fetched by pick().  Also empties the
 *			   discard_pile.
 */

void new_deck(void);

/*
 *	pick - returns top card from draw_pile.  If draw_pile is empty, moves
 *		   discard_pile to draw_pile, shuffles, and returns top card.
 */

int pick(void);

/*
 *	throw - puts card on top of discard_pile.
 */

void throw(int acard);

/*
 *	crandom - returns a random integer from 0 to limit-1.
 */

int crandom(int limit);

# endif /* cards_defined */
