game

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package game implements treasure hunting game.

Package game is a generated GoMock package.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrActiveLicenseLimit = errors.New("no more active licenses allowed")
	ErrNoThreasure        = errors.New("no treasure")
	ErrBogusCoin          = errors.New("bogus coin")
	ErrNoSuchLicense      = errors.New("no such license")
	ErrNotDigged          = errors.New("treasure is not digged")
	ErrWrongCoord         = errors.New("wrong coordinates")
	ErrWrongDepth         = errors.New("wrong depth")
)

Errors.

Functions

This section is empty.

Types

type Area

type Area struct {
	X     int // From 0.
	Y     int // From 0.
	SizeX int // From 1.
	SizeY int // From 1.
}

Area describes rectangle.

type Config

type Config struct {
	Seed              int64
	MaxActiveLicenses int
	Density           int // About one treasure per Density cells.
	SizeX             int
	SizeY             int
	Depth             uint8
	TreasureValue     *[]int // Pointer to keep this struct comparable.
	TreasureValueAlg  TreasureValueAlg
}

Config contains game configuration.

type Coord

type Coord struct {
	X     int   // From 0.
	Y     int   // From 0.
	Depth uint8 // From 1.
}

Coord describes single cell.

type Ctx added in v1.0.0

type Ctx = context.Context

type Factory added in v0.3.0

type Factory struct{}

Factory implements app.GameFactory interface.

func (Factory) Continue added in v0.3.0

func (factory Factory) Continue(ctx Ctx, r io.ReadSeeker) (g Game, err error)

Continue implements app.GameFactory interface.

func (Factory) New added in v0.3.0

func (Factory) New(ctx Ctx, cfg Config) (Game, error)

New implements app.GameFactory interface.

type Game

type Game interface {
	// WriteTo saves current game state.
	WriteTo(w io.Writer) (n int64, err error)
	// Balance returns current balance and up to 1000 issued coins.
	Balance() (balance int, wallet []int)
	// Licenses returns all active licenses.
	Licenses() []License
	// IssueLicense creates and returns a new license with given digAllowed.
	// Errors: ErrActiveLicenseLimit, ErrBogusCoin.
	IssueLicense(wallet []int) (License, error)
	// CountTreasures returns amount of not-digged-yet treasures in the area
	// at depth.
	// Errors: ErrWrongCoord, ErrWrongDepth.
	CountTreasures(area Area, depth uint8) (int, error)
	// Dig tries to dig at pos and returns if any treasure was found.
	// The pos depth must be next to current (already digged) one.
	// Also it increment amount of used dig calls in given active license.
	// If amount of used dig calls became equal to amount of allowed dig calls
	// then license will became inactive after the call.
	// Errors: ErrNoSuchLicense, ErrWrongCoord, ErrWrongDepth.
	Dig(licenseID int, pos Coord) (found bool, _ error)
	// Cash returns coins earned for treasure as given pos.
	// Errors: ErrWrongCoord, ErrNotDigged, ErrAlreadyCached.
	Cash(pos Coord) (wallet []int, err error)
}

Game implements treasure hunting game.

type License

type License struct {
	ID         int
	DigAllowed int
	DigUsed    int
}

License defines amount of allowed dig calls.

type MockGame

type MockGame struct {
	// contains filtered or unexported fields
}

MockGame is a mock of Game interface

func NewMockGame

func NewMockGame(ctrl *gomock.Controller) *MockGame

NewMockGame creates a new mock instance

func (*MockGame) Balance

func (m *MockGame) Balance() (int, []int)

Balance mocks base method

func (*MockGame) Cash

func (m *MockGame) Cash(pos Coord) ([]int, error)

Cash mocks base method

func (*MockGame) CountTreasures

func (m *MockGame) CountTreasures(area Area, depth uint8) (int, error)

CountTreasures mocks base method

func (*MockGame) Dig

func (m *MockGame) Dig(licenseID int, pos Coord) (bool, error)

Dig mocks base method

func (*MockGame) EXPECT

func (m *MockGame) EXPECT() *MockGameMockRecorder

EXPECT returns an object that allows the caller to indicate expected use

func (*MockGame) IssueLicense

func (m *MockGame) IssueLicense(wallet []int) (License, error)

IssueLicense mocks base method

func (*MockGame) Licenses

func (m *MockGame) Licenses() []License

Licenses mocks base method

func (*MockGame) WriteTo added in v0.3.0

func (m *MockGame) WriteTo(w io.Writer) (int64, error)

WriteTo mocks base method

type MockGameMockRecorder

type MockGameMockRecorder struct {
	// contains filtered or unexported fields
}

MockGameMockRecorder is the mock recorder for MockGame

func (*MockGameMockRecorder) Balance

func (mr *MockGameMockRecorder) Balance() *gomock.Call

Balance indicates an expected call of Balance

func (*MockGameMockRecorder) Cash

func (mr *MockGameMockRecorder) Cash(pos interface{}) *gomock.Call

Cash indicates an expected call of Cash

func (*MockGameMockRecorder) CountTreasures

func (mr *MockGameMockRecorder) CountTreasures(area, depth interface{}) *gomock.Call

CountTreasures indicates an expected call of CountTreasures

func (*MockGameMockRecorder) Dig

func (mr *MockGameMockRecorder) Dig(licenseID, pos interface{}) *gomock.Call

Dig indicates an expected call of Dig

func (*MockGameMockRecorder) IssueLicense

func (mr *MockGameMockRecorder) IssueLicense(wallet interface{}) *gomock.Call

IssueLicense indicates an expected call of IssueLicense

func (*MockGameMockRecorder) Licenses

func (mr *MockGameMockRecorder) Licenses() *gomock.Call

Licenses indicates an expected call of Licenses

func (*MockGameMockRecorder) WriteTo added in v0.3.0

func (mr *MockGameMockRecorder) WriteTo(w interface{}) *gomock.Call

WriteTo indicates an expected call of WriteTo

type TreasureValueAlg added in v1.0.0

type TreasureValueAlg int

TreasureValueAlg define which algorithm to use for calculating min/max treasure value range at given depth.

const (
	// AlgDoubleMax generates treasure values in range x…x*2
	// where x is Config.TreasureValue[depth].
	AlgDoubleMax TreasureValueAlg = iota + 1
	// AlgQuarterAround generates treasure values in range x*0.75…x*1.25
	// where x is Config.TreasureValue[depth].
	AlgQuarterAround
)

Jump to

Keyboard shortcuts

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