Class MasterMindSolver

Interactive object which helps you solve a Master Mind puzzle.

Info:

  • Copyright: 2021 Damian Monogue,2008,2009 Konstantinos Asimakis for code used to turn an index number into a guess (indexToGuess method)
  • Author: Damian Monogue

Methods

MasterMindSolver:new(options) Creates a new Master Mind solver
MasterMindSolver:reducePossible(guess, coloredPins, whitePins) Function used to reduce the remaining possible answers, given a guess and the answer to that guess.
MasterMindSolver:checkLastSuggestion(coloredPins, whitePins) Function which assumes you used the last suggested guess from the solver, and reduces the number of possible correct solutions based on the answer given
MasterMindSolver:getValidGuess(useActions) Used to get one of the remaining valid possible guesses


Methods

MasterMindSolver:new(options)
Creates a new Master Mind solver

Parameters:

  • options table table of configuration options for the solver
    option name description default
    places How many spots in the code we're breaking? 4
    items The table of colors/gemstones/whatever which can be part of the code {"red", "orange", "yellow", "green", "blue", "purple"}
    template The string template to use for the guess. Within the template, |t is replaced by the item. Used as the command if autoSend is true "|t"
    autoSend Should we send the guess directly to the server? false
    allowDuplicates Can the same item be used more than once in a code? true
    singleCommand If true, combines the guess into a single command, with each one separated by the separator false
    separator If sending the guess as a single command, what should we put between the guesses to separate them? " "
MasterMindSolver:reducePossible(guess, coloredPins, whitePins)
Function used to reduce the remaining possible answers, given a guess and the answer to that guess. This is not undoable.

Parameters:

  • guess table guess which the answer belongs to. Uses numbers, rather than item names. IE { 1, 1, 2, 2} rather than { "blue", "blue", "green", "green" }
  • coloredPins number how many parts of the guess are both the right color and the right place
  • whitePins number how many parts of the guess are the right color, but in the wrong place

Returns:

    true if you solved the puzzle (coloredPins == number of positions in the code), or false otherwise
MasterMindSolver:checkLastSuggestion(coloredPins, whitePins)
Function which assumes you used the last suggested guess from the solver, and reduces the number of possible correct solutions based on the answer given

Parameters:

  • coloredPins number how many parts of the guess are both the right color and the right place
  • whitePins number how many parts of the guess are the right color, but in the wrong place

Returns:

    true if you solved the puzzle (coloredPins == number of positions in the code), or false otherwise

See also:

MasterMindSolver:getValidGuess(useActions)
Used to get one of the remaining valid possible guesses

Parameters:

  • useActions boolean if true, will return the guess as the commands which would be sent, rather than the numbered items
generated by LDoc 1.4.6 Last updated 2021-08-31 18:42:52