model

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2024 License: MIT Imports: 13 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

Functions

This section is empty.

Types

type Answer

type Answer struct {
	Numerical *float64       `firestore:"numerical"`
	Geo       *GeoCoordinate `firestore:"geo"`
}

type Bet

type Bet struct {
	PlayerID string `firestore:"playerId"`
	Amount   int    `firestore:"amount"`
}

type BettingRound

type BettingRound struct {
	QuestionRound *QuestionRound `firestore:"questionRound,omitempty"`
	Bets          []*Bet         `firestore:"bets"`
	CurrentPlayer *Player        `firestore:"currentPlayer"`
}

func (*BettingRound) AddBet

func (b *BettingRound) AddBet(bet *Bet, isBlind bool)

AddBet processes the bet

func (*BettingRound) AmountToCall

func (b *BettingRound) AmountToCall() int

AmountToCall returns the amount to call in the current betting round

func (*BettingRound) IsFinished

func (b *BettingRound) IsFinished() bool

IsFinished returns true if the betting round is over

func (*BettingRound) MoveToNextPlayer

func (b *BettingRound) MoveToNextPlayer()

MoveToNextPlayer sets the current player ID. Warning: It expects the current player to still be in the game!

func (*BettingRound) Start

func (b *BettingRound) Start()

Start sets current player id to next active player of dealer and resets all player states to nil

type BettingStates

type BettingStates string
const (
	BettingStatesChecked BettingStates = "CHECKED"
	BettingStatesCalled  BettingStates = "CALLED"
	BettingStatesRaised  BettingStates = "RAISED"
)

type Game

type Game struct {
	ID             string           `firestore:"id,omitempty"`
	Players        []*Player        `firestore:"players"`
	QuestionRounds []*QuestionRound `firestore:"questionRounds"`
	DealerID       string           `firestore:"dealerId"`
	Questions      []*Question      `firestore:"questions"`
	IsOver         bool             `firestore:"isOver"`
	SetNames       []string         `firestore:"setNames"`
	TTL            time.Time        `firestore:"ttl,omitempty"`
}

func FindGame

func FindGame(ctx context.Context, client *firestore.Client, id string) (*Game, error)

FindGame returns the game with the provided ID

func (*Game) ActionablePlayers

func (g *Game) ActionablePlayers() []*Player

ActionablePlayers returns the players that are in the game, have not folded in current QR and are not all in

func (*Game) ActivePlayers

func (g *Game) ActivePlayers() []*Player

ActivePlayers returns the players that are in the game and have not folded in current QR

func (*Game) AddNewPlayer

func (g *Game) AddNewPlayer(name string) *Player

AddNewPlayer adds a new player

func (*Game) AddNewQuestionRound

func (g *Game) AddNewQuestionRound()

AddNewQuestionRound adds a new question round

func (*Game) BigBlind

func (g *Game) BigBlind() int

BigBlind returns two times the small blind

func (*Game) BigBlindPlayer

func (g *Game) BigBlindPlayer() *Player

BigBlindPlayer returns the dealer player object

func (*Game) CurrentQuestionRound

func (g *Game) CurrentQuestionRound() *QuestionRound

CurrentQuestionRound returns the last element of the game's QuestionRounds slice

func (*Game) Dealer

func (g *Game) Dealer() *Player

Dealer returns the dealer player object

func (*Game) FindPlayer

func (g *Game) FindPlayer(id string) *Player

func (*Game) HasStarted

func (g *Game) HasStarted() bool

HasStarted returns true if there are 1 or more question rounds already

func (*Game) InPlayers

func (g *Game) InPlayers() []*Player

InPlayers returns the players that are not out of the game

func (*Game) IsFinished

func (g *Game) IsFinished() bool

IsFinished returns true if there is only one player left in the game

func (*Game) OutPlayers

func (g *Game) OutPlayers() ([]*Player, []string)

OutPlayers returns the players that are no longer in the game

func (*Game) Participants

func (g *Game) Participants() []string

Participants returns a slice of all player names

func (*Game) PlayerIds

func (g *Game) PlayerIds() []string

PlayerIds returns a slice of all player IDs

func (*Game) RecentQuestionRound

func (g *Game) RecentQuestionRound() *QuestionRound

RecentQuestionRound returns the last played question round If the game is over then this is the same as the current question round

func (*Game) RemovePlayer added in v0.0.4

func (g *Game) RemovePlayer(playerID string)

RemovePlayer adds a new player

func (*Game) Save

func (g *Game) Save(ctx context.Context, client *firestore.Client) error

func (*Game) SmallBlind

func (g *Game) SmallBlind() int

SmallBlind returns the amout of the small blind depending on the env variable and the number of question rounds

func (*Game) SmallBlindPlayer

func (g *Game) SmallBlindPlayer() *Player

SmallBlindPlayer returns the dealer player object

type GeoCoordinate

type GeoCoordinate struct {
	Longitude       float64  `firestore:"longitude"`
	Latitude        float64  `firestore:"latitude"`
	ToleranceRadius *float64 `firestore:"toleranceRadius,omitempty"`
}

type Guess

type Guess struct {
	Guess      *Answer  `firestore:"guess"`
	PlayerID   string   `firestore:"playerId"`
	Difference *float64 `firestore:"difference,omitempty"`
}

