utils

package
v0.0.0-...-d26b62e Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SearchByID

func SearchByID(list []models.Player, id string) (*models.Player, int, error)

func SelectRandom

func SelectRandom(cards [52]models.Card, selected int) (models.Card, int)

SelectRandom randomly selects a card from the stack and returns a copy of it

func SelectRandomN

func SelectRandomN(s int) (int, int)

func SendToAll

func SendToAll(players []models.Player, event *models.Event)

SendToAll is a utility for sending an event (message) to an entire array (lobby) of players.

func SendToChanTimeout

func SendToChanTimeout(out chan []byte, event *models.Event) error

func SendToChanTimeoutD

func SendToChanTimeoutD(out chan []byte, event *models.Event, d time.Duration) error

func SendToPlayerInListTimeout

func SendToPlayerInListTimeout(players []models.Player, i int, event *models.Event) error

SendToPlayerInList is a utility for sending an event (message) to a specific player in a slice

func SendToPlayerTimeout

func SendToPlayerTimeout(player *models.Player, event *models.Event) error

SendToPlayer is a utility for sending an event (message) to a given player

func WaitUntilCloseOrEvent

func WaitUntilCloseOrEvent(player *models.Player) (*models.Event, error)

WaitUntilEvent waits for a player event before a timeout succeeds.

func WaitUntilCloseOrEventD

func WaitUntilCloseOrEventD(in chan *models.Event, close chan bool, d time.Duration) (*models.Event, error)

WaitUntilEventD waits for a player event before a given timeout duration succeeds.

func WaitUntilEventD

func WaitUntilEventD(in chan *models.Event, d time.Duration) (*models.Event, error)

WaitUntilEventD waits for a player event before a given timeout duration succeeds.

Types

type CardGenerator

type CardGenerator struct {
	Cards         [52]models.Card
	SelectedCards int
}

CardGenerator is a utility for randomly choose a multiple cards out of a 52 card deck

func NewCardSelector

func NewCardSelector() *CardGenerator

NewCardSelector creates a new card select

func (*CardGenerator) Reset

func (s *CardGenerator) Reset()

Reset resets the card stack and therefore the probabilities

func (*CardGenerator) Select

func (s *CardGenerator) Select(n int) []models.Card

func (*CardGenerator) SelectRandom

func (s *CardGenerator) SelectRandom() (c models.Card)

SelectRandom randomly selects a card from the stack and returns a copy of it

type PlayerQueue

type PlayerQueue struct {
	Queue    []*models.Player
	Register map[string]string
}

func (*PlayerQueue) Dequeue

func (p *PlayerQueue) Dequeue() (*models.Player, string)

func (*PlayerQueue) Enqueue

func (p *PlayerQueue) Enqueue(player *models.Player, id string)

Jump to

Keyboard shortcuts

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