Documentation
¶
Overview ¶
Package minesweeper is a deterministic implementation of the classic game.
Index ¶
- Variables
- type Action
- type ActionKind
- type Board
- type Cell
- type CellSymbol
- type CellView
- type Game
- func (g *Game) Board() *Board
- func (g *Game) Bytes() []byte
- func (g *Game) FlagsPlaced() int
- func (g *Game) Handle(act *Action) error
- func (g *Game) Mines() int
- func (g *Game) Rand() *rand.Rand
- func (g *Game) Render(w io.Writer) (err error)
- func (g *Game) RevealCell(startX, startY int) error
- func (g *Game) Seed() uint64
- func (g *Game) Start(x, y int) error
- func (g *Game) Status() GameStatus
- func (g *Game) String() string
- func (g *Game) ToJSON() ([]byte, error)
- func (g *Game) ToggleFlag(x, y int) error
- func (g *Game) View() GameView
- type GameStatus
- type GameView
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrInvalidSize = errors.New("size must be a positive number") ErrInvalidTotalMines = errors.New("total mines must be a positive number") ErrOutOfBounds = errors.New("coordinates out of bounds") ErrInvalidAction = errors.New("invalid action") ErrInvalidBoard = errors.New("board must be greater than 3x3 and place (NxM)/2 mines") )
Functions ¶
This section is empty.
Types ¶
type Action ¶
type Action struct {
Kind ActionKind
X, Y int
}
func NewAction ¶
func NewAction(kind ActionKind, x, y int) Action
func ParseAction ¶
func ParseActions ¶
type ActionKind ¶
type ActionKind byte
const ( ActionToggleFlag ActionKind = 'F' ActionRevealCell ActionKind = 'C' )
func (ActionKind) String ¶
func (a ActionKind) String() string
type Cell ¶
func (*Cell) ToggleFlag ¶
func (c *Cell) ToggleFlag()
type CellSymbol ¶
type CellSymbol = byte
const ( SymbolUnrevealed CellSymbol = 'o' SymbolEmpty CellSymbol = '_' SymbolFlag CellSymbol = '!' SymbolMine CellSymbol = 'x' SymbolBreakln CellSymbol = '\n' )
type CellView ¶
type CellView struct {
X int `json:"x"`
Y int `json:"y"`
Revealed bool `json:"revealed"`
Flagged bool `json:"flagged"`
// -1 (Game Over)
// 0-8 revealed adjacents value
// 0 unrevealed cell
Value int `json:"value"`
}
func (CellView) MarshalJSON ¶
func (*CellView) UnmarshalJSON ¶
type Game ¶
type Game struct {
// contains filtered or unexported fields
}
func (*Game) FlagsPlaced ¶
func (*Game) RevealCell ¶
func (*Game) Status ¶
func (g *Game) Status() GameStatus
func (*Game) ToggleFlag ¶
type GameStatus ¶
type GameStatus uint8
const ( StatusUnknown GameStatus = iota StatusPlaying StatusLost StatusWon )
func (GameStatus) String ¶
func (gs GameStatus) String() string
Source Files
¶
Click to show internal directories.
Click to hide internal directories.