Skip to content
This repository was archived by the owner on May 2, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,33 @@ on:
- '**/windows.yml'

jobs:
msvc:
runs-on: windows-latest
steps:
- uses: actions/checkout@v6

- name: Set up MSVC environment
uses: ilammy/msvc-dev-cmd@v1
with:
arch: x64

- name: Install Meson and Ninja
run: pip install meson ninja

- name: Meson setup
env:
PKG_CONFIG_PATH: ${{ env.VCPKG_INSTALLATION_ROOT }}\installed\x64-windows\lib\pkgconfig
run: |
meson setup _build -Db_sanitize=none

- name: Build
run: meson compile -C _build

- name: Test
run: meson test --no-stdsplit -v -C _build
MSYS2:
runs-on: windows-latest
needs: msvc
steps:
- uses: actions/checkout@v6
- uses: msys2/setup-msys2@v2
Expand Down
4 changes: 2 additions & 2 deletions deckhandler.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ static void DH_init_deck(DH_Deck *deck) {
deck->top_card = 0;

int card = 0;
int suit = 0;
int face = DH_CARD_ACE;
int8_t suit = 0;
int8_t face = DH_CARD_ACE;

while (suit < DH_SUIT_MAX) {
deck->card[card].face_val = face++;
Expand Down
40 changes: 25 additions & 15 deletions deckhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ extern "C" {
#include <stdbool.h>
#include <stdint.h>

#if defined(_WIN32) || defined(__CYGWIN__)
# ifdef DECKHANDLER_BUILD
# define DH_API __declspec(dllexport)
# else
# define DH_API __declspec(dllimport)
# endif
#else
# define DH_API
#endif

/// Number of face values in a standard card deck (Ace to King).
#define NUM_OF_FACES 13

Expand Down Expand Up @@ -64,12 +74,12 @@ typedef struct {
int8_t suit; ///< Suit of the card (see enum)
} DH_Card;

extern const DH_Card DH_card_back;
extern const DH_Card DH_card_null;
extern DH_API const DH_Card DH_card_back;
extern DH_API const DH_Card DH_card_null;

bool DH_is_card_back(DH_Card a);
DH_API bool DH_is_card_back(DH_Card a);

bool DH_is_card_null(DH_Card a);
DH_API bool DH_is_card_null(DH_Card a);

/**
* @DH_Deck
Expand All @@ -86,14 +96,14 @@ typedef struct {
* @param initstate Initialization state value.
* @param initseq Initialization sequence value.
*/
void DH_pcg_srand(uint64_t initstate, uint64_t initseq);
DH_API void DH_pcg_srand(uint64_t initstate, uint64_t initseq);

/**
* @brief Automatically seed the PCG random number generator with internal defaults.
*
* Uses `time(NULL)` and pointer values for entropy.
*/
void DH_pcg_srand_auto(void);
DH_API void DH_pcg_srand_auto(void);

/**
* @brief Create and initialize a new deck of cards.
Expand All @@ -103,7 +113,7 @@ void DH_pcg_srand_auto(void);
*
* @return A fully initialized deck of cards.
*/
DH_Deck DH_get_new_deck(void);
DH_API DH_Deck DH_get_new_deck(void);

/**
* @brief Deal the top card from the deck.
Expand All @@ -115,14 +125,14 @@ DH_Deck DH_get_new_deck(void);
* @param deck Pointer to the deck from which to deal a card.
* @return The card at the current top position of the deck.
*/
DH_Card DH_deal_top_card(DH_Deck *deck);
DH_API DH_Card DH_deal_top_card(DH_Deck *deck);

/**
* @brief Shuffle a deck of cards using the PCG random number generator.
*
* @param deck_dh Pointer to the deck to shuffle.
*/
void DH_shuffle_deck(DH_Deck *deck_dh);
DH_API void DH_shuffle_deck(DH_Deck *deck_dh);

/**
* @brief Cuts the deck at the specified index, simulating a real-life card cut.
Expand All @@ -140,23 +150,23 @@ void DH_shuffle_deck(DH_Deck *deck_dh);
*
* @see DH_shuffle_deck
*/
void DH_cut_deck(DH_Deck *deck, int cut_point);
DH_API void DH_cut_deck(DH_Deck *deck, int cut_point);

/**
* @brief Get the string name of a card's face value (e.g., "Ace", "10", "King").
*
* @param card The card to query.
* @return Pointer to a constant string.
*/
const char *DH_get_card_face(DH_Card card);
DH_API const char *DH_get_card_face(DH_Card card);

/**
* @brief Get the string name of a card's suit (e.g., "Hearts", "Spades").
*
* @param card The card to query.
* @return Pointer to a constant string.
*/
const char *DH_get_card_suit(DH_Card card);
DH_API const char *DH_get_card_suit(DH_Card card);

/**
* @brief Get the Unicode symbol representing the card's suit.
Expand All @@ -166,17 +176,17 @@ const char *DH_get_card_suit(DH_Card card);
* @param card The card to query.
* @return Pointer to a UTF-8 encoded Unicode string.
*/
const char *DH_get_card_unicode_suit(DH_Card card);
DH_API const char *DH_get_card_unicode_suit(DH_Card card);

const char *DH_get_unicode_suit(DH_suit suit);
DH_API const char *DH_get_unicode_suit(DH_suit suit);

/**
* @brief Get the string name of a face value given its integer representation.
*
* @param val Integer value representing a face (1–13).
* @return Pointer to a constant string.
*/
const char *DH_get_card_face_str(int val);
DH_API const char *DH_get_card_face_str(int val);

#ifdef __cplusplus
}
Expand Down
15 changes: 14 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
project(
'deckhandler',
'c',
version: '0.1.0999',
version: '0.0.1',
meson_version: '>= 0.56.0',
default_options: ['warning_level=3', 'c_std=c99'],
)
Expand All @@ -20,6 +20,18 @@ extra_flags = [

add_project_arguments(cc.get_supported_arguments(extra_flags), language: 'c')

# Parse version components
version_components = meson.project_version().split('.')
major_version = version_components[0]
minor_version = version_components[1]
patch_version = version_components[2]

conf = configuration_data()
conf.set('DH_VERSION_MAJOR', major_version)
conf.set('DH_VERSION_MINOR', minor_version)
conf.set('DH_VERSION_PATCH', patch_version)
config_h = configure_file(output : 'config.h', configuration : conf)

src = files('deckhandler.c')

pcg = subproject('pcg')
Expand All @@ -28,6 +40,7 @@ pcg_dep = pcg.get_variable('pcg_dep')
buildtarget = library(
meson.project_name(),
src,
c_args: '-DDECKHANDLER_BUILD',
dependencies: pcg_dep,
version: meson.project_version(),
install: not meson.is_subproject(),
Expand Down
4 changes: 3 additions & 1 deletion subprojects/pcg/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ project(
default_options: ['warning_level=3', 'c_std=c99'],
)

cc = meson.get_compiler('c')

extra_flags = [
'-fno-common',
'-fstack-protector-strong',
Expand All @@ -16,7 +18,7 @@ extra_flags = [
'-Werror=strict-aliasing',
]

add_project_arguments(extra_flags, language: 'c')
add_project_arguments(cc.get_supported_arguments(extra_flags), language: 'c')

_pcg = static_library('pcg', 'pcg_basic.c')

Expand Down
2 changes: 1 addition & 1 deletion test/test_01.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ int main(int argc, char *argv[]) {
} while (deals_num++ < deals_max);

puts("\n\n\t]=[ Create 4 decks, shuffle each one, and deal them all out ]=[\n");
int total_decks = 4;
enum { total_decks = 4 };
DH_Deck deck_num[total_decks];
for (int i = 0; i < total_decks; i++)
deck_num[i] = DH_get_new_deck();
Expand Down
Loading