/*
 * File: acm98.h
 * Author: Chris Alfeld (calfeld@cs.utah.edu)
 *
 * Description: This file defines global data structures used in
 * the ACM take home problem.  These data structures are to be
 * used *read-only* by the contestent written code.  The file acm98.cpp
 * implements the routines that maintain and update these datastructures,
 * include main().
  */

/*
 * For compatability - Remove if it gives you problems.  We'll add it again
 * if necessary for us to compile it.
 */
#define NULL 0

/*
 * The various types used.  See below for descriptions.
 */
typedef struct _acm_scores acm_scores;
typedef struct _acm_play   acm_play;
typedef struct _acm_card   acm_card;
typedef struct _acm_gameinfo acm_gameinfo;

/*
 * Declarations of global variables that are defined in acm98.cpp (GAME)
 * or the contestent code (PLAY_NAME).
 */
extern acm_gameinfo GAME;
extern const char PLAYER_NAME[];  

/*
 * acm_card
 *
 * This structure describes a single card.  It is used in
 * other data structures and is the return value of PlayCard,
 * and TakeCard.
 */
struct _acm_card {
  /* The suit of the card. 's' = spades, 'h' = hearts,
   * 'd' = diamonds, 'c' = clubs.
   */
  char suit;

  /* The face of the card. 'a' = ace, 'k' = king, 'q' = queen,
   * 'j' = jack, 't' = ten, '9'-'2' = themselves.
   */
  char face;
};

/*
 * acm_play
 *
 * This structure describes a round or partial round of plays or
 * takes.  It gives the cards played/taken by each side and which
 * side lead.  In partial rounds some cards will be not played/taken,
 * indicated by the suit and face of the card == '\0'.
 */
struct _acm_play {
  /* Who lead the round.  'n','e','s' or 'w'. */
  char leader;

  /* A pointer to the card that lead the round */
  acm_card *lead;
  
  /* The card played by each player. */
  acm_card north,east,south,west;
};

/*
 * acm_scores
 *
 * A simple structure that given the current scores of the four players.
 */
struct _acm_scores {
  /* The score of each player */
  int north,east,south,west;
};

/*
 * acm_gameinfo
 *
 * This is the global data structure that is maintained by acm98.cpp
 * and should be read by contestant code.  It is accessible via the
 * global variables GAME.
 */
struct _acm_gameinfo {
  /* The cards played during the last trick, and who lead. */
  acm_play last_trick;

  /* The cards taken during the current trick, and who lead.
   * Note: 1 or more cards may be blank indicating that they
   * will be played by or after you.  Ex: if you are the leader
   * all four cards will be blank
   */
  acm_play cur_trick;

  /* The cards taken is the last round of takes. */
  acm_play last_take;

  /* The cards taken in the current trick.
   * Note: 1 or more cards may be blank.  See comment on cur_trick.
   */
  acm_play cur_take;

  /* The size and cards of the pool.  Once all cards have been
   * taken the size will be 0 and all cards will be blank.
   * The cards array will be packed, i.e. as cards are removed
   * the other cards are shifted to the front of the array to fill
   * in the holes.
   */
  int pool_size;
  acm_card pool[12];

  /* The size and cards of your hand.  As in the pool, the cards
   * array is packed.
   */
  int hand_size;
  acm_card hand[13];

  /* The current trick number.  Take numbers are indicated by
   * -2, -1, and 0, indicating the three rounds of take.
   */
  int trick_number;
     
  /* The scores of the four players
   * This is updated after each round is played (just before PlayCard).
   */
  acm_scores scores;

  /* Who you are.  This is either 'n','s','e', or 'w'*/
  char player;
};


/*
 * These functions are called by acm98.cpp and should be implemented by the
 * contestant.  See shell.cpp .
 */
void NewGame();
void NewRound();
acm_card TakeCard();
acm_card PlayCard();
void EndTakes();
void EndRound();


/*
 * These are helped functions that can be called by the contestant code.
 *
 * card_cmp(char lead_suit,acm_card A,acm_card B)
 * Compares two cards and returns -1 if A<B, 0 if A==B, and 1 if A>B
 */
int card_cmp(char lead_suit,acm_card A,acm_card B);



