entity

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2020 License: AGPL-3.0 Imports: 22 Imported by: 1

Documentation

Index

Constants

View Source
const (
	AudGame   EventAudienceType = "game"
	AudGameTV                   = "gametv"
	AudUser                     = "user"
	AudLobby                    = "lobby"
)
View Source
const (
	KnowledgeMistakeType = "knowledge"
	FindingMistakeType   = "finding"
	VisionMistakeType    = "vision"
	TacticsMistakeType   = "tactics"
	StrategyMistakeType  = "strategy"
	TimeMistakeType      = "time"
	EndgameMistakeType   = "endgame"
)
View Source
const (
	LargeMistakeMagnitude  = "large"
	MediumMistakeMagnitude = "medium"
	SmallMistakeMagnitude  = "small"

	SaddestMistakeMagnitude = "saddest"
	SadderMistakeMagnitude  = "sadder"
	SadMistakeMagnitude     = "sad"

	UnspecifiedMistakeMagnitude = "unspecified"
)
View Source
const (
	ALL_TRIPLE_LETTERS_COVERED_STAT        string = "All Triple Letter Squares Covered"
	ALL_TRIPLE_WORDS_COVERED_STAT          string = "All Triple Word Squares Covered"
	BINGOS_STAT                            string = "Bingos"
	CHALLENGED_PHONIES_STAT                string = "Challenged Phonies"
	CHALLENGES_LOST_STAT                   string = "Challenges Lost"
	CHALLENGES_WON_STAT                    string = "Challenges Won"
	COMMENTS_STAT                          string = "Comments"
	DRAWS_STAT                             string = "Draws"
	EXCHANGES_STAT                         string = "Exchanges"
	FIRSTS_STAT                            string = "Firsts"
	GAMES_STAT                             string = "Games"
	HIGH_GAME_STAT                         string = "High Game"
	HIGH_TURN_STAT                         string = "High Turn"
	LOSSES_STAT                            string = "Losses"
	LOW_GAME_STAT                          string = "Low Game"
	NO_BINGOS_STAT                         string = "Games with no Bingos"
	MANY_DOUBLE_LETTERS_COVERED_STAT       string = "Many Double Letter Squares Covered"
	MANY_DOUBLE_WORDS_COVERED_STAT         string = "Many Double Word Squares Covered"
	MISTAKES_STAT                          string = "Mistakes"
	SCORE_STAT                             string = "Score"
	TILES_PLAYED_STAT                      string = "Tiles Played"
	TIME_STAT                              string = "Time Taken"
	TRIPLE_TRIPLES_STAT                    string = "Triple Triples"
	TURNS_STAT                             string = "Turns"
	TURNS_WITH_BLANK_STAT                  string = "Turns With Blank"
	UNCHALLENGED_PHONIES_STAT              string = "Unchallenged Phonies"
	VALID_PLAYS_THAT_WERE_CHALLENGED_STAT  string = "Valid Plays That Were Challenged"
	VERTICAL_OPENINGS_STAT                 string = "Vertical Openings"
	WINS_STAT                              string = "Wins"
	NO_BLANKS_PLAYED_STAT                  string = "No Blanks Played"
	HIGH_SCORING_STAT                      string = "High Scoring"
	COMBINED_HIGH_SCORING_STAT             string = "Combined High Scoring"
	COMBINED_LOW_SCORING_STAT              string = "Combined Low Scoring"
	ONE_PLAYER_PLAYS_EVERY_POWER_TILE_STAT string = "One Player Plays Every Power Tile"
	ONE_PLAYER_PLAYS_EVERY_E_STAT          string = "One Player Plays Every E"
	MANY_CHALLENGES_STAT                   string = "Many Challenges"
	FOUR_OR_MORE_CONSECUTIVE_BINGOS_STAT   string = "Four or More Consecutive Bingos"
)
View Source
const (
	VarClassic   Variant = "classic"
	VarAWorth100         = "a-is-worth-100"
	VarDogworms          = "dogworms" // OMGWords scrambled = dogworms?
	VarSuper             = "superomg"
)
View Source
const (
	TCRegular    TimeControl = "regular"    // > 14/0
	TCRapid                  = "rapid"      // 6/0 to <= 14/0
	TCBlitz                  = "blitz"      // > 2/0 to < 6/0
	TCUltraBlitz             = "ultrablitz" // 2/0 and under
	TCCorres                 = "corres"
)
View Source
const (
	// Cutoffs in seconds for different time controls.
	CutoffUltraBlitz = 2 * 60
	CutoffBlitz      = 6 * 60
	CutoffRapid      = 14 * 60
)
View Source
const (
	CrosswordGame string = "CrosswordGame"
)
View Source
const (
	// MaxNameLength is the maximum length that a proto message can be.
	MaxNameLength = 64
)
View Source
const MaxNotableInt = 1000000000
View Source
const (
	// SessionExpiration - Expire a session after this much time.
	SessionExpiration = time.Hour * 24 * 30
)
View Source
const TurnsPerGame = 16 // just an estimate.

