Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/eduardo06sp/mastermind
A terminal game of Mastermind in which the user can choose to play as the codemaster or codebreaker. The computer is guaranteed to guess correctly within 5 tries.
https://github.com/eduardo06sp/mastermind
mastermind oop ruby swaszek-algorithm
Last synced: 2 days ago
JSON representation
A terminal game of Mastermind in which the user can choose to play as the codemaster or codebreaker. The computer is guaranteed to guess correctly within 5 tries.
- Host: GitHub
- URL: https://github.com/eduardo06sp/mastermind
- Owner: Eduardo06sp
- Created: 2021-05-08T20:39:03.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-05-11T03:26:21.000Z (over 3 years ago)
- Last Synced: 2024-12-09T11:51:03.231Z (about 2 months ago)
- Topics: mastermind, oop, ruby, swaszek-algorithm
- Language: Ruby
- Homepage: https://replit.com/@Eduardo06sp/Mastermind?v=1
- Size: 25.4 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Mastermind
This project is played entirely in the terminal. Initially, the player chooses to either play as the codemaker or the codebreaker. The computer is automatically made the opponent. The computer's guessing algorithm is an implementation of the Swaszek Mastermind algorithm, guaranteed to guess correctly within 5 tries.
Rules:
* The codebreaker has 12 attempts to break the code
* The possible code pegs are: R O Y G B V
* These letters represent the colors of the rainbow for ease of use / rememberance (with the exception of indigo)
* The pattern (i.e. the answer) must be 4 letters long
* Duplicates in the pattern are allowedHow To Play:
* [Here is a wikiHow article explaining it with the help of pictures](https://www.wikihow.com/Play-Mastermind)
* Lowercase letters are allowed
* If you are codemaster
* Type in a 4-letter pattern for the computer to guess
* Watch as the computer correctly guesses the pattern within 5 tries :}
* If you are codebreaker
* You will have to type in a 4-letter guess
* Black key pegs are represented in text
* They indicate the number of code pegs (i.e. colors you guessed) that are the right color and in the right spot
* White key pegs are also represented in text
* They indicate the number of code pegs that are the correct color in the _wrong_ spot
* You can only win if you guess the correct colors in the correct spot (i.e. get 4 black key pegs) within 12 attemptsSome of the techniques I learned include:
* Designing with **object-oriented programming** in mind
* Separating classes / modules into different classes for **code organization**
* Adding top-level **documentation** for each class / module
* Using **inheritance** to avoid duplicating code
* Using **heredocs** to display terminal interface and prevent cluttery code
* Creating **private methods** to prevent oversharing of classes