game

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2020 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewGuid

func NewGuid() string

func RandomSuit

func RandomSuit(deck Deck) string

func Run

func Run(configPath string)

func RunTest

func RunTest()

func SetupHTTPServer

func SetupHTTPServer(uiDirectory string, responder Responder)

Types

type Action

type Action struct {
	Name  string
	Apply func() error
}

type Card

type Card struct {
	Suit   string
	Number string
}

func Cards

func Cards(deck Deck) []*Card

func NoShuffle added in v0.3.0

func NoShuffle(cards []*Card) []*Card

func RandomShuffle added in v0.3.0

func RandomShuffle(cards []*Card) []*Card

func Shuffle

func Shuffle(deck Deck) []*Card

func (*Card) Key

func (card *Card) Key() string

type CardBag added in v0.3.0

type CardBag struct {
	Cards map[string]*PlayerCard
}

func NewCardBag added in v0.3.0

func NewCardBag(cards []*Card) *CardBag

type Client

type Client struct {
	Host  string
	Port  int
	Resty *resty.Client
}

func NewClient

func NewClient(host string, port int) *Client

func (*Client) GetModel

func (client *Client) GetModel() (string, error)

func (*Client) GetMyModel

func (client *Client) GetMyModel(me string) (*PlayerModel, error)

type Config

type Config struct {
	LogLevel string

	UIDirectory string

	Port int
}

func GetConfig

func GetConfig(configPath string) (*Config, error)

GetConfig ...

func (*Config) GetLogLevel

func (config *Config) GetLogLevel() (log.Level, error)

GetLogLevel ...

type CurrentHand

type CurrentHand struct {
	Suit       string
	Leader     string
	LeaderCard *Card
	NextPlayer string
}

type Deck

type Deck interface {
	Suits() []string
	Numbers() []string
	CompareNumbers(l string, r string) int
	CompareSuits(l string, r string) int
	Compare(l *Card, r *Card) int
	Shuffle() shuffler
	DeckType() DeckType
	Size() int
}

type DeckType added in v0.3.0

type DeckType string
const (
	// use Custom if your deck isn't one of the predefined types
	DeckTypeCustom                DeckType = "DeckTypeCustom"
	DeckTypeMini                  DeckType = "DeckTypeMini"
	DeckTypeDoubleMini            DeckType = "DeckTypeDoubleMini"
	DeckTypeStandard              DeckType = "DeckTypeStandard"
	DeckTypeDoubleStandard        DeckType = "DeckTypeDoubleStandard"
	DeckTypeDeterministicStandard DeckType = "DeckTypeDeterministicStandard"
)

func (DeckType) JSONString added in v0.3.0

func (d DeckType) JSONString() string

func (DeckType) MarshalJSON added in v0.3.0

func (d DeckType) MarshalJSON() ([]byte, error)

func (DeckType) MarshalText added in v0.3.0

func (d DeckType) MarshalText() (text []byte, err error)

func (*DeckType) UnmarshalJSON added in v0.3.0

func (d *DeckType) UnmarshalJSON(data []byte) error

func (*DeckType) UnmarshalText added in v0.3.0

func (d *DeckType) UnmarshalText(text []byte) (err error)

type DoubleDeck added in v0.3.0

type DoubleDeck struct {
	UnderlyingDeck Deck
	Type           DeckType
}

DoubleDeck can be used for larger games to increase the number of cards. It has two cards for each number/suit, and otherwise works identically to its underlying deck.

func NewDoubleDeck added in v0.3.0

func NewDoubleDeck(underlyingDeck Deck, deckType DeckType) *DoubleDeck

func NewDoubleStandardDeck

func NewDoubleStandardDeck() *DoubleDeck

func (*DoubleDeck) Compare added in v0.3.0

func (dd *DoubleDeck) Compare(l *Card, r *Card) int

func (*DoubleDeck) CompareNumbers added in v0.3.0

func (dd *DoubleDeck) CompareNumbers(l string, r string) int

func (*DoubleDeck) CompareSuits added in v0.3.0

func (dd *DoubleDeck) CompareSuits(l string, r string) int

func (*DoubleDeck) DeckType added in v0.3.0

func (dd *DoubleDeck) DeckType() DeckType

func (*DoubleDeck) Numbers added in v0.3.0

func (dd *DoubleDeck) Numbers() []string

func (*DoubleDeck) Shuffle added in v0.3.0

func (dd *DoubleDeck) Shuffle() shuffler

func (*DoubleDeck) Size added in v0.3.0

func (dd *DoubleDeck) Size() int

func (*DoubleDeck) Suits added in v0.3.0

func (dd *DoubleDeck) Suits() []string

type FinishRoundAction

type FinishRoundAction struct{}

type Game

type Game struct {
	Players        []string
	PlayersSet     map[string]bool
	Deck           Deck
	CardsPerPlayer int
	FinishedRounds []*Round
	CurrentRound   *Round
	State          GameState
}

func NewGame

func NewGame() *Game

type GameConcurrencyWrapper

