Everything const except SetGuess

I use a constructor and start each game with a fresh instance, so I don’t have a reset().

In my case, every method but SetGuess() is const. It happens that SetGuess quietly checks the new guess for being a good isogram at the same time, so the number of tries, returned by GoodTries(), the only other alterable state variable, is only touched there.

That’s very cool. Until I started checking, I didn’t realize that was an invariant of my implementation. I should have realized. The const decoration makes it very clear.

For the record, here is my complete list of const methods. Your mileage will vary:

WordSize()
CurrentGuess()
IsOnlyLetters()
IsCorrectLength()
IsGoodIsogram()
IsSecretGuessed()
Bulls()
Cows()
GoodTries()
SuggestedMaxTries()

This particular class structure was chosen so that the interactions with the player have everything needed to provide error messages and encourage retrying with a repaired guess.

It works well. Now that PlayGame works with all of that, I do need a way to make it not so large and unwieldy with its large variety of different output operations. Something to see how to streamline…

Privacy & Terms