Calculate "total" time assuming there are 16 turns in a game per player.

Variables

Functions

func DeterministicUsername

func DeterministicUsername(uuid string) string

func RelevantRating

func RelevantRating(ratings Ratings, ratingKey VariantKey) string

RelevantRating returns the rating from a Ratings object given a rating key.

func VariantFromGameReq

func VariantFromGameReq(gamereq *pb.GameRequest) (TimeControl, Variant, error)

Types

type EventAudienceType

type EventAudienceType string

type EventWrapper

type EventWrapper struct {
	Type pb.MessageType
	// The actual event should therefore be a proto object
	Event proto.Message
	// contains filtered or unexported fields
}

An EventWrapper is a real-time update, whether it is a played move, a challenged move, or the game ending, a seek beginning, etc.

func EventFromByteArray

func EventFromByteArray(arr []byte) (*EventWrapper, error)

EventFromByteArray takes in a serialized event and deserializes it.

func WrapEvent

func WrapEvent(event proto.Message, messageType pb.MessageType, gameID string) *EventWrapper

WrapEvent wraps a protobuf event.

func (*EventWrapper) AddAudience

func (e *EventWrapper) AddAudience(audType EventAudienceType, specific string)

AddAudience sets the audience(s) for this event. It is in the form of a NATS channel name. This is not required to be set in order to deliver a message, but certain functions will use it in the gameplay/entity module.

func (*EventWrapper) Audience

func (e *EventWrapper) Audience() []string

Audience gets the audience(s) for this event, in the form of NATS channel names.

func (*EventWrapper) GameID

func (e *EventWrapper) GameID() string

func (*EventWrapper) Serialize

func (e *EventWrapper) Serialize() ([]byte, error)

Serialize serializes the event to a byte array. Our encoding inserts a two byte big-endian number indicating the length of the coming bytes, then a byte representing the message type to the start of the event.

func (*EventWrapper) SetSerializationProtocol

func (e *EventWrapper) SetSerializationProtocol(protocol string)

SetSerializationProtocol sets the serialization protocol of the protobuf object.

type Game

type Game struct {
	sync.Mutex
	game.Game

	PlayerDBIDs [2]uint
	GameReq     *pb.GameRequest
	// started is set when the game actually starts (when the game timers start).
	// Note that the internal game.Game may have started a few seconds before,
	// but there should be no information about it given until _this_ started
	// is true.
	Started bool
	Timers  Timers

	GameEndReason pb.GameEndReason
	// if 0 or 1, that player won
	// if -1, it was a tie!
	WinnerIdx int
	LoserIdx  int

	Stats *Stats

	ChangeHook chan<- *EventWrapper
}

A Game should be saved to the database or store. It wraps a macondo.Game, and we should save most of the included fields here, especially the macondo.game.History (which can be exported as GCG, etc in the future)

func NewGame

func NewGame(mcg *game.Game, req *pb.GameRequest) *Game

