Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/andy5995/zigdeck
A library that creates and shuffles a deck of cards from which you can draw
https://github.com/andy5995/zigdeck
cards library mit-license simulation zig zig-library zig-package
Last synced: 28 days ago
JSON representation
A library that creates and shuffles a deck of cards from which you can draw
- Host: GitHub
- URL: https://github.com/andy5995/zigdeck
- Owner: andy5995
- License: mit
- Created: 2024-03-11T08:10:46.000Z (8 months ago)
- Default Branch: trunk
- Last Pushed: 2024-03-14T09:43:13.000Z (8 months ago)
- Last Synced: 2024-09-29T02:01:54.986Z (about 1 month ago)
- Topics: cards, library, mit-license, simulation, zig, zig-library, zig-package
- Language: Zig
- Homepage:
- Size: 22.5 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Linux CI](https://github.com/andy5995/zigdeck/actions/workflows/linux.yml/badge.svg)](https://github.com/andy5995/zigdeck/actions/workflows/linux.yml)
# zigdeck
A library that creates and shuffles a deck of cards from which you can draw
Tested with the the development version of [zig](https://ziglang.org/) (may
not build with the last release).## Example
```zig
// initialize the deck. This must be done before shuffle.
var deck = Deck.init();try std.testing.expectEqual(Suit.Clubs, deck.cards[0].suit);
try std.testing.expectEqual(Face.Ace, deck.cards[0].face);
try std.testing.expectEqual(Suit.Spades, deck.cards[48].suit);
try std.testing.expectEqual(Face.King, deck.cards[51].face);// Seed the random number generator
var rng = std.rand.DefaultPrng.init(@as(u64, @intCast(std.time.milliTimestamp())));// Shuffle
Deck.shuffle(&deck, &rng.random());// Draw one card
const card = Deck.getTopCard(&deck) orelse return;try std.testing.expectEqual(Suit.Clubs, card.suit);
try std.testing.expectEqual(Face.Queen, card.face);std.debug.print("Top card: Suit = {}, Value = {}\n", .{ card.suit, card.face });
```This library is used by [zigpokerhands](https://github.com/andy5995/zigpokerhands).