-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Mastermind project (#17) #32
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HOLY CRAP THIS IS A GOOD TUTORIAL. Love the setup. Super solid formating.
I added some small formatting things, feel free to make the changes and @Bobliuuu will take a look!
projects/create-mastermind-game-using-python/create-mastermind-game-using-python.mdx
Outdated
Show resolved
Hide resolved
projects/create-mastermind-game-using-python/create-mastermind-game-using-python.mdx
Outdated
Show resolved
Hide resolved
@@ -0,0 +1,225 @@ | |||
--- | |||
title: Create Mastermind game using Python | |||
author: 3t8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi! Not sure if I mentioned this before, but is it possible to show your name here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mind if we keep just the alias?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course! But may I ask how old are you and where you are from? Just so we know!
projects/create-mastermind-game-using-python/create-mastermind-game-using-python.mdx
Outdated
Show resolved
Hide resolved
projects/create-mastermind-game-using-python/create-mastermind-game-using-python.mdx
Outdated
Show resolved
Hide resolved
projects/create-mastermind-game-using-python/create-mastermind-game-using-python.mdx
Outdated
Show resolved
Hide resolved
…-game-using-python.mdx Co-authored-by: Sonny Li <[email protected]>
…-game-using-python.mdx Co-authored-by: Sonny Li <[email protected]>
…-game-using-python.mdx Co-authored-by: Sonny Li <[email protected]>
…-game-using-python.mdx Co-authored-by: Sonny Li <[email protected]>
…-game-using-python.mdx Co-authored-by: Sonny Li <[email protected]>
Thanks a lot! |
Alright, I just shared with the team this project, we all freaking love it and suuuper excited about releasing it. 🙌 So great job once again on the draft. One thing though: We are wondering, do you think the modern black and white terminal version is better or a color version is better, in your opinion? Our engineer brought up that we could use color in the terminal with something similar to colorama. But I just don't know if it's too late or not and if it's worth it. My guts is telling me though: If you think adding color will make the project 2x better, then I think we should do it! |
Thanks for the quick update! As I mentioned in the project, representing colors can be a bit tricky. I'm guessing with something like colorama you could use ANSI color codes on windows too, but I'm not sure that would cover web-based python interpreters. If you think a more classical version of the game with colors instead of numbers would be better, I have no problem implementing that |
projects/create-mastermind-game-with-python/create-mastermind-game-with-python.mdx
Outdated
Show resolved
Hide resolved
projects/create-mastermind-game-with-python/create-mastermind-game-with-python.mdx
Outdated
Show resolved
Hide resolved
projects/create-mastermind-game-with-python/create-mastermind-game-with-python.mdx
Outdated
Show resolved
Hide resolved
- A random 4 digit secret code is generated | ||
- The player will input a 4 digit number trying to guess the secret code | ||
- The number of digits that are correct and in the right position is returned | ||
- The number of digits that are correct but in the wrong position is returned |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick, but could you add a small note here about what "right position" and "correct" means?
The easiest way would be to use a simple mastermind example to walk through it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
projects/create-mastermind-game-with-python/create-mastermind-game-with-python.mdx
Outdated
Show resolved
Hide resolved
projects/create-mastermind-game-with-python/create-mastermind-game-with-python.mdx
Outdated
Show resolved
Hide resolved
while (guess.isnumeric() == False or len(guess) != 4): | ||
guess = input('Guess the four digit number: ') | ||
``` | ||
The `guess` read with `input` is treated as a string, same as the secret code `number`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't number
treated as a number here, not a string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Please change guess = 0
to guess = '0'
.
correct_position = 0 | ||
``` | ||
|
||
and one to count the correct digits in the wrong position |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this to the previous line.
"We need a variable ... in the right position and one ... wrong position.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The two variables can also be combined to one python field.
|
||
To improve this project you could try to: | ||
|
||
- Increase the number of digits the user has to guess. With 4 digits the possible permutations are 10000. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Increase the number of digits the user has to guess. With 4 digits the possible permutations are 10000. | |
- Increase the number of digits the user has to guess. With 4 digits the possible permutations are 10000, but with more digits, it would be harder for the user to guess the permutation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love it! Just dropped a few small changes, please take a look 😄
@@ -0,0 +1,226 @@ | |||
--- | |||
title: Create Mastermind Game with Python | |||
author: 3t8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you ok with using your real name here?
If so please update your name here
…game-with-python.mdx Co-authored-by: Jerry Zhu <[email protected]>
…game-with-python.mdx Co-authored-by: Jerry Zhu <[email protected]>
…game-with-python.mdx Co-authored-by: Jerry Zhu <[email protected]>
…game-with-python.mdx Co-authored-by: Jerry Zhu <[email protected]>
…game-with-python.mdx Co-authored-by: Jerry Zhu <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow. This is a really well-done project tutorial! I've reviewed it and left some comments that I think should be addressed.
- A random 4 digit secret code is generated | ||
- The player will input a 4 digit number trying to guess the secret code | ||
- The number of digits that are correct and in the right position is returned | ||
- The number of digits that are correct but in the wrong position is returned |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
The easiest way to do it is converting the number to a string and justify it to the right with `rjust` by adding `0` until it has `4` digits. | ||
|
||
``` python | ||
number = str(number).rjust(4, '0') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we rename this number
to secret_code
and also update all the usage of this variable below, to make it more semantic?
while (guess.isnumeric() == False or len(guess) != 4): | ||
guess = input('Guess the four digit number: ') | ||
``` | ||
The `guess` read with `input` is treated as a string, same as the secret code `number`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Please change guess = 0
to guess = '0'
.
```python | ||
correct_digit = 0 | ||
``` | ||
We will also use a copy of `number` in order to keep track of the digits that have already been matched and the ones that are left unmatched |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing a period.
The `guess` variable has not been changed at all, but we **must not** check the digits that have already been matched in the right position. | ||
That is done by also checking if `guess[i] != number[i]` (or if `unmathced[i] != 'f'`). | ||
|
||
```python |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing the aforementioned for
loop here.
|
||
## [#](#-counting-the-number-of-guesses-and-winning) Step 7. Counting the number of guesses and winning | ||
|
||
The whole code after the `number` generation needs to be inside a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to finish this sentence with a colon or "white
loop as follows:"
Hi @3t8! Dharma just reviewed it one last time, can you take a look? Also, after further thinking and research, let's do the colors!!! Just because colors is SUCH a big part of Mastermind Let's use |
Let me know when you finish these and we can merge it! @3t8 |
it doesn't have to be this crazy of course, but colors do add a layer of fun i think |
Hey @3t8, how's progress on the changes? Please let us know if you need any help! |
Closes issue #17
mdx