...

Package backend

import "github.com/ob-algdatii-ss19/leistungsnachweis-minesweeper/backend"
Overview
Index
Examples

Overview ▾

Constants

Possible actions provided by hint

const (
    NoIdea    string = "no idea"
    SetFlag   string = "flag"
    DoUncover string = "uncover"
)

type API

API is an interface for APIs communicating with the backend.

type API interface {
    HostAPI()
}

func NewGraphQlAPI

func NewGraphQlAPI(field *Playground) (API, error)

NewGraphQlAPI creates a new GraphQLAPI

type Guess

Guess represents the probability that a cell contains a bomb. The Probability should have a value between 0.0 and 1.0.

type Guess struct {
    X           int
    Y           int
    Probability float32
}

type Hint

Hint represents an Action.

type Hint struct {
    X      int
    Y      int
    Action string
}

type Playground

Playground contains the a slice of rows of the field.

type Playground struct {
    Rows []Row
    Win  bool
    // contains filtered or unexported fields
}

Example

Code:

p := NewPlayground()
_ = p.Init(5, 5, 0)
p.placeBomb(3, 3)
p.placeBomb(4, 3)
p.placeBomb(3, 4)
p.Uncover(0, 0)
p.flagsLeft++
p.ToggleFlag(4, 4)
fmt.Println(p.ToString())

Output:

|0|0|0|0|0|
------------
|0|0|0|0|0|
------------
|0|0|1|2|2|
------------
|0|0|2| | |
------------
|0|0|2| |F|
------------

func NewPlayground

func NewPlayground() *Playground

NewPlayground generates a new Playground

func (*Playground) InRange

func (field *Playground) InRange(x, y int) bool

InRange checks whether the given coordinates are inside the playground. If the position is inside the playground true is returned, otherwise false.

func (*Playground) Init

func (field *Playground) Init(sizeX, sizeY, bombs int) error

Init a new playground with the given size. The size of the playground gets passed to the method.

func (*Playground) ToString

func (field *Playground) ToString() string

ToString generates a string representation of the playground.

func (*Playground) ToggleFlag

func (field *Playground) ToggleFlag(x, y int)

ToggleFlag either sets or unsets a flag.

func (*Playground) Uncover

func (field *Playground) Uncover(x, y int)

Uncover uncovers the field at the given position and sets the CloseBombs variable so it gets visible in the UI

type Position

Position contains all required information about the representing position on the playground.

type Position struct {
    Uncovered         bool
    BombBackend       bool
    Bomb              bool
    Flagged           bool
    CloseBombsBackend int
    CloseBombs        int
    // contains filtered or unexported fields
}

type Row

Row contains a slice of positions.

type Row struct {
    Fields []Position
}