#include <stdio.h>

#include "cards.h"
#include "poker.h"

struct card hand[5];

void print(struct card *c)
{
	switch(c->suit) {
	case DIAMONDS:
		printf("D");
		break;
	case CLUBS:
		printf("C");
		break;
	case HEARTS:
		printf("H");
		break;
	case SPADES:
		printf("S");
		break;
	}
	printf("%c",c->name);
}

void print_cards(void)
{
	int i;
	for(i=0;i<5;i++) {
		printf("%i:",i+1);
		print(&hand[i]);
		printf(" ");
	}
	printf("\n");
}

void get_card_choices(int x[])
{
	int i=0;
	char buf[20];
	printf("Enter Choices: ");
	fgets(buf,20,stdin);
	sscanf(buf,"%i %i %i %i %i",&x[0],&x[1],&x[2],&x[3],&x[4]);
}

int get_command(void)
{
	char x;
	char buf[20];
	print_cards();
	printf("> ");
	fgets(buf,20,stdin);
	sscanf(buf,"%c",&x);
	if(x == 'q') {
		return 0;
	} else {
		return x;
	}
}

void swap_cards(int x[])
{
	int i=-1;
	while(x[++i]) {
		deal_card(&hand[x[i]]);
		printf("%i:",x[i]);
		print(&hand[x[i]]);
		printf(" ");
	}
	printf("\n");
}

int main(void)
{
	char c;
	int swap[5], i;
	memset(swap,0,sizeof(int)*5);
	init_game();
	deal(hand);
	while(c = get_command()) {
		switch(tolower(c)) {
		case 's':
			get_card_choices(swap);
			swap_cards(swap);
			break;
		default:
			printf("not good.\n");
			break;
		}
	}
	end_game();
	return 0;
}