NewGame takes in a Macondo game that was just "started". Note that Macondo games when they start do not log any time, they just deal tiles. The time of start must be logged later, when both players are in the table and ready.

func (*Game) CachedTimeRemaining

func (g *Game) CachedTimeRemaining(idx int) int

func (*Game) ChallengeRule

func (g *Game) ChallengeRule() macondopb.ChallengeRule

func (*Game) CreationRequest

func (g *Game) CreationRequest() *pb.GameRequest

func (*Game) GameID

func (g *Game) GameID() string

func (*Game) GetWinnerIdx

func (g *Game) GetWinnerIdx() int

func (*Game) HistoryRefresherEvent

func (g *Game) HistoryRefresherEvent() *pb.GameHistoryRefresher

Return a HistoryRefresherEvent for the given user ID. If sanitize is true, opponent racks are stripped.

func (*Game) RatingKey

func (g *Game) RatingKey() (VariantKey, error)

func (*Game) RatingMode

func (g *Game) RatingMode() pb.RatingMode

func (*Game) RecordTimeOfMove

func (g *Game) RecordTimeOfMove(idx int)

func (*Game) RegisterChangeHook

func (g *Game) RegisterChangeHook(eventChan chan<- *EventWrapper) error

RegisterChangeHook registers a channel with the game. Events will be sent down this channel.

func (*Game) ResetTimersAndStart

func (g *Game) ResetTimersAndStart()

Reset timers to _now_. The game is actually starting.

func (*Game) SendChange

func (g *Game) SendChange(e *EventWrapper)

SendChange sends an event via the registered hook.

func (*Game) SetGameEndReason

func (g *Game) SetGameEndReason(r pb.GameEndReason)

func (*Game) SetLoserIdx

func (g *Game) SetLoserIdx(pidx int)

func (*Game) SetWinnerIdx

func (g *Game) SetWinnerIdx(pidx int)

func (*Game) TimeRanOut

func (g *Game) TimeRanOut(idx int) bool

TimeRanOut calculates if time ran out for the given player. Assumes player is on turn, otherwise it always returns false.

func (*Game) TimeRemaining

func (g *Game) TimeRemaining(idx int) int

TimeRemaining calculates the time remaining, but does NOT update it.

func (*Game) TimeStarted

func (g *Game) TimeStarted() int64

func (*Game) WinnerWasSet

func (g *Game) WinnerWasSet() bool

type IncrementInfo

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

type IncrementType

type IncrementType int
const (
	EventType IncrementType = iota
	GameType
	FinalType
)

type ListItem

type ListItem struct {
	Word        string `json:"w"`
	Probability int    `json:"p"`
	Score       int    `json:"s"`
	GameId      string `json:"g"`
}

type MistakeMagnitude

type MistakeMagnitude string

type MistakeType

type MistakeType string

type PoolMember

type PoolMember struct {
	Id          int
	Rating      int
	RatingRange [2]int
	Blocking    []int
	Misses      int
}

func NewPoolMember

func NewPoolMember(id int, rating int, minimumRating int, maximumRating int, blocking []int) *PoolMember

type Profile

type Profile struct {
	FirstName   string
	LastName    string
	CountryCode string
	Title       string
	About       string
	Ratings     Ratings
	Stats       ProfileStats
}

Profile is a user profile. It might not be defined for anonymous users.

type ProfileStats

type ProfileStats struct {
	Data map[VariantKey]*Stats
}

type Ratings

type Ratings struct {
	Data map[VariantKey]SingleRating
}

Ratings gets stored into a PostgreSQL database.

type Session

type Session struct {
	ID       string
	Username string
	UserUUID string
}

Session - The db specific-details are in the store package.

type SingleRating

type SingleRating struct {
	Rating          float64 `json:"r"`
	RatingDeviation float64 `json:"rd"`
	Volatility      float64 `json:"v"`
	// This is the last game timestamp for this user for THIS variant:
	LastGameTimestamp int64 `json:"ts"`
}

SingleRating encodes a whole Glicko-225 rating object.

