Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

# Mastermind.py has trouble counting black and white pegs.

See original GitHub issue

I was working on reverting #611 because it was just wrong and decided to run a few games to test it was doing the right thing. Using Python 3.8.10. There’s also a bit of debug printf’s regarding what its doing while taking the computer is guessing.

There’s some screwy stuff going on with this port. Here is an example of it not validating ANY possible answer on the simplest puzzle of two colors and two positions (4 total possible solutions.)

`````` Mastermind
Creative Computing Morristown, New Jersey
Number of colors (max 8): 2
Number of positions: 2
Number of rounds: 2
Number of possibilities 4
Color   Letter
=====   ======
BLACK   B
WHITE   W
Round number 1
Guess my combination ...
Move # 1 Guess :
Guess BW
Results: ['BW', 0, 0]
You have 0 blacks and 0 whites
Move # 2 Guess :
Guess WW
Results: ['WW', 0, 0]
You have 0 blacks and 0 whites
Move # 3 Guess :
Guess BB
Results: ['BB', 0, 0]
You have 0 blacks and 0 whites
Move # 4 Guess :
Guess RR
INVALID GUESS: RR
Move # 4 Guess :
Guess BB
Results: ['BB', 0, 0]
You have 0 blacks and 0 whites
Move # 5 Guess :
Guess BWB
BAD NUMBER OF POSITIONS
Move # 5 Guess :
Guess BB
Results: ['BB', 0, 0]
You have 0 blacks and 0 whites
Move # 6 Guess :
Guess WW
Results: ['WW', 0, 0]
You have 0 blacks and 0 whites
Move # 7 Guess :
Guess BW
Results: ['BW', 0, 0]
You have 0 blacks and 0 whites
Move # 8 Guess :
Guess WB
Results: ['WB', 0, 0]
You have 0 blacks and 0 whites
Move # 9 Guess :
Guess ^CTraceback (most recent call last):
``````

Here the computer guesses TT.

``````Mastermind
Creative Computing Morristown, New Jersey
Number of colors (max 8): 2
Number of positions: 2
Number of rounds: 1
Number of possibilities 4
Color   Letter
=====   ======
BLACK   B
WHITE   W
Round number 1
Guess my combination ...
Move # 1 Guess :
Guess BW
Results: ['BW', 0, 2]
You have 0 blacks and 2 whites
Move # 2 Guess :
Guess WB
Results: ['WB', 2, 0]
You guessed it in 2 moves!
SCORE:
COMPUTER 0
HUMAN    2
NOW I GUESS. THINK OF A COMBINATION.
HIT RETURN WHEN READY:
My guess is: TT
ENTER BLACKS, WHITES (e.g. 1,2): 0,0
['TT', 2, 0]
['BB', 0, 0]
['WB', 0, 0]
['BW', 0, 0]
My guess is: BB
ENTER BLACKS, WHITES (e.g. 1,2): 2,0
I GOT IT IN 2 MOVES
SCORE:
COMPUTER 2
HUMAN    2
GAME OVER
FINAL SCORE:
COMPUTER 2
HUMAN    2

``````

Similar to the first example. Three colors, two positions, computer says none of the colors is in the solution.

``````Mastermind
Creative Computing Morristown, New Jersey
Number of colors (max 8): 3
Number of positions: 2
Number of rounds: 2
Number of possibilities 9
Color   Letter
=====   ======
BLACK   B
WHITE   W
RED     R
Round number 1
Guess my combination ...
Move # 1 Guess :
Guess BB
Results: ['BB', 0, 0]
You have 0 blacks and 0 whites
Move # 2 Guess :
Guess WW
Results: ['WW', 0, 0]
You have 0 blacks and 0 whites
Move # 3 Guess :
Guess RR
Results: ['RR', 0, 0]
You have 0 blacks and 0 whites
Move # 4 Guess :
Guess

``````

### Issue Analytics

• State:
• Created a year ago
• Comments:5 (5 by maintainers)

#### Top GitHub Comments

1reaction
jnelliscommented, Apr 29, 2022

Cool, I’ve figured out the python issues and will push those soon as well.

1reaction
AnthonyMichaelTDMcommented, Apr 29, 2022

I think I read that you ported your rust port from this python port, is that correct? Maybe this the reason you saw funny behavior?

I did not, but I figured out the reason I saw errors in my port, I was comparing the possibilities to the answer when filtering them, not to the computers guess. see here

I’ll probably push those changes soon once I refactor the rust port to follow rust conventions more closely (extract game logic to lib.rs to improve readability of main.rs and make testing logic easier)

Read more comments on GitHub >

#### Top Results From Across the Web

Mastermind game python pegs count
The first R creates a black peg, right? Every other R is indeed in your code (since your method doesn't account for duplicates),...
Read more >
Mastermind/Guess the Code Game - Python Forum
The official dedicated python forum. ... This is to take out the "S" if the number of white pegs or black pegs is...
Read more >
Programming Mastermind in Python : r/learnprogramming
A black peg represents a digit in the guess being at the exact right spot in the code. A white peg represents a...
Read more >
Solving Mastermind With Python
The Codemaker then places either black or white pegs on the Hint Slot using the following logic: Black: Placed for each guess peg...
Read more >
Thinking Task #2: Mastermind – you need to be! - Code? Boom.
The basic premise of the game is that the problem setter picks a combination of four coloured pegs (usually from a choice of...
Read more >

No results found

No results found

#### Troubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

No results found

No results found

No results found

No results found

No results found