#include <iostream>
#include <cstdio>
#include "Card.h"

using std::cout;
using std::endl;


/* make_card
 *
 * Allocate space for AND initialize the values for a single card
 */

Card::Card(int sui, int val)
{
  suit = sui;
  value = val;
}

int Card::get_suit() const
{
  return suit;
}

int Card::get_value() const
{
  return value;
}

/* compare
 *
 * Compare two cards.  The way we compare cards is to first look at the 
 * value.  If the values are different, then the card with the higher value
 * is higher.  If the values are the same, then we check the suit.  The vard
 * with a suit with a higher value (0-3) is higher.
 *
 * The compare result is -1, 0, or 1.  If c1 < c2, then return -1.  If
 * c1 == c2, then return 0.  If c1 > c2, then return 1.
 */

int Card::compare(const Card& c) const
{
  if (value == c.get_value())
    {
      if (suit > c.get_suit())
	return 1;
      else if (suit < c.get_suit())
	return -1;
      else 
	return 0;
    }  
  else if (c.get_value() > value)
    return -1;
  else 
    return 1;    
}

void Card::print_card()const
{  
  char suitchars[] = "CDHS";
  char valuechars[] = "WA23456789TJQK";
  
  if ((suit < 0) || (suit > 3))
    /*printf("Invalid suit: %d\n",suit);*/
    cout << "Invalid suit: " << get_suit() <<endl;
  else if ((value < 0) || (value > 13))
    /*printf("Invalid value: %d\n",value);*/
    cout << "Invalid value: " << get_value() << endl;
  else
    cout << suitchars[get_suit()] << " "<< valuechars[get_value()] << " " ;
}
