From 52f95177eb8050f073a3d65413feb16cfce93baa Mon Sep 17 00:00:00 2001 From: Mario Kilies Date: Tue, 25 Jan 2011 13:14:17 +0100 Subject: Removed awkward pnoc_t and refactored its contents to the new player_list_entry_t. --- src/player.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'src/player.c') diff --git a/src/player.c b/src/player.c index 3e03729..b264922 100644 --- a/src/player.c +++ b/src/player.c @@ -1,9 +1,12 @@ #include "player.h" #include +#include -pnoc_t* get_pnoc_from_playerid(player_list* pl, const uint8_t pid) +player_list_entry_t *get_player_list_entry_by_player_id(player_list_t *pl, const player_id_t pid) { - for(int i=0; icount; i++) + assert(pl != NULL); + + for(int i = 0; i < pl->count; i++) { if(pl->players[i].player_id != pid) continue; @@ -13,3 +16,17 @@ pnoc_t* get_pnoc_from_playerid(player_list* pl, const uint8_t pid) return NULL; } +static int ple_comparator(const void *a, const void *b) +{ + player_list_entry_t ple1 = *(player_list_entry_t *)a; + player_list_entry_t ple2 = *(player_list_entry_t *)b; + + return ple1.open_card - ple2.open_card; +} + +void player_list_sort_by_open_card(player_list_t *pl, const uint8_t num_entries) +{ + assert(pl != NULL); + + qsort(pl, num_entries, sizeof(player_list_entry_t), ple_comparator); +} -- cgit v1.2.3