From 339b4a488d445fd355d8c6d848d12ba2587e9fc2 Mon Sep 17 00:00:00 2001 From: Mario Kilies Date: Fri, 14 Jan 2011 06:11:21 +0100 Subject: pnoc_sort() implemented. --- src/main.c | 3 ++- src/player_name_open_card_tuple.h | 13 ------------- src/pnoc.c | 15 +++++++++++++++ src/pnoc.h | 15 +++++++++++++++ src/ui.c | 2 +- src/ui.h | 4 ++-- 6 files changed, 35 insertions(+), 17 deletions(-) delete mode 100644 src/player_name_open_card_tuple.h create mode 100644 src/pnoc.c create mode 100644 src/pnoc.h (limited to 'src') diff --git a/src/main.c b/src/main.c index 1861185..87c7209 100644 --- a/src/main.c +++ b/src/main.c @@ -10,7 +10,7 @@ int main(int argc, char **argv) // The stack points window uses ts, too, so there is no separate data set // Example data set for current state window - const player_name_open_card_tuple pnoc[10] = { + pnoc_t pnoc[10] = { {"$you", 10}, {"1234567890", 23}, {"baz", 38}, @@ -22,6 +22,7 @@ int main(int argc, char **argv) {"hornoxe", 33}, {"1337nick", 74} }; + pnoc_sort(pnoc, 10); const uint8_t num_players = 10; const uint32_t score = 10; diff --git a/src/player_name_open_card_tuple.h b/src/player_name_open_card_tuple.h deleted file mode 100644 index b856e80..0000000 --- a/src/player_name_open_card_tuple.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef OXEN_PLAYER_NAME_OPEN_CARD_TUPLE_H -#define OXEN_PLAYER_NAME_OPEN_CARD_TUPLE_H - -#include "player.h" -#include "card.h" - -typedef struct -{ - char player_name[MAX_PLAYER_NAME_LENGTH+1]; // Player name length + 1 for string termination - card open_card; -} player_name_open_card_tuple; - -#endif // OXEN_PLAYER_NAME_OPEN_CARD_TUPLE_H diff --git a/src/pnoc.c b/src/pnoc.c new file mode 100644 index 0000000..0bfacad --- /dev/null +++ b/src/pnoc.c @@ -0,0 +1,15 @@ +#include "pnoc.h" +#include + +static int pnoc_comparator(const void *a, const void *b) +{ + pnoc_t pnoc1 = *(pnoc_t *)a; + pnoc_t pnoc2 = *(pnoc_t *)b; + + return pnoc1.open_card - pnoc2.open_card; +} + +void pnoc_sort(pnoc_t pnoc[], const uint8_t num_tuples) +{ + qsort(pnoc, num_tuples, sizeof(pnoc_t), pnoc_comparator); +} diff --git a/src/pnoc.h b/src/pnoc.h new file mode 100644 index 0000000..bfff947 --- /dev/null +++ b/src/pnoc.h @@ -0,0 +1,15 @@ +#ifndef OXEN_PNOC_H +#define OXEN_PNOC_H + +#include "player.h" +#include "card.h" + +typedef struct +{ + char player_name[MAX_PLAYER_NAME_LENGTH+1]; // Player name length + 1 for string termination + card open_card; +} pnoc_t; + +void pnoc_sort(pnoc_t pnoc[], const uint8_t num_tuples); + +#endif // OXEN_PNOC_H diff --git a/src/ui.c b/src/ui.c index 3500f93..ee27567 100644 --- a/src/ui.c +++ b/src/ui.c @@ -202,7 +202,7 @@ void ui_display_wnd_stack_points(const tablestacks ts, const bool highlight, con * @param[in] active_players The currently active player * @param[in] score The players score */ -void ui_display_wnd_current_state(const player_name_open_card_tuple pnoc[], const uint8_t num_players, const uint8_t active_player, const uint32_t score) +void ui_display_wnd_current_state(const pnoc_t pnoc[], const uint8_t num_players, const uint8_t active_player, const uint32_t score) { wattron(w_current_state, A_BOLD); mvwprintw(w_current_state, 0, 0, "Current state:"); diff --git a/src/ui.h b/src/ui.h index 2d38654..05f82ff 100644 --- a/src/ui.h +++ b/src/ui.h @@ -6,11 +6,11 @@ #include "cardstack.h" #include "tablestacks.h" #include "hand.h" -#include "player_name_open_card_tuple.h" +#include "pnoc.h" void ui_display_wnd_table_cards(const tablestacks ts, const bool highlight, const uint8_t highlighted_stack); void ui_display_wnd_stack_points(const tablestacks ts, const bool highlight, const uint8_t highlighted_points); -void ui_display_wnd_current_state(const player_name_open_card_tuple pnoc[], const uint8_t num_players, const uint8_t active_player, const uint32_t score); +void ui_display_wnd_current_state(const pnoc_t pnoc[], const uint8_t num_players, const uint8_t active_player, const uint32_t score); void ui_display_wnd_hand_cards(const hand h, const bool highlight, const uint8_t highlighted_card); uint8_t ui_choose_card(hand h); uint8_t ui_choose_stack(const tablestacks ts); -- cgit v1.2.3