func (*Guess) GetGeoDistance

func (g *Guess) GetGeoDistance(a *Answer) float64

GetGeoDistance returns the distance between the geo guess and answer in km

type Player

type Player struct {
	ID           string         `firestore:"id"`
	Money        int            `firestore:"money"`
	Name         string         `firestore:"name"`
	Game         *Game          `firestore:"game,omitempty"`
	IsDead       bool           `firestore:"isDead"`
	BettingState *BettingStates `firestore:"bettingState,omitempty"`
}

func FindPlayer

func FindPlayer(slice []*Player, id string) (player *Player)

FindPlayer finds player by ID in given player slice

func (*Player) FindNextActionablePlayer

func (p *Player) FindNextActionablePlayer() *Player

FindNextActionablePlayer returns the next neighbour that is actionable

func (*Player) FindNextInPlayer

func (p *Player) FindNextInPlayer() *Player

FindNextInPlayer returns the next neighbor that is active

func (*Player) HasFolded

func (p *Player) HasFolded() bool

HasFolded returns true if the player in included in the FoldedPlayerId list of the current QR

func (*Player) IsActionable

func (p *Player) IsActionable() bool

IsActionable returns true if the player can still place bets in current QR

func (*Player) IsActive

func (p *Player) IsActive() bool

IsActive returns true if the player can win money in current QR

func (*Player) IsAllIn

func (p *Player) IsAllIn() bool

IsAllIn returns true if the player has no money left but money in current QR and has not folded

func (*Player) IsOutGame

func (p *Player) IsOutGame() bool

IsOutGame returns true if the player has no more money left and has no chance of winning some in the current question round

func (*Player) MoneyInBettingRound

func (p *Player) MoneyInBettingRound() int

MoneyInBettingRound returns the amount that the player has in the pot of the current betting round

func (*Player) MoneyInQuestionRound

func (p *Player) MoneyInQuestionRound() int

MoneyInQuestionRound returns the amount that the player has in the pot of the current question round

type Question

type Question struct {
	ID                 string        `firestore:"id,omitempty"`
	Type               QuestionTypes `firestore:"type"`
	Question           string        `firestore:"question"`
	Answer             *Answer       `firestore:"answer"`
	Alternatives       []string      `firestore:"alternatives,omitempty"`
	HiddenAlternatives []string      `firestore:"hiddenAlternatives,omitempty"`
	Hints              []string      `firestore:"hints,omitempty"`
	Explanation        *string       `firestore:"explanation,omitempty"`
}

func DrawQuestion

func DrawQuestion(g *Game) *Question

DrawQuestion draws the next Question and removes it from the slice

func (*Question) GetHiddenAlternative

func (q *Question) GetHiddenAlternative() string

GetHiddenAlternative returns one of the incorrect alternatives that is not yet hidden

type QuestionRound

type QuestionRound struct {
	Game              *Game                  `firestore:"game,omitempty"`
	Question          *Question              `firestore:"question"`
	Guesses           []*Guess               `firestore:"guesses"`
	DeadPlayerGuesses []*Guess               `firestore:"deadPlayerGuesses"`
	BettingRounds     []*BettingRound        `firestore:"bettingRounds"`
	FoldedPlayerIds   []string               `firestore:"foldedPlayerIds"`
	IsOver            bool                   `firestore:"isOver"`
	IsShowdown        bool                   `firestore:"isShowdown"`
	Results           []*QuestionRoundResult `firestore:"results"`
	RevealedGuesses   []string               `firestore:"revealedGuesses"`
}

func (*QuestionRound) AddNewBettingRound

func (q *QuestionRound) AddNewBettingRound()

AddNewBettingRound adds a new betting round

func (*QuestionRound) CurrentBettingRound

func (q *QuestionRound) CurrentBettingRound() *BettingRound

CurrentBettingRound returns the last element of the game's QuestionRounds slice

func (*QuestionRound) DistributePot

func (q *QuestionRound) DistributePot()

DistributePot determines winner(s), allocates money accordingly

func (*QuestionRound) Fold

func (q *QuestionRound) Fold(playerID string)

Fold adds a player to the FoldedPlayerId List of the question round

func (*QuestionRound) IsFinished

func (q *QuestionRound) IsFinished() bool

IsFinished returns true if the current betting round is finished and all hints are already revealed or all players are all in or only one player is still active WARNING: this assumes the the current betting round is also finished

func (*QuestionRound) PlaceBlinds

func (q *QuestionRound) PlaceBlinds()

PlaceBlinds places the small and big blind of the QR

func (*QuestionRound) Rank

func (q *QuestionRound) Rank() [][]string

Rank determines who has won the question round

type QuestionRoundResult

type QuestionRoundResult struct {
	PlayerID      string `firestore:"playerId"`
	ChangeInMoney int    `firestore:"changeInMoney"`
}

type QuestionTypes

type QuestionTypes string
const (
	QuestionTypesNumerical      QuestionTypes = "NUMERICAL"
	QuestionTypesMultipleChoice QuestionTypes = "MULTIPLE_CHOICE"
	QuestionTypesDate           QuestionTypes = "DATE"
	QuestionTypesGeo            QuestionTypes = "GEO"
)

Jump to

Keyboard shortcuts

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