core

package
v0.0.0-...-d73c5c4 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TelegramChatIDField = "telegram_chat_id"
	ActiveGameField     = "active_game"
	StatisticsField     = "statistics"
	DeckField           = "deck"
)
View Source
const (
	StartCommand       = "start"
	StatsCommand       = "stats"
	NewGameCommand     = "new"
	DrawCardCommand    = "draw"
	StopDrawingCommand = "stop"
)
View Source
const (
	GameDealerField         = "dealer"
	GamePlayersField        = "players"
	GamePlayerUsernameField = "username"
	GamePlayerCardsField    = "cards"
	GamePlayerStopField     = "stop"
	GamePlayerBustedField   = "busted"
)
View Source
const NumOfCardsInDeck = 52

Variables

View Source
var (
	ErrNotFound    = errors.New("404 Not Found")
	ErrServerError = errors.New("500 Server Error")

	ErrChatRegistered = errors.New("chat already registered")
	ErrActiveGame     = errors.New("chat has active game")
	ErrNoActiveGame   = errors.New("chat has no active game")
	ErrDeckEmpty      = errors.New("deck is empty")
	ErrAlreadyStopped = errors.New("you are already stopped drawing")
	ErrBusted         = errors.New("more than 21")
	ErrCantDraw       = errors.New("player can't draw more cards")
)
View Source
var CardSymbols = []string{
	"♣",
	"♦",
	"♥",
	"♠",
}
View Source
var CardValues = map[string]int{
	"A":  1,
	"2":  2,
	"3":  3,
	"4":  4,
	"5":  5,
	"6":  6,
	"7":  7,
	"8":  8,
	"9":  9,
	"10": 10,
	"J":  10,
	"Q":  10,
	"K":  10,
}

Functions

This section is empty.

Types

type Card

type Card string

func (Card) ToString

func (c Card) ToString() string

type Cards

type Cards []Card

func NewCards

func NewCards(numOfDecks int) Cards

func (Cards) CountValue

func (cards Cards) CountValue() int

func (Cards) IsBlackjack

func (cards Cards) IsBlackjack() bool

type Chat

type Chat struct {
	TelegramChatID int64           `bson:"telegram_chat_id"`
	ActiveGame     *Game           `bson:"active_game"`
	Statistics     UsersStatistics `bson:"statistics"`
	Deck           *Deck           `bson:"deck"`
}

type Deck

type Deck struct {
	Cards Cards `bson:"cards"`
	// contains filtered or unexported fields
}

func NewDeck

func NewDeck(numOfDecks int) *Deck

func NewDeckWithCards

func NewDeckWithCards(cards Cards) *Deck

func (*Deck) DrawCard

func (d *Deck) DrawCard() (Card, error)

func (*Deck) IsEmpty

func (d *Deck) IsEmpty() bool

type Game

type Game struct {
	Dealer  Cards    `bson:"dealer"`
	Players []Player `bson:"players"`
}

type Player

type Player struct {
	Username string `bson:"username"`
	Cards    Cards  `bson:"cards"`
	Stop     bool   `bson:"stop"`
	Busted   bool   `bson:"busted"`
}

type SortedUserStatistics

type SortedUserStatistics []userStatistics

type UsersStatistics

type UsersStatistics map[string]int

func (UsersStatistics) SortByValue

func (u UsersStatistics) SortByValue() SortedUserStatistics

Jump to

Keyboard shortcuts

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