type GameConcurrencyWrapper struct {
	Game    *Game
	Stop    <-chan struct{}
	Actions chan *Action
}

func NewGameConcurrencyWrapper

func NewGameConcurrencyWrapper(game *Game, stop <-chan struct{}) *GameConcurrencyWrapper

func (*GameConcurrencyWrapper) FinishRound

func (gcw *GameConcurrencyWrapper) FinishRound() error

func (*GameConcurrencyWrapper) GetModel

func (gcw *GameConcurrencyWrapper) GetModel() string

func (*GameConcurrencyWrapper) GetPlayerModel

func (gcw *GameConcurrencyWrapper) GetPlayerModel(player string) *PlayerModel

func (*GameConcurrencyWrapper) Join

func (gcw *GameConcurrencyWrapper) Join(player string) (string, error)

func (*GameConcurrencyWrapper) MakeWager

func (gcw *GameConcurrencyWrapper) MakeWager(player string, hands int) error

func (*GameConcurrencyWrapper) PlayCard

func (gcw *GameConcurrencyWrapper) PlayCard(player string, card *Card) error

func (*GameConcurrencyWrapper) RemovePlayer

func (gcw *GameConcurrencyWrapper) RemovePlayer(player string) error

func (*GameConcurrencyWrapper) SetCardsPerPlayer

func (gcw *GameConcurrencyWrapper) SetCardsPerPlayer(count int) error

func (*GameConcurrencyWrapper) SetDeck

func (gcw *GameConcurrencyWrapper) SetDeck() error

func (*GameConcurrencyWrapper) SetDeckType added in v0.3.0

func (gcw *GameConcurrencyWrapper) SetDeckType(deckType DeckType) error

func (*GameConcurrencyWrapper) StartRound

func (gcw *GameConcurrencyWrapper) StartRound() error

type GameState

type GameState int
const (
	GameStateSetup           GameState = iota
	GameStateRoundInProgress GameState = iota
)

func (GameState) MarshalJSON

func (g GameState) MarshalJSON() ([]byte, error)

func (GameState) MarshalText

func (g GameState) MarshalText() (text []byte, err error)

func (GameState) String

func (g GameState) String() string

type GetPlayerModelAction

type GetPlayerModelAction struct{}

type Hand

type Hand struct {
	Guid         string
	Deck         Deck
	TrumpSuit    string
	CardsPlayed  map[string]*Card
	PlayersOrder []string
	Suit         string
	Leader       string
	LeaderCard   *Card
}

func NewHand

func NewHand(deck Deck, trumpSuit string, playersOrder []string) *Hand

func (*Hand) PlayCard

func (hand *Hand) PlayCard(player string, card *Card)

type JoinAction

type JoinAction struct{}

type MakeWagerAction

type MakeWagerAction struct {
	Hands int
}

type PlayerAction

type PlayerAction struct {
	Me                string
	GetModel          *GetPlayerModelAction
	Join              *JoinAction
	MakeWager         *MakeWagerAction
	PlayCard          *Card
	RemovePlayer      *RemovePlayerAction
	SetCardsPerPlayer *SetCardsPerPlayerAction
	SetDeckType       *SetDeckTypePlayerAction
	StartRound        *StartRoundAction
	FinishRound       *FinishRoundAction
}

type PlayerCard

type PlayerCard struct {
	Card  *Card
	Count int
}

type PlayerGame

type PlayerGame struct {
	Players           []string
	MaxCardsPerPlayer int
	CardsPerPlayer    int
	DeckType          DeckType
}

type PlayerModel

type PlayerModel struct {
	Me      string
	State   PlayerState
	Game    *PlayerGame
	Status  *Status
	MyCards []*Card
}

type PlayerMood

type PlayerMood int
const (
	PlayerMoodNone            PlayerMood = iota
	PlayerMoodLost            PlayerMood = iota
	PlayerMoodLostBadly       PlayerMood = iota
	PlayerMoodLostReallyBadly PlayerMood = iota
	PlayerMoodScared          PlayerMood = iota
	PlayerMoodWinnable        PlayerMood = iota
	PlayerMoodBarelyWinnable  PlayerMood = iota
	PlayerMoodPotato          PlayerMood = iota
	PlayerMoodWon             PlayerMood = iota
)

func (PlayerMood) JSONString

func (p PlayerMood) JSONString() string

func (PlayerMood) MarshalJSON

func (p PlayerMood) MarshalJSON() ([]byte, error)

func (PlayerMood) MarshalText

func (p PlayerMood) MarshalText() (text []byte, err error)

func (*PlayerMood) UnmarshalJSON

func (p *PlayerMood) UnmarshalJSON(data []byte) error

func (*PlayerMood) UnmarshalText

func (p *PlayerMood) UnmarshalText(text []byte) (err error)

type PlayerState

type PlayerState int
const (
	PlayerStateNotJoined         PlayerState = iota
	PlayerStateWaitingForPlayers PlayerState = iota
	PlayerStateWagerTurn         PlayerState = iota
	PlayerStatePlayCardTurn      PlayerState = iota
	PlayerStateRoundFinished     PlayerState = iota
)

func (PlayerState) JSONString

func (p PlayerState) JSONString() string

func (PlayerState) MarshalJSON

func (p PlayerState) MarshalJSON() ([]byte, error)

func (PlayerState) MarshalText

func (p PlayerState) MarshalText() (text []byte, err error)

func (*PlayerState) UnmarshalJSON

func (p *PlayerState) UnmarshalJSON(data []byte) error

func (*PlayerState) UnmarshalText

func (p *PlayerState) UnmarshalText(text []byte) (err error)

type PlayerStatus

type PlayerStatus struct {
	Player           string
	IsMe             bool
	IsNextWagerer    bool
	IsNextPlayer     bool
	IsCurrentLeader  bool
	IsPreviousWinner bool
	Mood             PlayerMood
	Wager            *int
	HandsWon         *int
	PreviousCard     *Card
	CurrentCard      *Card
}

type PreviousHand

type PreviousHand struct {
	Suit   string
	Winner string
}

type RemovePlayerAction

type RemovePlayerAction struct {
	Player string
}

type Responder

type Responder interface {
	GetModel() string
	GetPlayerModel(player string) *PlayerModel
	Join(player string) (string, error)
	RemovePlayer(player string) error
	SetCardsPerPlayer(count int) error
	SetDeckType(deckType DeckType) error
	StartRound() error
	MakeWager(player string, hands int) error
	PlayCard(player string, card *Card) error
	FinishRound() error
}

type Round

type Round struct {
	Guid           string
	CardsPerPlayer int
	Deck           Deck
	// Players are ordered
	PlayersOrder  []string
	PlayerCards   map[string]*CardBag
	TrumpSuit     string
	Wagers        map[string]int
	WagerSum      int
	FinishedHands []*Hand
	CurrentHand   *Hand
	//
	State RoundState
}

func NewRound

func NewRound(players []string, deck Deck, cardsPerPlayer int) *Round

func (*Round) PlayCard

func (round *Round) PlayCard(player string, card *Card) error

func (*Round) Wager

func (round *Round) Wager(player string, hands int) error

type RoundState

type RoundState int
const (
	RoundStateWagers         RoundState = iota
	RoundStateHandInProgress RoundState = iota
	RoundStateFinished       RoundState = iota
)

func (RoundState) MarshalJSON

func (r RoundState) MarshalJSON() ([]byte, error)

func (RoundState) MarshalText

func (r RoundState) MarshalText() (text []byte, err error)

func (RoundState) String

func (r RoundState) String() string

type SetCardsPerPlayerAction

type SetCardsPerPlayerAction struct {
	Count int
}

type SetDeckTypePlayerAction added in v0.3.0

type SetDeckTypePlayerAction struct {
	DeckType DeckType
}

type SimpleDeck added in v0.3.0

type SimpleDeck struct {
	DeckSuits     []string
	SuitRatings   map[string]int
	DeckNumbers   []string
	NumberRatings map[string]int
	Type          DeckType
	// contains filtered or unexported fields
}

func NewDeterministicShuffleDeck

func NewDeterministicShuffleDeck() *SimpleDeck

func NewMiniDeckWithShuffle added in v0.3.0

func NewMiniDeckWithShuffle(shuffle shuffler) *SimpleDeck

func NewSimpleDeck added in v0.3.0

func NewSimpleDeck(numbers []string, suits []string, deckType DeckType, shuffle shuffler) *SimpleDeck

func NewStandardDeck

func NewStandardDeck() *SimpleDeck

func NewStandardDeckWithShuffle added in v0.3.0

func NewStandardDeckWithShuffle(shuffle shuffler) *SimpleDeck

func (*SimpleDeck) Compare added in v0.3.0

func (sd *SimpleDeck) Compare(l *Card, r *Card) int

func (*SimpleDeck) CompareNumbers added in v0.3.0

func (sd *SimpleDeck) CompareNumbers(l string, r string) int

func (*SimpleDeck) CompareSuits added in v0.3.0

func (sd *SimpleDeck) CompareSuits(l string, r string) int

func (*SimpleDeck) DeckType added in v0.3.0

func (sd *SimpleDeck) DeckType() DeckType

func (*SimpleDeck) Numbers added in v0.3.0

func (sd *SimpleDeck) Numbers() []string

func (*SimpleDeck) Shuffle added in v0.3.0

func (sd *SimpleDeck) Shuffle() shuffler

func (*SimpleDeck) Size added in v0.3.0

func (sd *SimpleDeck) Size() int

func (*SimpleDeck) Suits added in v0.3.0

func (sd *SimpleDeck) Suits() []string

type StartRoundAction

type StartRoundAction struct{}

type Status

type Status struct {
	PlayerStatuses  []*PlayerStatus
	TrumpSuit       string
	NextWagerPlayer string
	WagerSum        int
	PreviousHand    *PreviousHand
	CurrentHand     *CurrentHand
}

Jump to

Keyboard shortcuts

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