#include <fstream.h>
#include <stdlib.h>
#include <time.h>

struct card
{
    int colour;
    int number;
};
struct cards
{
    struct card deck[150];
};
class deck
{
    private:
        int no_of_cards;
        struct card play_deck[150];
    public:
        deck(char[20]);
        void load_cards(char[20]);
        void shuffle_cards(void);
        struct card pickup_card(void);
        void return_card(struct card);
        struct cards get_deck(void);
        int get_no_of_cards(void);
};
deck::deck(char name[20])
{
    no_of_cards = 150;
    deck::load_cards(name);
    deck::shuffle_cards();
}
void deck::load_cards(char name[20])
{
    int length=0, i=0;
    ifstream cards_in(name, ios::in);
    cards_in>>length;
    for(i=0;i<length;i++)
    {
        cards_in>>play_deck[i].colour>>play_deck[i].number;
    }
    cards_in.close();
    no_of_cards=length;
}
void deck::shuffle_cards(void)
{
    srand(time(0));
    bool taken[150];
    struct card temp[150];
    int ran = 0;
    bool take = false;

    for(int i=0;i<no_of_cards;i++)
    {
        temp[i].colour=play_deck[i].colour;
        temp[i].number=play_deck[i].number;
        taken[i]=false;
    }
    for(int i=0;i<no_of_cards;i++)
    {
        do
        {
            ran = rand()%no_of_cards;
            if(!taken[ran])
            {
                play_deck[i].colour=temp[ran].colour;
                play_deck[i].number=temp[ran].number;
		taken[ran]=true;
		take=false;
            }
	    else
	       take=true;
        }while(take);
    }
}
struct card deck::pickup_card(void)
{
    no_of_cards--;
    for(int i=0;i<no_of_cards;i++)
    {
        play_deck[i].colour=play_deck[i+1].colour;
        play_deck[i].number=play_deck[i+1].number;
    }
    return play_deck[0];
}
void deck::return_card(struct card temp)
{
    play_deck[no_of_cards].colour = temp.colour;
    play_deck[no_of_cards].number = temp.number;
    no_of_cards++;
}
struct cards deck::get_deck(void)
{
    struct cards temp;
    for(int i=0;i<no_of_cards;i++)
    {
        temp.deck[i].colour=play_deck[i].colour;
        temp.deck[i].number=play_deck[i].number;
    }
    return temp;
}
int deck::get_no_of_cards(void)
{
    return no_of_cards;
}

class hand
{
    private:
        struct card play_hand[30];
        int hand_size;
    public:
        hand();
        void add_card(struct card);
        struct card play_card(int);
        struct cards get_hand(void);
        void load_hand(struct cards);
        void sort_hand();
        int get_hand_size();
};
hand::hand()
{
    hand_size=0;

}
void hand::add_card(struct card add)
{
    hand_size++;
    play_hand[hand_size-1].colour = add.colour;
    play_hand[hand_size-1].number = add.number;
}
struct card hand::play_card(int card_no)
{
    hand_size--;
    struct card temp = play_hand[card_no];
    for(int i=card_no;i<hand_size;i++)
    {
        play_hand[i].colour=play_hand[i+1].colour;
        play_hand[i].number=play_hand[i+1].number;
    }
    return temp;
}
struct cards hand::get_hand()
{
    struct cards temp;
    for(int i=0;i<hand_size;i++)
    {
        temp.deck[i].colour = play_hand[i].colour;
        temp.deck[i].number = play_hand[i].number;
    }
    return temp;
}
int hand::get_hand_size()
{
    return hand_size;
}
/*class screen_card
{
    private:
        struct card play_card

*/

