{"id":16687963,"url":"https://github.com/danielpclark/cardslib","last_synced_at":"2025-07-25T03:04:31.338Z","repository":{"id":32227284,"uuid":"35801318","full_name":"danielpclark/CardsLib","owner":"danielpclark","description":"The \"smartest\" OO Card Game Library","archived":false,"fork":false,"pushed_at":"2017-04-29T14:00:57.000Z","size":80,"stargazers_count":29,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-13T15:25:57.062Z","etag":null,"topics":["card","card-evaluation","deck","game","game-development","library","ranker","ruby","ruby-gem"],"latest_commit_sha":null,"homepage":"","language":"Ruby","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/danielpclark.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-18T06:45:05.000Z","updated_at":"2022-01-12T04:24:45.000Z","dependencies_parsed_at":"2022-09-09T04:12:37.676Z","dependency_job_id":null,"html_url":"https://github.com/danielpclark/CardsLib","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielpclark%2FCardsLib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielpclark%2FCardsLib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielpclark%2FCardsLib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielpclark%2FCardsLib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danielpclark","download_url":"https://codeload.github.com/danielpclark/CardsLib/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221817705,"owners_count":16885604,"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":["card","card-evaluation","deck","game","game-development","library","ranker","ruby","ruby-gem"],"created_at":"2024-10-12T15:26:09.953Z","updated_at":"2024-10-28T10:37:42.380Z","avatar_url":"https://github.com/danielpclark.png","language":"Ruby","readme":"# CardsLib\n\n[![Gem Version](https://badge.fury.io/rb/cards_lib.svg)](http://badge.fury.io/rb/cards_lib)[![Build Status](https://travis-ci.org/danielpclark/CardsLib.svg?branch=master)](https://travis-ci.org/danielpclark/CardsLib)[![Code Climate](https://codeclimate.com/github/danielpclark/CardsLib/badges/gpa.svg)](https://codeclimate.com/github/danielpclark/CardsLib)[![Test Coverage](https://codeclimate.com/github/danielpclark/CardsLib/badges/coverage.svg)](https://codeclimate.com/github/danielpclark/CardsLib/coverage)\n\nI apply best practices in designing this gem and each feature has had\na LOT of thought put into it. Just look at how the Deck works. It's\ndesigned with an immutable set of cards to draw from and to return\ncards to. You can even seed it to write robust tests and get the same\nresults time after time. Card evaluation is written in a functional\nway that allows, and is optimized for, lazy evaluation. The set\nverification is as simple as handing it some cards and the names of\nthe rules to apply.\n\nI'm willing to bet you that there is no other Ruby card game library\nout there as easy to use, as well thought out, and as simple to\nunderstand as mine. Come on, I dare you to use it and review it! ;-)\n\n## Scope\n\nThe scope of this project aims to be a game agnostic card management\nand evaluation system.  Game logic itself will not be provided with\nthis library.  The creation, grouping, comparison, and evaluation of\ncards is the sole purpose of this gem.\n\nFeel free to contribute or raise suggestions via the issue tracker.\nI welcome participation of all kinds! :-)\n\n## Install\n\n```\ngem install 'cards_lib'\n```\nRequires Ruby 2 or greater.\n\n## Usage\n\nCreate a Card with Card.new(face)\n\n```ruby\nCardsLib::Card.new(\"As\")\n```\n\nUse a Macro to create a list of Card instances from card faces.\n\n```ruby\nCardsLib::Cards[\"Ah\",\"2h\",\"3h\",\"4h\",\"5h\"]\n```\n\nCreate a Deck with Deck.new(cards)\nA default deck is generated if no parameters are given.\n\n```ruby\nCardsLib::Deck.new\n```\n\nPick what rules you'd like to use in determining a set of cards.\n\n```ruby\n# BOOLEAN RESULT\nCardsLib::IsSet.verify(\n  card_instances_array,\n  rules = [:unique, :ordered, :paired, :suited],\n  specifications = {min: 3, max: Float::INFINITY}\n)\n```\n\n## Goodies\n\n* **lib/cards_lib/is_set.rb** is a golden tool in card hand verification.\n\n* In **lib/cards_lib/standard.rb** there are some basic deck templates.\n\n* In **lib/cards_lib/standard/rules/poker_rule.rb** there are some working Poker hand verification methods.\n\n* In **lib/cards_lib/standard/evaluators/blackjack_evaluator.rb** there is a Blackjack hand worth evaluation tool.  See the **test/standard/evaluators/blackjack_evaluator_test.rb** for examples.\n\n## Definitions\n\nThe main difference between **Rules** and **Evaluators** is Rules are purposed\nfor exact precedence and exact given matches (eg: two_pair only accepts\n4 cards).  An Evaluator can take all cards in a \"Hand\" *(Hand is not yet\ndefined in specification or implementation)* and give a complete evaluation\nof the hands worth.  To make a PokerEvaluator work for two_pair; one way you\ncould implement it is with\n\n```ruby\nhand.combination(4).detect {|cards| two_pair(cards)}\n```\n\nbut this is a very inefficient way to implement this.  Perhaps a more\nefficient way would be to use groupings\n\n```ruby\nhand.group_by(\u0026:rank).values.count {|group| group.length == 2} \u003e 1\n```\n\nBut that's pretty mutch the gist of it.  The Evaluators can give the\nentire hand evaluation where-as Rules are specific scenarios.\n\n**Ranker** is a card evaluation object that is passed into a Card when\nthe Cards are first initialized.  Each Card holds its own Ranker\nobject.\n\n# Example Usage\n\n### High Card\n\n```ruby\ninclude CardsLib\nclass CardRanks \u003c Ranker\n  def initialize(card)\n    super card, \"23456789TJQKA\".chars\n  end\nend\n\ndeck = Deck.new ranker: CardRanks\n# =\u003e \u003cDeck: 52 Cards - Seed#317847827465261913302134114334103894430\u003e\n\nfirst_card = deck.pluck\n# =\u003e (Card)\nfirst_card.face\n# =\u003e \"Th\"\nsecond_card = deck.pluck\n# =\u003e (Card)\nsecond_card.face\n# =\u003e \"6h\"\n\ncase [first_card.value, second_card.value].max\n  when -\u003e_{first_card.eql? second_card}\n    puts \"It's a tie!\"\n  when first_card.value\n    puts \"First player wins!\"\n  when second_card.value\n    puts \"Second player wins!\"\n  else\n    raise \"There was a problem determining a winner\"\n  end\nend\n# First player wins!\n```\n\nThe example above shows the shorthand way of creating a Ranker object with passing the ranks\nas a simple list from least to greatest value.  If you want to use a Hash (in case some cards\nof different ranks may be the same value) you may, but you must then also define a Proc for\nlookup.  See [lib/cards_lib/standard/rankers/blackjack_ranker.rb](https://github.com/danielpclark/CardsLib/blob/master/lib/cards_lib/standard/rankers/blackjack_ranker.rb) for an example of how to implement that.\n\n## License\n\nThe MIT License (MIT)\n\nCopyright (c) 2015-2017 by Daniel P. Clark\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielpclark%2Fcardslib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanielpclark%2Fcardslib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielpclark%2Fcardslib/lists"}