Documentation ¶
Index ¶
- Constants
- func NewErrDifficultyDimension(row, col int) error
- func NewErrDifficultyMineCount(mines int) error
- func OutOfBounds(p Pos, d Difficulty) bool
- type Actions
- type Difficulty
- type ErrDifficultyDimension
- type ErrDifficultyMineCount
- type Field
- type FieldContent
- type Game
- type LocalGame
- func (g *LocalGame) CheckField(p Pos) (*Status, bool)
- func (g *LocalGame) IsReplay() bool
- func (g *LocalGame) Lost() bool
- func (g *LocalGame) OutOfBounds(p Pos) bool
- func (g *LocalGame) Replay()
- func (g *LocalGame) Status() *Status
- func (g *LocalGame) ToSave() (*Save, error)
- func (g *LocalGame) UpdateStatus() *Status
- func (g *LocalGame) Won() bool
- type Pos
- type Save
- type Status
Constants ¶
const ( DifficultyClassic = iota DifficultyBeginner = iota DifficultyIntermediate = iota DifficultyExpert = iota )
const ( DifficultyRowColMin = 8 DifficultyRowColMax = 99 DifficultyMineMin = 9 DifficultyMineMaxPercentage = 0.8 )
const SaveFileExtension = ".sav"
Variables ¶
This section is empty.
Functions ¶
func NewErrDifficultyDimension ¶ added in v0.2.0
func NewErrDifficultyMineCount ¶ added in v0.2.0
func OutOfBounds ¶ added in v0.2.4
func OutOfBounds(p Pos, d Difficulty) bool
Check if a position is out of bounds on the given difficulty
Types ¶
type Difficulty ¶
Represent a difficulty setting for the Game
func Difficulties ¶
func Difficulties() []Difficulty
Exposes pre-defined difficulties in a way that does not allow the original array to be modified
func NewCustomDifficulty ¶ added in v0.2.0
func NewCustomDifficulty(mines, row, col int) (Difficulty, error)
type ErrDifficultyDimension ¶ added in v0.2.0
type ErrDifficultyDimension struct {
// contains filtered or unexported fields
}
func (*ErrDifficultyDimension) Error ¶ added in v0.2.0
func (e *ErrDifficultyDimension) Error() string
type ErrDifficultyMineCount ¶ added in v0.2.0
type ErrDifficultyMineCount struct {
// contains filtered or unexported fields
}
func (*ErrDifficultyMineCount) Error ¶ added in v0.2.0
func (e *ErrDifficultyMineCount) Error() string
type Field ¶
type Field struct { Checked bool Content FieldContent }
Represents a single field in a minefield
type FieldContent ¶
type FieldContent int
Represents the content of a field. Can be a mine, unknown or the number of mines in the neighboring fields
const ( Mine FieldContent = -1 Unknown FieldContent = -2 )
func (FieldContent) String ¶ added in v0.2.3
func (fc FieldContent) String() string
Convert FieldContent to string for logging
type Game ¶
type Game interface { // Check a given field and recursevly reveal all neighboring fields that should be revield. // Returns the resulting new status of the game CheckField(p Pos) (*Status, bool) // Check if the given position is out of bounds OutOfBounds(p Pos) bool // Returns the current status of the game. Only contains the knowledge a player should have. Status() *Status // Check if Game Over Lost() bool // Check if the game is won Won() bool // Reset the current game to be played again Replay() // Check if the game is a replay IsReplay() bool // Generate a save from the game ToSave() (*Save, error) }
Interface for playing the game
type LocalGame ¶ added in v0.2.0
type LocalGame struct { Field [][]Field Difficulty Difficulty // Keep these 2 exported for testing in other packages GameOver bool GameWon bool // contains filtered or unexported fields }
func NewGameSolvable ¶ added in v0.5.0
func NewGameSolvable(d Difficulty, p Pos) *LocalGame
Create a new game that is solvable without random guesses.
func NewGameWithSafeArea ¶ added in v0.2.4
func NewGameWithSafeArea(d Difficulty, p Pos) *LocalGame
Create a new game with mines seeded randomly in the map, with the exception of a 3x3 area around the given position.
func NewGameWithSafePos ¶
func NewGameWithSafePos(d Difficulty, p Pos) *LocalGame
Create a new game with mines seeded randomly in the map, with the exception of the given position.
func (*LocalGame) CheckField ¶ added in v0.2.0
Check a given field and recursevly reveal all neighboring fields that should be revield. Returns the resulting new status of the game and a boolean indicating if there where changes.
func (*LocalGame) OutOfBounds ¶ added in v0.2.0
Check if the given position is out of bounds
func (*LocalGame) Replay ¶ added in v0.2.0
func (g *LocalGame) Replay()
Reset the current game to be played again
func (*LocalGame) Status ¶ added in v0.2.0
Returns the current status of the game. Only contains the knowledge a player should have.
func (*LocalGame) UpdateStatus ¶ added in v0.3.0
Update the status from the current state of the game. Returns status for convenience.
type Pos ¶
type Pos struct {
X, Y int
}
Represent a position in the minefield
func CreateMines ¶
func CreateMines(d Difficulty, safe []Pos) []Pos
Randomly create mines for the given difficulty. Does not create a mine on the given positions.
type Save ¶ added in v0.2.3
type Save struct { // ID is the hash generated from the Data ID string `json:"id"` // Data contains everything necessary to create a game Data saveData `json:"data"` }
type Status ¶
type Status struct { Field [][]Field // contains filtered or unexported fields }
Status contains the current state of the game known to the player. As such it will always be a copy and needs to be it's own type, despite the overlapping similarities. It does not support any of the functions that Game does. It is safe to write to Status, as it is merely a copy.
func (*Status) ObviousMines ¶ added in v0.3.0
Returns the position of all obvious mines
func (*Status) ObviousSafePos ¶ added in v0.3.0
Returns the position of all obvious safe positions