<abstract> new Game()
Members
-
<static> NUM_CHOICES :number
-
Type:
- number
-
<static> NUM_GUESSES :number
-
Type:
- number
-
<static> SECRET_LENGTH :number
-
Type:
- number
-
numChoices :number
-
Type:
- number
-
numGuesses :number
-
Type:
- number
-
secretLength :number
-
Type:
- number
Methods
-
evaluateGuess(guess)
-
Evaluate a guess against the secret sequence, returning an object with two properties:
correctPosition
: the number of numbers that have both the correct value and correct position.correctNumber
: the number of numbers that have the correct value but wrong position.
For example, if the secret were [2, 1, 2, 2] and you guessed [1, 2, 3, 2] the response would be
{ correctPosition: 1, correctNumber: 2 }
.Parameters:
Name Type Description guess
Array A guess at the secret sequence.
Returns:
Response to the guess:
{ correctPosition: Number, correctNumber: Number }
- Type
- Object
Example
var secret = [2, 1, 2, 2] var guess = [1, 2, 3, 2] var game = new Game({ secret: secret }) var response = game.evaluateGuess(guess) // response.correctPosition = 1 // response.correctNumber = 2
-
isGuessCorrect(guess)
-
Returns whether the guess matches the secret sequence.
Parameters:
Name Type Description guess
Array A guess at the secret sequence.
Returns:
Whether the guess matches the secret sequence (
true
) or not (false
).- Type
- Boolean
-
makeSecret(numChoices, secretLength)
-
Generate a secret sequence of length
secretLength
composed of integers between 1 andnumChoices
.Parameters:
Name Type Description numChoices
Number The maximum value for elements of the secret sequence.
secretLength
Number The length of the secret to be generated.
Returns:
A secret sequence!
- Type
- Array
-
<abstract> play()
-
Play the game! Sub-classes must implement this method, or they won't know how to play the game!
Returns:
An error! This method must be implemented by a sub-class.
- Type
- Error