summaryrefslogtreecommitdiff
path: root/src/hand.c
blob: 359ed08a0a99481e3a7a0d935e17a6f17939b511 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "hand.h"
#include <stdlib.h>
#include <assert.h>
#include "card.h"

static int hand_comparator(const void *a, const void *b)
{
	card c1 = *(card *)a;
	card c2 = *(card *)b;
	
	return c1 - c2;
}

void hand_sort(hand_t *h)
{
	assert(h != NULL);

	qsort(h->cards, MAX_HAND_CARDS, sizeof(card), hand_comparator);
}

void hand_remove_card(hand_t *h, const uint8_t card_index)
{
	assert(h != NULL);

	h->cards[card_index] = 0;
}

const uint8_t hand_count_cards(const hand_t* h)
{
	uint8_t count = 0;
	for(int i=0; i<MAX_HAND_CARDS; i++)
		if(h->cards[i] != 0)
			count++;

	return count;
}