Skip to content
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

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open

Add Mastermind project (#17) #32

wants to merge 18 commits into from

Conversation

3t8
Copy link

@3t8 3t8 commented Nov 6, 2022

Closes issue #17

  • My project tutorial topic has already been aproved by the Codédex team
  • My project tutorial file renders properly in mdx
  • The content written is my own, and not plagiarized from other sources
  • All code written is commented or documented thoroughly
  • I have already completed a self-review of the project tutorial
  • I will comply with changes from the Codédex team about my project tutorial

Copy link
Member

@sonnynomnom sonnynomnom left a 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!

@@ -0,0 +1,225 @@
---
title: Create Mastermind game using Python
author: 3t8
Copy link
Member

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?

Copy link
Author

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?

Copy link
Member

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!

3t8 and others added 10 commits November 23, 2022 13:40
…-game-using-python.mdx

Co-authored-by: Sonny Li <sonnynomnom@gmail.com>
…-game-using-python.mdx

Co-authored-by: Sonny Li <sonnynomnom@gmail.com>
…-game-using-python.mdx

Co-authored-by: Sonny Li <sonnynomnom@gmail.com>
…-game-using-python.mdx

Co-authored-by: Sonny Li <sonnynomnom@gmail.com>
…-game-using-python.mdx

Co-authored-by: Sonny Li <sonnynomnom@gmail.com>
@3t8
Copy link
Author

3t8 commented Nov 23, 2022

Thanks a lot!
I updated the project with your suggestions, found and fixed a few typos that I previously missed and ended up changing the name of the project according to the new title. Let me know if I should change anything else.
@sonnynomnom

@sonnynomnom
Copy link
Member

sonnynomnom commented Nov 23, 2022

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!

@3t8

@3t8
Copy link
Author

3t8 commented Nov 23, 2022

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

@sonnynomnom

- 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
Copy link
Contributor

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

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`.
Copy link
Contributor

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?

Copy link
Member

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
Copy link
Contributor

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.

Copy link
Contributor

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- 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.

Copy link
Contributor

@Bobliuuu Bobliuuu left a 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
Copy link
Collaborator

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 <54565411+Bobliuuu@users.noreply.github.com>
3t8 and others added 4 commits December 2, 2022 12:58
…game-with-python.mdx

Co-authored-by: Jerry Zhu <54565411+Bobliuuu@users.noreply.github.com>
…game-with-python.mdx

Co-authored-by: Jerry Zhu <54565411+Bobliuuu@users.noreply.github.com>
…game-with-python.mdx

Co-authored-by: Jerry Zhu <54565411+Bobliuuu@users.noreply.github.com>
…game-with-python.mdx

Co-authored-by: Jerry Zhu <54565411+Bobliuuu@users.noreply.github.com>
Copy link
Member

@Goku-kun Goku-kun left a 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
Copy link
Member

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')
Copy link
Member

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`.
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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:"

@sonnynomnom
Copy link
Member

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 usecolorama, termcolor, or something else of your choice. Just because we should expect the user to use VS Code or Repl.it to finish this!

@sonnynomnom
Copy link
Member

Let me know when you finish these and we can merge it! @3t8

@sonnynomnom
Copy link
Member

take a look at this for inspiration:
mastermind

@sonnynomnom
Copy link
Member

sonnynomnom commented Dec 9, 2022

it doesn't have to be this crazy of course, but colors do add a layer of fun i think

@Bobliuuu
Copy link
Contributor

Hey @3t8, how's progress on the changes? Please let us know if you need any help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants