Documentation ¶
Overview ¶
Core logic of solving the mastermind problem with go.
Index ¶
- func CreateColors(length uint8) []uint8
- func DetermineGameState(correntSpots uint8, codeLength uint8, guessLimit uint8, guessIndex uint8) uint8
- func EvaluateGuess(guess []uint8, code []uint8) (uint8, uint8)
- func GameIsFinished(gameStatus uint8) bool
- func GenerateCode(colors []uint8, codeLength uint8) []uint8
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateColors ¶
Creates a list of uint8 that represent the available colors of a single game.
Example ¶
package main import ( "fmt" core "github.com/George-Spanos/mastermind/api/core" ) func main() { colors := core.CreateColors(10) fmt.Println(colors) }
Output: [1 2 3 4 5 6 7 8 9 10]
func DetermineGameState ¶
func DetermineGameState(correntSpots uint8, codeLength uint8, guessLimit uint8, guessIndex uint8) uint8
Returns 0 if game is over and player lost.
Returns 1 if game is over and player won.
Returns 2 if game is not over.
Example ¶
package main import ( "fmt" core "github.com/George-Spanos/mastermind/api/core" ) func main() { state := core.DetermineGameState(5, 5, 8, 8) fmt.Println(state) }
Output: 1
func EvaluateGuess ¶
Given a guess []uint8 and a code, it returns (correntSpots, incorrectSpots) as a pair of uints for the given guess.
Example ¶
package main import ( "fmt" core "github.com/George-Spanos/mastermind/api/core" ) func main() { code := []uint8{1, 3, 3, 4} guess := []uint8{1, 4, 4, 3} correctSpots, incorrectSpots := core.EvaluateGuess(guess, code) fmt.Println(correctSpots) fmt.Println(incorrectSpots) }
Output: 1 2
func GameIsFinished ¶
returns true if gameStatus == 1 or gameStatus == 0
func GenerateCode ¶
Given a list of colors and a length, generates the secret code
Example ¶
package main import ( "fmt" core "github.com/George-Spanos/mastermind/api/core" ) func main() { colors := core.CreateColors(10) code := core.GenerateCode(colors, 4) fmt.Println(len(code)) }
Output: 4
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.