{"id":19527221,"url":"https://github.com/sbagdat/mastermind_generator","last_synced_at":"2025-04-26T10:31:40.754Z","repository":{"id":52047850,"uuid":"346169824","full_name":"sbagdat/mastermind_generator","owner":"sbagdat","description":"Fully customizable mastermind game generator. Supports custom items, multiplayer, timers, and etc.","archived":false,"fork":false,"pushed_at":"2021-05-07T23:58:24.000Z","size":66,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-04T11:51:10.131Z","etag":null,"topics":["game","mastermind","multiplayer","rails","ruby","wordle"],"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/sbagdat.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":"2021-03-09T23:12:19.000Z","updated_at":"2022-01-27T22:09:38.000Z","dependencies_parsed_at":"2022-08-03T08:00:49.587Z","dependency_job_id":null,"html_url":"https://github.com/sbagdat/mastermind_generator","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbagdat%2Fmastermind_generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbagdat%2Fmastermind_generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbagdat%2Fmastermind_generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbagdat%2Fmastermind_generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sbagdat","download_url":"https://codeload.github.com/sbagdat/mastermind_generator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250972916,"owners_count":21516443,"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":["game","mastermind","multiplayer","rails","ruby","wordle"],"created_at":"2024-11-11T01:13:59.397Z","updated_at":"2025-04-26T10:31:40.370Z","avatar_url":"https://github.com/sbagdat.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MastermindGenerator\n\n[![Gem Version](https://badge.fury.io/rb/mastermind_generator.svg)](https://badge.fury.io/rb/mastermind_generator)\n[![Build Status](https://travis-ci.com/sbagdat/mastermind_generator.svg?token=eLjuyGgeA2bT8BPBsdDh\u0026branch=main)](https://travis-ci.com/sbagdat/mastermind_generator)\n\nMastermind\u003csup\u003e*\u003c/sup\u003e Generator is a fully customizable mastermind (or master mind) game generator. It supports using\ncustom items other than classic color variations. It can also generate multi-player games.\n\nIf you are looking for a playable version of Mastermind, you can look at\n[demo folder](https://github.com/sbagdat/mastermind_generator/tree/main/demo).\n\n\u003csup\u003e*\u003c/sup\u003e Mastermind s a code-breaking game. For more\ninformation: [Wikipedia](https://en.wikipedia.org/wiki/Mastermind_(board_game))\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'mastermind_generator'\n```\n\nAnd then execute:\n\n    $ bundle install\n\nOr install it yourself as:\n\n    $ gem install mastermind_generator\n\n## Configuration\n\nBefore you use mastermind generator you need to configure it. Two attributes should be supplied like below:\n\n```ruby\nMastermindGenerator.configure do |config|\n  config.items = %w[red green blue yellow purple orange]\n  config.difficulties = {\n    beginner: {\n      item_count: 4,\n      sequence_length: 4\n    },\n    intermediate: {\n      item_count: 5,\n      sequence_length: 6\n    },\n    advanced: {\n      item_count: 6,\n      sequence_length: 8\n    }\n  }\nend\n```\n\n## Basic Usage\n\nRequire the gem and include it in your class definition.\n\n```ruby\nrequire 'mastermind_generator'\n# require \"path_to_your_configuration_file\"\n\nclass MastermindGame\n  include MastermindGenerator\n\n  # your code goes here...\nend\n```\n\nNow, you can generate game objects...\n\n```ruby\n...\n\n  class MastermindGame\n    include MastermindGenerator\n    attr_reader :game\n\n    def start\n      # You must supply one of the difficulty level as an argument to `Game.new`\n      @game = Game.new(:beginner)\n\n      # You can add one or two player\n      game.add_player(\"Aaron\")\n      game.add_player(\"Celine\")\n\n      # You are ready to create a game loop however you want\n      # An example is shown below\n      loop do\n        # Current player takes a guess (chosen automatically)\n        print \"Hey #{game.player_name}! What's your guess?\"\n        game.take_a_guess(gets.strip)\n\n        # Check the guess is succeed or fail\n        if game.finished?\n          puts \"congrats\"\n          break\n        else\n          puts \"feedback\"\n        end\n\n        # if the game is multi-player, you need to call `@game.next_turn`\n        game.next_turn if game.players_count \u003e 1\n      end\n    end\n  end\n```\n\n## Gathering information\n\nYou can use following methods to get information about the game.\n\n```ruby\ngame.sequence_value # returns auto-generated target sequence value\n\ngame.player_name # returns current player's name\n\ngame.guesses # returns all of guesses of the current player\n\ngame.guess_stats\n# returns all information about the current player guesses\n# # =\u003e {\n#    value:  guess sequence value,\n#    target: target sequence value,\n#    status: successful or fail,\n#    count: count of guesses,\n#    element_count:  correct element count,\n#    position_count: correct position count,\n#    position_hints: correct position hints,\n#    duration: elapsed time,\n#    duration_as_text: elapsed time in human readable format,\n# }\n\n# You can also get some of the statistics by piece \ngame.guess_value\ngame.guess_count\ngame.timer_duration\ngame.timer_duration_as_text\n```\n\n## Providing Feedbacks\n\nYou can give feedbacks to your players by using the methods we mentioned above. An example is given below:\n\n```ruby\ndef congrats\n  print(\u003c\u003c~MSG)\n    Congratulations #{game.player_name}! You guessed the sequence '#{game.sequence_value.upcase}' \\\n    in #{game.guesses_count} guesses over #{game.timer_duration_as_text}.\n  MSG\nend\n```\n\n```ruby\ndef feedback\n  stats = game.guess_stats\n  print(\u003c\u003c~MSG)\n      '#{stats[:value].upcase}' has #{stats[:element_count]} of the correct elements with \\\n      #{stats[:position_count]} in the correct positions.\\nYou've taken #{stats[:count]} guess.\n  MSG\nend\n```\n\n## Exception Handling\n\nThere are six error types defined in the gem with proper `#message` methods.\n\n* SequenceTooLongError\n* SequenceTooShortError\n* SequenceHasInvalidCharsError\n* InvalidDifficultyError\n* TimerNotStartedError\n* TimerNotStoppedError\n\nAn example usage might be like this:\n\n```ruby\nbegin\n  print(\"Hey #{game.player_name}! What's your guess? \u003e \")\n  game.take_a_guess(gets.strip)\nrescue SequenceTooLongError, SequenceTooShortError, SequenceHasInvalidCharsError =\u003e e\n  warn(\"#{e.message}. Try again!\")\n  retry\nend\n```\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/sbagdat/mastermind_generator. This project is\nintended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to\nthe [code of conduct](https://github.com/sbagdat/mastermind_generator/blob/main/CODE_OF_CONDUCT.md).\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the MastermindGenerator project's codebases, issue trackers, chat rooms and mailing lists is\nexpected to follow the [code of conduct](https://github.com/sbagdat/mastermind_generator/blob/main/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsbagdat%2Fmastermind_generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsbagdat%2Fmastermind_generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsbagdat%2Fmastermind_generator/lists"}