core

package
v1.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Core logic of solving the mastermind problem with go.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateColors

func CreateColors(length uint8) []uint8

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

func EvaluateGuess(guess []uint8, code []uint8) (uint8, uint8)

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

func GameIsFinished(gameStatus uint8) bool

returns true if gameStatus == 1 or gameStatus == 0

func GenerateCode

func GenerateCode(colors []uint8, codeLength uint8) []uint8

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL