game

package
v0.0.0-...-0a6770c Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2018 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeActionInformationColor = iota
	TypeActionInformationValue
	TypeActionDiscard
	TypeActionPlaying
)
View Source
const (
	NoneColor = iota
	Red
	Blue
	Green
	Yellow
	Orange
)
View Source
const (
	NoneValue = iota
	One
	Two
	Three
	Four
	Five
)
View Source
const (
	Type_NormalGame = iota
	Type_InfinityGame
)
View Source
const (
	MaxBlueTokens = 8
	MaxRedTokens  = 3
)
View Source
const (
	InfoTypeUsually = iota
	InfoTypeCheat
	InfoTypeFullCheat
)

Variables

View Source
var CardCodes map[HashValue]ColorValue
View Source
var ColorsTable = Colors[1:]
View Source
var Values = []CardValue{
	NoneValue,
	One,
	Two,
	Three,
	Four,
	Five,
}
View Source
var ValuesTable = Values[1:]

Functions

func CardColorToInt

func CardColorToInt(color CardColor) int

func ColorValueByHashColorValue

func ColorValueByHashColorValue(hashValue HashValue) (CardColor, CardValue)

func GetCardColor

func GetCardColor(color CardColor) string

func GetCardUrlByValueAndColor

func GetCardUrlByValueAndColor(color CardColor, value CardValue) string

func GetCardValue

func GetCardValue(value CardValue) string

func GetTableColorOrder

func GetTableColorOrder() map[string]CardColor

func RandomCardsPermutation

func RandomCardsPermutation(cards []*Card)

func RandomIntPermutation

func RandomIntPermutation(values []int)

func RegisterFunction

func RegisterFunction()

func SetMostColourfulPlayerCardsAtZeroPlace

func SetMostColourfulPlayerCardsAtZeroPlace(pcards []*[]Card) [][]Card

Types

type Action

type Action struct {
	ActionType     ActionType `json:"action_type"`
	PlayerPosition int        `json:"player_position"`
	Value          int        `json:"value"`
}

func NewAction

func NewAction(actionType ActionType, playerPosition int, value int) *Action

func (*Action) Copy

func (action *Action) Copy() *Action

func (*Action) Equal

func (a1 *Action) Equal(a2 *Action) bool

func (Action) IsInfoAction

func (action Action) IsInfoAction() bool

func (Action) String

func (action Action) String() string

type ActionType

type ActionType int

type AvailablePlayerGameInfo

type AvailablePlayerGameInfo struct {
	PlayerInfo  *PlayerGameInfo
	Probability float64
}

type AvailablePlayerGameInfos

type AvailablePlayerGameInfos []*AvailablePlayerGameInfo

func (AvailablePlayerGameInfos) NormalizeProbablities

func (availableInfo AvailablePlayerGameInfos) NormalizeProbablities()

func (AvailablePlayerGameInfos) UpdatePlayerInformation

func (availableInfo AvailablePlayerGameInfos) UpdatePlayerInformation(playerInfo *PlayerGameInfo)

type Card

type Card struct {
	Color             CardColor             `json:"color"`
	KnownColor        bool                  `json:"known_color"`
	ProbabilityColors map[CardColor]float64 `json:"probability_colors"`
	Value             CardValue             `json:"value"`
	KnownValue        bool                  `json:"known_value"`
	ProbabilityValues map[CardValue]float64 `json:"probability_values"`
	ProbabilityCard   map[HashValue]float64 `json:"probability_card"`
}

func DereferenceCard

func DereferenceCard(pcards []*Card) []Card

func NewCard

func NewCard(color CardColor, value CardValue, known bool) *Card

func (*Card) ApplyProbabilities

func (card *Card) ApplyProbabilities()

func (*Card) CheckVisible

func (card *Card) CheckVisible()

func (Card) Copy

func (card Card) Copy() Card

func (*Card) EmptyProbabilities

func (card *Card) EmptyProbabilities()

func (*Card) GetColors

func (card *Card) GetColors() map[CardColor]string

func (*Card) GetCriticality

func (card *Card) GetCriticality(progress map[CardColor]CardValue, variants map[ColorValue]int) float64

func (*Card) GetPlayability

func (card *Card) GetPlayability(progress map[CardColor]CardValue) float64

func (*Card) GetPoints

func (card *Card) GetPoints() int

func (*Card) GetValues

func (card *Card) GetValues() map[CardValue]string

func (*Card) IsCardPlayable

func (card *Card) IsCardPlayable(progress map[CardColor]CardValue) bool

func (*Card) IsVisible

func (card *Card) IsVisible() bool

func (*Card) NormalizeProbabilities

func (card *Card) NormalizeProbabilities(color CardColor, value CardValue, countLeft int)

func (*Card) SetColor

func (card *Card) SetColor(color CardColor)

func (*Card) SetKnown

func (card *Card) SetKnown(known bool)

func (*Card) SetValue

func (card *Card) SetValue(value CardValue)

func (Card) String

func (card Card) String() string

func (*Card) UpdateProbability

func (card *Card) UpdateProbability()

type CardColor

type CardColor int

type CardProbs

type CardProbs struct {
	Card  *Card
	Probs []float64
}

type CardValue

type CardValue int

type Cards

type Cards []CardProbs

func (Cards) Len

func (c Cards) Len() int

func (Cards) Swap

func (c Cards) Swap(i, j int)

type ColorValue

type ColorValue struct {
	Color CardColor
	Value CardValue
}

func (ColorValue) String

func (cv ColorValue) String() string

type Game

type Game struct {
	PlayerCount  int        `json:"player_count"`
	InitState    *GameState `json:"init_state"`
	CurrentState *GameState `json:"current_state"`
	Actions      []Action   `json:"actions"`
	Seed         int64      `json:"seed"`
	Points       int        `json:"points"`
	Type         int        `json:"game_type"`
}

func NewGame

func NewGame(originalIds []int, gameType int, seed ...int64) *Game

func (*Game) AppendAction

func (game *Game) AppendAction(action *Action, err error) (*Action, error)

func (*Game) ApplyAction

func (game *Game) ApplyAction(action Action) (err error)

func (*Game) GetPlayerGameInfo

func (game *Game) GetPlayerGameInfo(playerId int, infoType int) PlayerGameInfo

func (*Game) GetPlayerPositionById

func (game *Game) GetPlayerPositionById(id int) (pos int, err error)

func (*Game) GetPoints

func (game *Game) GetPoints() (points int, err error)

func (*Game) IsGameOver

func (game *Game) IsGameOver() bool

func (*Game) NewActionDiscard

func (game *Game) NewActionDiscard(playerPosition int, cardPosition int) (*Action, error)

func (*Game) NewActionInformationColor

func (game *Game) NewActionInformationColor(playerPosition int, cardColor CardColor) (*Action, error)

func (*Game) NewActionInformationValue

func (game *Game) NewActionInformationValue(playerPosition int, cardValue CardValue) (*Action, error)

func (*Game) NewActionPlaying

func (game *Game) NewActionPlaying(playerPosition int, cardPosition int) (*Action, error)

func (*Game) SprintGame

func (game *Game) SprintGame() string

type GameState

type GameState struct {
	Deck            []Card             `json:"deck"`
	Round           int                `json:"round"`
	Step            int                `json:"step"`
	BlueTokens      int                `json:"blue_tokens"`
	RedTokens       int                `json:"red_tokens"`
	CurrentPosition int                `json:"current_pos"`
	UsedCards       []Card             `json:"used_cards"`
	TableCards      map[CardColor]Card `json:"table_cards"`
	PlayerStates    []PlayerState      `json:"player_state"`
	MaxStep         int                `json:"max_step"`
	GameType        int                `json:"game_type"`
}

func NewGameState

func NewGameState(ids []int, gameType int, pcards []*Card) *GameState

func (*GameState) ApplyAction

func (state *GameState) ApplyAction(action *Action) (err error)

func (*GameState) Copy

func (state *GameState) Copy() *GameState

func (*GameState) GetCardCount

func (state *GameState) GetCardCount() int

func (*GameState) GetCardCountByPlayerCount

func (state *GameState) GetCardCountByPlayerCount(count int) int

func (*GameState) GetPlayerGameInfo

func (state *GameState) GetPlayerGameInfo(playerId int, infoType int) PlayerGameInfo

func (*GameState) GetPlayerGameInfoByPos

func (state *GameState) GetPlayerGameInfoByPos(playerPosition int, infoType int) PlayerGameInfo

func (*GameState) GetPlayerPositionById

func (state *GameState) GetPlayerPositionById(id int) (pos int, err error)

func (*GameState) GetPoints

func (state *GameState) GetPoints() (points int, err error)

func (*GameState) IncreaseStep

func (state *GameState) IncreaseStep()

func (*GameState) IsGameOver

func (state *GameState) IsGameOver() bool

func (*GameState) NewAction

func (state *GameState) NewAction(actionType ActionType, playerPosition int, value int) *Action

func (*GameState) NewActionDiscard

func (state *GameState) NewActionDiscard(playerPosition int, cardPosition int) (*Action, error)

func (*GameState) NewActionInformation

func (state *GameState) NewActionInformation(playerPosition int, value int, actionType ActionType, actionFunc func(card *Card, value int)) (*Action, error)

func (*GameState) NewActionInformationColor

func (state *GameState) NewActionInformationColor(playerPosition int, cardColor CardColor) (*Action, error)

func (*GameState) NewActionInformationValue

func (state *GameState) NewActionInformationValue(playerPosition int, cardValue CardValue) (*Action, error)

func (*GameState) NewActionPlaying

func (state *GameState) NewActionPlaying(playerPosition int, cardPosition int) (*Action, error)

func (*GameState) Sprint

func (state *GameState) Sprint() string

type HashValue

type HashValue int

func HashColorValue

func HashColorValue(color CardColor, value CardValue) HashValue

type Pair

type Pair struct {
	Count int
	Index int
}

type Pairs

type Pairs []Pair

func (Pairs) Len

func (pairs Pairs) Len() int

func (Pairs) Less

func (pairs Pairs) Less(i, j int) bool

func (Pairs) Swap

func (pairs Pairs) Swap(i, j int)

type PlayerGameInfo

type PlayerGameInfo struct {
	MyTurn          bool               `json:"my_turn"`
	CurrentPosition int                `json:"current_position"`
	PlayerCount     int                `json:"player_count"`
	Position        int                `json:"pos"`
	Step            int                `json:"step"`
	MaxStep         int                `json:"max_step"`
	Round           int                `json:"round"`
	PlayerId        int                `json:"player_id"`
	DeckSize        int                `json:"deck_size"`
	Deck            []Card             `json:"deck"`
	UsedCards       []Card             `json:"used_cards"`
	TableCards      map[CardColor]Card `json:"table_cards"`
	PlayerCards     [][]Card           `json:"player_cards"`
	PlayerCardsInfo [][]Card           `json:"player_cards_info"`
	BlueTokens      int                `json:"blue_tokens"`
	RedTokens       int                `json:"red_tokens"`
	Points          int                `json:"points"`
	VariantsCount   map[ColorValue]int `json:"-"`
	GameType        int                `json:"game_type"`
	HashKey         *string            `json:"-"`
	InfoIsSetted    bool               `json:"-"`
}

func NewPlayerInfo

func NewPlayerInfo(game *Game, playerId int, infoType int) PlayerGameInfo

func (*PlayerGameInfo) AvailablePlayerInformations

func (info *PlayerGameInfo) AvailablePlayerInformations() []*AvailablePlayerGameInfo

func (*PlayerGameInfo) Copy

func (info *PlayerGameInfo) Copy() *PlayerGameInfo

func (*PlayerGameInfo) GetCardVariants

func (info *PlayerGameInfo) GetCardVariants() []Variants

func (*PlayerGameInfo) GetDefaultDeck

func (info *PlayerGameInfo) GetDefaultDeck() map[ColorValue]int

func (*PlayerGameInfo) GetPlayableCardPositions

func (info *PlayerGameInfo) GetPlayableCardPositions() []int

func (*PlayerGameInfo) GetPoints

func (info *PlayerGameInfo) GetPoints() int

func (*PlayerGameInfo) GetUnplayedCards

func (info *PlayerGameInfo) GetUnplayedCards() map[ColorValue]int

func (*PlayerGameInfo) IncreasePosition

func (info *PlayerGameInfo) IncreasePosition()

func (*PlayerGameInfo) IsCardPlayable

func (info *PlayerGameInfo) IsCardPlayable(card *Card) bool

func (*PlayerGameInfo) IsGameOver

func (info *PlayerGameInfo) IsGameOver() bool

func (*PlayerGameInfo) MoveCardFromDeckToPlayer

func (info *PlayerGameInfo) MoveCardFromDeckToPlayer(playerPosition int)

func (*PlayerGameInfo) PreviewAction

func (info *PlayerGameInfo) PreviewAction(action *Action) (*ResultPreviewPlayerInformations, error)

func (*PlayerGameInfo) PreviewActionDiscard

func (info *PlayerGameInfo) PreviewActionDiscard(cardPosition int) (*ResultPreviewPlayerInformations, error)

func (*PlayerGameInfo) PreviewActionInformationColor

func (info *PlayerGameInfo) PreviewActionInformationColor(playerPosition int, cardColor CardColor, canUnknown ...bool) (*ResultPreviewPlayerInformations, error)

func (*PlayerGameInfo) PreviewActionInformationValue

func (info *PlayerGameInfo) PreviewActionInformationValue(playerPosition int, cardValue CardValue, canUnknown ...bool) (*ResultPreviewPlayerInformations, error)

func (*PlayerGameInfo) PreviewActionPlaying

func (info *PlayerGameInfo) PreviewActionPlaying(cardPosition int) (*ResultPreviewPlayerInformations, error)

func (*PlayerGameInfo) SetCard

func (info *PlayerGameInfo) SetCard(card *Card, cardVariants []Variants) *CardProbs

func (*PlayerGameInfo) SetEasyKnownAboutCards

func (info *PlayerGameInfo) SetEasyKnownAboutCards()

func (*PlayerGameInfo) SetProbabilities

func (info *PlayerGameInfo) SetProbabilities(isCheater, isFullCheater bool)

func (*PlayerGameInfo) SetProbabilities_ConvergenceOfProbability

func (info *PlayerGameInfo) SetProbabilities_ConvergenceOfProbability(cards Cards, variants []Variants)

func (*PlayerGameInfo) SetVariantsCount

func (info *PlayerGameInfo) SetVariantsCount(isCheater, isFullCheater bool)

func (PlayerGameInfo) String

func (info PlayerGameInfo) String() string

type PlayerState

type PlayerState struct {
	PlayerId       int    `json:"player_id"`
	PlayerPosition int    `json:"pos"`
	PlayerCards    []Card `json:"player_cards"`
}

func NewPlayerState

func NewPlayerState(cards [][]Card, playerPosition int, playerId int) *PlayerState

func (*PlayerState) Copy

func (state *PlayerState) Copy() PlayerState

type ResultPlayerInfo

type ResultPlayerInfo struct {
	Probability float64
	Info        *PlayerGameInfo
}

type ResultPreviewPlayerInformations

type ResultPreviewPlayerInformations struct {
	Action  *Action
	Max     int
	Min     int
	Med     float64
	Results []*ResultPlayerInfo
}

type Variants

type Variants struct {
	PCards []*CardProbs
	Color  CardColor
	Value  CardValue
}

Jump to

Keyboard shortcuts

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