{"id":14960990,"url":"https://github.com/radialgames/deck","last_synced_at":"2025-10-24T20:30:43.066Z","repository":{"id":206465751,"uuid":"716722529","full_name":"RadialGames/Deck","owner":"RadialGames","description":"A generic C# deck/card/shuffling library, compatible with the Unity Package Manager","archived":false,"fork":false,"pushed_at":"2023-11-09T23:27:58.000Z","size":42,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-31T03:54:13.206Z","etag":null,"topics":["csharp","csharp-library","deck","deckofcards","randomization","shuffle","unity","unity3d","upm-package"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RadialGames.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-09T18:26:43.000Z","updated_at":"2023-11-24T17:51:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"07e60c38-4ba2-43dd-bdc6-c5229ba020a3","html_url":"https://github.com/RadialGames/Deck","commit_stats":{"total_commits":20,"total_committers":2,"mean_commits":10.0,"dds":"0.050000000000000044","last_synced_commit":"571938248d5cdbd3cc9b11358f8b6bfb0c89a342"},"previous_names":["radialgames/deck"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RadialGames%2FDeck","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RadialGames%2FDeck/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RadialGames%2FDeck/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RadialGames%2FDeck/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RadialGames","download_url":"https://codeload.github.com/RadialGames/Deck/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238030288,"owners_count":19404859,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","csharp-library","deck","deckofcards","randomization","shuffle","unity","unity3d","upm-package"],"created_at":"2024-09-24T13:23:36.437Z","updated_at":"2025-10-24T20:30:37.688Z","avatar_url":"https://github.com/RadialGames.png","language":"C#","readme":"﻿Deck\n===========\n\n## Concept\n\nThis is the `UPM` repository for Deck, the generic C# deck/card/shuffling abstraction library.\n\nWhen designing games, I often think about random events and items in terms of \"cards in a deck.\" This makes it easier to\nconceptualize odds, weights, repetition, and probabilities.\n\nThis library is a generic implementation of that concept -- it doesn't presuppose cards, and instead uses generic types\nof your own choosing.\n\nFeel free to send feedback, submit pull requests, or open issues!\n\n## Requirements\n\n- This packages requires access to the `System` and `System.Collections.Generic` namespaces, which should be trivial for\nany standard project package.\n- Tested in Unity 2019.4.0f1, should work in anything newer.\n- This package utilizes C# language features introduced in C# 8.0, and thus requires a compiler that supports that, eg:\n.NET Core 3.x or .NET 5.0+\n\n## Installation\n\nInstall it via the Unity Package Manager by:\n- Opening your project in Unity\n- Open the Package Manager window (`Window \u003e Package Manager`)\n- Click the `+` button in the top left corner of the window\n- Select `Add package from git URL...`\n- Enter the following url, and you'll be up to date: `https://github.com/RadialGames/Deck.git`\n\nOr if you aren't using Unity, just grab the C# files and start using them as-is. Nothing in this package requires Unity;\nand there are no Unity-specific dependencies. You can use these files directly in any C# project.\n\n## Usage\n\nAll files in this package are in the `Radial.Deck` namespace. Access them by adding the following to the top of your\nfiles:\n\n```c#\nusing Radial.Deck;\n```\n\n### QuickStart\n\nYou can quickly create a new `Deck` and start using it with the following code:\n\n```c#\nvar deck = new Deck\u003cint\u003e(); // Create the initial deck, and populate it\ndeck.Library.AddToTop(1);\ndeck.Library.AddToTop(2);\ndeck.Library.AddToTop(3);\n\nint[] myHand = deck.Draw(2); // draws [3,2]\n\ndeck.Discard(myHand); // Discard your hand\n\nmyHand = deck.Draw(2); // Auto shuffles the discarded items back into the library, and draws [1,3] (non-deterministic)\n```\n\nNote that the type used when declaring the `Deck` is not locked to `int`, it can be of any basic type or your own\nconstructs.\n\n### Set\n\nThe foundation of this package is a `Set\u003cT\u003e` of items. The items can be of any type. A `Set` could be thought of as\nany collection of cards -- a draw pile, a discard pile, a graveyard, whatever your project needs.\n\nSets can be initialized with any `IEnumerable` such as a `Stack\u003cT\u003e` or a `Queue\u003cT\u003e` of items; the draw-order of items is\nimportant and preserved, with the first index (0) of an array or List being drawn first.\n\n```c#\nvar items = new Stack\u003cint\u003e(); // LIFO\nitems.Add(2);\nitems.Add(1); // top card on the deck, will be drawn first\n\nvar set = new Set\u003cint\u003e(items);\nset.Draw(); // 1\nset.Draw(); // 2\n```\n\nYou can also initialize a `Set` with no items, and add them later.\n\n```c#\nvar set = new Set\u003cstring\u003e();\nset.Size(); // 0\nset.AddToTop(\"foo\");\nset.AddToTop(\"bar\");\n\nset.Draw(); // \"bar\"\n```\n\nAs demonstrated above, the `Draw()` function will remove an item from the top of the Set, and return it. You can also\nrequest a certain number of cards to be Drawn, which will return an array of items:\n\n```c#\nvar set = new Set\u003cint\u003e();\nset.AddToTop(1);\nset.AddToTop(2);\nset.AddToTop(3);\nvar itemsInHand = set.Draw(2); // [3, 2]\n```\n\nIt's important to note that a `Set` on its own does not track items that have been drawn - once you draw all the items\nof a set, the Set will be empty, and you will have to re-populate it (and perhaps shuffle it).\n\n```c#\nvar set = new Set\u003cint\u003e();\nset.AddToTop(1);\nvar itemInHand = set.Draw(); // 1\n\nset.Size(); // 0; calling Draw() again at this point will cause an Exception.\nset.AddToBottom(itemInHand); // add the item back to the bottom of the Set\nitemInHand = set.Draw(); // Draw a new item (still 1!)\n```\n\nYou can `AddToBottom()`, `AddToTop()`, or `AddAtIndex()`, so you have flexibility on where items can be inserted.\nThis will alter the order in which items will be drawn; items are always drawn from the top first.\n\n```c#\nvar set = new Set\u003cint\u003e();\nset.AddToTop(1);\nset.AddToTop(2);\nset.AddToBottom(3);\n\nset.Draw(); // 2\n```\n\nYou can also `Clear()` a Set to wipe it completely, and `Shuffle()` a set to randomize the order of the items inside.\n\n### Deck\n\nA Deck is a helper collection of Sets that can be shuffled and drawn from; it tracks an individual Library, Discarded,\nand Exiled Set. It can be thought of as all the cards in the box, minus anything that is \"in play\" (and managed by your\nown game logic).\n\n(TODO: an InHand Set, that helps manage that common state further).\n\nThe primary role of the `Deck` class is to help automate the common process of drawing from a `Library`, and shuffling\n`Discarded` items back into your Library when the Library is empty.\n\n`Deck`s are initialized with a collection of items as the initial state of the system.\n\n```c#\nvar initialLibrary = new int[] { 1, 2, 3 };\n\nvar deck = new Deck\u003cint\u003e(initialLibrary);\nvar itemInHand = deck.Draw(); // 1\ndeck.Discard(item); // place this item in the discard pile for future use\n\nvar itemsInHand = deck.Draw(3); // [2, 3, 1] - this is deterministic as there is only one item in the discard pile.\ndeck.Discard(itemsInHand); // place all the items back into discard.\ndeck.Library.Size(); // 0\ndeck.Discarded.Size(); // 3\n\ndeck.Draw(); // random result (shuffled)\n```\n\nA `Deck` also contains an `Exiled` set, which is not shuffled back into the `Library` unless explicitly requested.\n\n\n```c#\ndeck.ReturnExiledToBottomOfLibrary();\ndeck.Library.Shuffle();\n```\n\n## Randomization\n\nThe `Set` and `Deck` classes both accept a `Random` object in their constructors, which can be used to control the\nrandom seed used when `Set.Shuffle()` is called (thus making the shuffle, optionally, deterministic).\n\nIf no `Random` object is provided, a new one is generated with non-deterministic results.\n\nYou can call `Deck.ReplaceRandomProvider(new Random(mySeed))` to replace the random provider for all `Set`s in your\n`Deck` in a single operation.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fradialgames%2Fdeck","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fradialgames%2Fdeck","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fradialgames%2Fdeck/lists"}