I am in the process of writing and debugging a Python version of Mastermind. I have to use classes, so I have them all in their own files. I have them called and such. My problem now is that a part of the code likes to repeat itself ad infinitum. Yikes!
Possible colors (enter first letter): [r]ed [g]reen lue [p]urple [o]range [y]ellow
Black pegs: 0
White pegs: 0
That is what is repeated forever until I ctrl+c the program. It only starts repeating after I have entered the four colors for the first guess.
My main code is:
import random from generateSecretColors import * from colors import * from guess import * from exactMatch import * from partialMatch import * def main(): allColors = Colors() allColors.colors() secret = SecretColors() secret.generateSecretColors() guess = Guess() secretCode = secret.returnSecret() exactMatchCount = ExactMatch() partialMatchCount = PartialMatch() #print "Secret Code - for testing - MAKE SURE TO REMOVE!" + str(secretCode) exact = 0 while (exact != 4): userGuess = guess.askForGuess() exact = exactMatchCount.exactMatch(userGuess,secretCode) partial = partialMatchCount.partialMatch(userGuess,secretCode) print "Black pegs: " + str(exact) print "White pegs: " + str(partial) if guess == secretCode: print "You got it! Good job!" if __name__=='__main__': main()
I don't know if you can fix it from just that. If you need to see the classes, let me know and I will fix them. Thanks for the help!