{"id":19543364,"url":"https://github.com/jonathanyiv/mastermind","last_synced_at":"2025-10-24T08:05:47.591Z","repository":{"id":87536040,"uuid":"99517540","full_name":"JonathanYiv/mastermind","owner":"JonathanYiv","description":"Implementation of Mastermind in Ruby","archived":false,"fork":false,"pushed_at":"2017-08-08T15:38:33.000Z","size":63,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-26T05:33:23.582Z","etag":null,"topics":["mastermind","ruby"],"latest_commit_sha":null,"homepage":"https://repl.it/@JonathanYiv/Mastermind","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JonathanYiv.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2017-08-06T22:47:23.000Z","updated_at":"2019-09-18T20:44:54.000Z","dependencies_parsed_at":"2023-05-10T12:31:34.368Z","dependency_job_id":null,"html_url":"https://github.com/JonathanYiv/mastermind","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/JonathanYiv/mastermind","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JonathanYiv%2Fmastermind","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JonathanYiv%2Fmastermind/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JonathanYiv%2Fmastermind/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JonathanYiv%2Fmastermind/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JonathanYiv","download_url":"https://codeload.github.com/JonathanYiv/mastermind/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JonathanYiv%2Fmastermind/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267029407,"owners_count":24024199,"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","status":"online","status_checked_at":"2025-07-25T02:00:09.625Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["mastermind","ruby"],"created_at":"2024-11-11T03:18:28.860Z","updated_at":"2025-10-24T08:05:47.532Z","avatar_url":"https://github.com/JonathanYiv.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mastermind Project\n\nCheck out my command line version of the game [Mastermind](https://en.wikipedia.org/wiki/Mastermind_(board_game)) built with Ruby!\n\nThis is a project from [The Odin Project](https://www.theodinproject.com/courses/ruby-programming/lessons/oop).\n\n![Mastermind](/mastermind.png)\n\n## Installation\n\nOpen your Terminal/Command Line. Navigate to the directory where your version will live. Type in the following:\n\n```\n$ git clone https://github.com/JonathanYiv/mastermind.git\n$ cd mastermind\n$ bundle install\n$ ruby mastermind.rb\n```\n\n## Pre-Project Thoughts\n\nI will need to figure out how to colorize the command line from a ruby script.\n\n### Thoughts on Structure\n\n```ruby\nclass Mastermind\n\tinstance variables:\n\t\tgameboard\n\tmethods:\n\t\tinitialize: takes a parameter to decide whether human/computer picks the code\n\t\tplay: starts the game\n\t\t\tinstructions: prints the instructions\n\nclass GameBoard = one instance\n\tinstance variables: \n\t\tsolution as a colorcode object\n\t\tarray of colorcode objects for display\n\t\tarray of hint objects for display\n\tmethods:\n\t\tdisplay: displays the entire board\n\t\trefresh: given a new colorcode, adds it to the display, and evaluates the hints\n\t\tevalute: based on the colorcode, provide a hint\n\nclass ColorCode = instances include a solution instance and a guess instance \n\tinstance variables: \n\t\tcolor1\n\t\tcolor2\n\t\tcolor3\n\t\tcolor4\n\tmethods:\n\t\tinitialize: takes four parameters to create a set of colors or defaults to a randomly selected set of color\n\nclass Hint = instances of the hints with red/white/black\n\tinstance variables:\n\t\tcolor1\n\t\tcolor2\n\t\tcolor3\n\t\tcolor4\n\tmethods:\n\t\tinitialize: takes five parameters (including the colorcode solution) and sets its four colors accordingly\n\nclass Computer\n\tinstance variables:\n\t\tincluded colors\n\tmethods:\n\t\talgorithms to solve mastermind\n```\n\t\n\n\n## Post-Project Thoughts\n\n1. To include color in the project, I found the ruby gem \"colorize.\" I also read about ANSI Escape Codes [(see below)](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors) which were a little too intense for the scope of this project. See below.\n\n```ruby\nclass String\n\tdef black;          \"\\e[30m#{self}\\e[0m\" end\n\tdef red;            \"\\e[31m#{self}\\e[0m\" end\n\tdef green;          \"\\e[32m#{self}\\e[0m\" end\n\tdef brown;          \"\\e[33m#{self}\\e[0m\" end\n\tdef blue;           \"\\e[34m#{self}\\e[0m\" end\n\tdef magenta;        \"\\e[35m#{self}\\e[0m\" end\n\tdef cyan;           \"\\e[36m#{self}\\e[0m\" end\n\tdef gray;           \"\\e[37m#{self}\\e[0m\" end\n\n\tdef bg_black;       \"\\e[40m#{self}\\e[0m\" end\n\tdef bg_red;         \"\\e[41m#{self}\\e[0m\" end\n\tdef bg_green;       \"\\e[42m#{self}\\e[0m\" end\n\tdef bg_brown;       \"\\e[43m#{self}\\e[0m\" end\n\tdef bg_blue;        \"\\e[44m#{self}\\e[0m\" end\n\tdef bg_magenta;     \"\\e[45m#{self}\\e[0m\" end\n\tdef bg_cyan;        \"\\e[46m#{self}\\e[0m\" end\n\tdef bg_gray;        \"\\e[47m#{self}\\e[0m\" end\nend\n```\n\n2. The computer AI was rather complex to implement; I spent the most time on that portion specifically. I only managed to get it to a 20% win-rate for now. I will come back and update it later with the [wikipedia supplied algorithm](https://en.wikipedia.org/wiki/Mastermind_(board_game)#Five-guess_algorithm) that guarantees a solution in five moves.\n\n3. My last project, [Tic-Tac-Toe](https://github.com/JonathanYiv/tic-tac-toe) followed poor practices regarding separating classes into different files. This project does better in that regard. However, several methods are overly complex and have too much responsibi\n\n4. @benjaminapetersen and the Odinites found three issues. \n\n\t1. The text sanitizer only ran each check once, so if you passed the first test but failed the second test, it would only check for the second test onwards. I fixed it by pulling it all into a large loop with redo statements if tests fail.\n\n\t2. The project requires the gem 'colorize' which I had not previously set up for users, causing an error. I set up a Gemfile and added an instruction with bundler in the installation instructions.\n\n\t3. Ruby has a syntax of two spaces per indent. I adjusted my text editor's settings to reflect this, so all future ruby files will be indented accordingly.\n\n5. Overall, it was a very fun project, probably the most complex for me to date.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonathanyiv%2Fmastermind","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonathanyiv%2Fmastermind","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonathanyiv%2Fmastermind/lists"}