type SoughtGame

type SoughtGame struct {
	// A sought game has either of these two fields set
	SeekRequest  *pb.SeekRequest
	MatchRequest *pb.MatchRequest
}

func NewMatchRequest

func NewMatchRequest(matchRequest *pb.MatchRequest) *SoughtGame

func NewSoughtGame

func NewSoughtGame(seekRequest *pb.SeekRequest) *SoughtGame

func (*SoughtGame) ID

func (sg *SoughtGame) ID() string

func (*SoughtGame) Seeker

func (sg *SoughtGame) Seeker() string

func (*SoughtGame) Type

func (sg *SoughtGame) Type() SoughtGameType

type SoughtGameType

type SoughtGameType int
const (
	TypeSeek SoughtGameType = iota
	TypeMatch
	TypeNone
)

type StatItem

type StatItem struct {
	Minimum       int                        `json:"-"`
	Maximum       int                        `json:"-"`
	Total         int                        `json:"t"`
	DataType      StatItemType               `json:"-"`
	IncrementType IncrementType              `json:"-"`
	List          []*ListItem                `json:"l"`
	Subitems      map[string]int             `json:"s"`
	AddFunction   func(*IncrementInfo) error `json:"-"`
}

type StatItemType

type StatItemType int
const (
	SingleType StatItemType = iota
	ListType
	MinimumType
	MaximumType
)

type Stats

type Stats struct {
	PlayerOneId   string               `json:"i1"`
	PlayerTwoId   string               `json:"i2"`
	PlayerOneData map[string]*StatItem `json:"d1"`
	PlayerTwoData map[string]*StatItem `json:"d2"`
	NotableData   map[string]*StatItem `json:"n"`
}

func InstantiateNewStats

func InstantiateNewStats(playerOneId string, playerTwoId string) *Stats

InstantiateNewStats instantiates a new stats object. playerOneId MUST have gone first in the game.

func (*Stats) AddGame

func (stats *Stats) AddGame(history *pb.GameHistory, req *realtime.GameRequest, cfg *macondoconfig.Config, id string) error

func (*Stats) AddStats

func (stats *Stats) AddStats(otherStats *Stats) error

func (*Stats) Finalize

func (stats *Stats) Finalize()

type TimeControl

type TimeControl string

type Timers

type Timers struct {
	// TimeOfLastUpdate is the timestamp of the last update, in milliseconds.
	// If no update has been made, this defaults to timeStarted.
	TimeOfLastUpdate int64 `json:"lu"`
	// TimeStarted is a unix timestamp, in milliseconds.
	TimeStarted int64 `json:"ts"`
	// TimeRemaining is an array of remaining time per player, in milliseconds.
	TimeRemaining []int `json:"tr"`
	// MaxOvertime is in minutes. All others are in milliseconds.
	MaxOvertime int `json:"mo"`
}

type User

type User struct {
	Anonymous bool
	// ID is the database ID. Since this increases monotonically, we should
	// not expose it to the user
	ID uint
	// UUID is the "user-exposed" ID, in any APIs.
	UUID     string
	Username string
	Password string
	Email    string
	Profile  *Profile
	// CurrentChannel tracks presence; where is the user currently?
	CurrentChannel string
}

User - the db-specific details are in the store package.

func (*User) GetRating

func (u *User) GetRating(ratingKey VariantKey) (*SingleRating, error)

GetRating gets a full Glicko-225 rating for this user, based on the passed-in rating key.

func (*User) GetRelevantRating

func (u *User) GetRelevantRating(ratingKey VariantKey) string

GetRelevantRating gets a displayable rating for this user, based on the passed-in rating key (encoding variant, time control, etc)

func (*User) RealName

func (u *User) RealName() string

RealName returns a user's real name, or an empty string if anonymous.

type Variant

type Variant string

type VariantKey

type VariantKey string

func ToVariantKey

func ToVariantKey(lexiconName string, variantName Variant, timeControl TimeControl) VariantKey

Jump to

Keyboard shortcuts

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