poker

package
v0.0.0-...-cdffa6e Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2022 License: MIT Imports: 15 Imported by: 1

Documentation

Index

Constants

View Source
const BadPlayerInputErrMsg = "Bad value received for number of players, please try again with a number"

BadPlayerInputErrMsg is the text telling the user they did bad things

View Source
const BadWinnerInputMsg = "invalid winner input, expect format of 'PlayerName wins'"

BadWinnerInputMsg is the text telling the user they declared the winner wrong

View Source
const PlayerPrompt = "Please enter the number of players: "

PlayerPrompt is the text asking the user for the number of players

Variables

This section is empty.

Functions

func Alerter

func Alerter(duration time.Duration, amount int, to io.Writer)

StdOutAlerter will schedule alerts and print them to os.Stdout

func AssertPlayerWin

func AssertPlayerWin(t *testing.T, store *StubPlayerStore, winner string)

AssertPlayerWin allows you to spy on the store's calls to RecordWin

Types

type BlindAlerter

type BlindAlerter interface {
	ScheduleAlertAt(duration time.Duration, amount int, to io.Writer)
}

BlindAlerter schedules alerts for blind amounts

type BlindAlerterFunc

type BlindAlerterFunc func(duration time.Duration, amount int, to io.Writer)

BlindAlerterFunc allows you to implement BlindAlerter with a function

func (BlindAlerterFunc) ScheduleAlertAt

func (a BlindAlerterFunc) ScheduleAlertAt(duration time.Duration, amount int, to io.Writer)

ScheduleAlertAt is BlindAlerterFunc implementation of BlindAlerter

type CLI

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

CLI helps players through a game of poker

func NewCLI

func NewCLI(in io.Reader, out io.Writer, game Game) *CLI

NewCLI creates a CLI for playing poker

func (*CLI) PlayPoker

func (cli *CLI) PlayPoker()

PlayPoker starts the game

type FileSystemPlayerStore

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

FileSystemPlayerStore stores players in the filesystem

func FileSystemPlayerStoreFromFile

func FileSystemPlayerStoreFromFile(path string) (*FileSystemPlayerStore, error)

FileSystemPlayerStoreFromFile creates a PlayerStore from the contents of a JSON file found at path

func NewFileSystemPlayerStore

func NewFileSystemPlayerStore(file *os.File) (*FileSystemPlayerStore, error)

NewFileSystemPlayerStore creates a FileSystemPlayerStore initialising the store if needed

func (*FileSystemPlayerStore) GetLeague

func (f *FileSystemPlayerStore) GetLeague() League

GetLeague returns the Scores of all the players

func (*FileSystemPlayerStore) GetPlayerScore

func (f *FileSystemPlayerStore) GetPlayerScore(name string) int

GetPlayerScore retrieves a player's score

func (*FileSystemPlayerStore) RecordWin

func (f *FileSystemPlayerStore) RecordWin(name string)

RecordWin will store a win for a player, incrementing wins if already known

type Game

type Game interface {
	Start(numberOfPlayers int, alertsDestination io.Writer)
	Finish(winner string)
}

Game manages the state of a game

type League

type League []Player

League stores a collection of players

func NewLeague

func NewLeague(rdr io.Reader) (League, error)

NewLeague creates a League from JSON

func (League) Find

func (l League) Find(name string) *Player

Find tries to return a player from a League

type Player

type Player struct {
	Name string
	Wins int
}

Player stores a name with a number of wins

type PlayerServer

type PlayerServer struct {
	http.Handler
	// contains filtered or unexported fields
}

PlayerServer is a HTTP interface for player information

func NewPlayerServer

func NewPlayerServer(store PlayerStore, game Game) (*PlayerServer, error)

NewPlayerServer creates a PlayerServer with routing configured

type PlayerStore

type PlayerStore interface {
	GetPlayerScore(name string) int
	RecordWin(name string)
	GetLeague() League
}

PlayerStore stores score information about players

type ScheduledAlert

type ScheduledAlert struct {
	At     time.Duration
	Amount int
}

ScheduledAlert holds information about when an alert is scheduled

func (ScheduledAlert) String

func (s ScheduledAlert) String() string

type SpyBlindAlerter

type SpyBlindAlerter struct {
	Alerts []ScheduledAlert
}

SpyBlindAlerter allows you to spy on ScheduleAlertAt calls

func (*SpyBlindAlerter) ScheduleAlertAt

func (s *SpyBlindAlerter) ScheduleAlertAt(at time.Duration, amount int, io io.Writer)

ScheduleAlertAt records alerts that have been scheduled

type StubPlayerStore

type StubPlayerStore struct {
	Scores   map[string]int
	WinCalls []string
	League   []Player
}

StubPlayerStore implements PlayerStore for testing purposes

func (*StubPlayerStore) GetLeague

func (s *StubPlayerStore) GetLeague() League

GetLeague returns League

func (*StubPlayerStore) GetPlayerScore

func (s *StubPlayerStore) GetPlayerScore(name string) int

GetPlayerScore returns a score from Scores

func (*StubPlayerStore) RecordWin

func (s *StubPlayerStore) RecordWin(name string)

RecordWin will record a win to WinCalls

type TexasHoldem

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

TexasHoldem manages a game of poker

func NewTexasHoldem

func NewTexasHoldem(alerter BlindAlerter, store PlayerStore) *TexasHoldem

NewTexasHoldem returns a new game

func (*TexasHoldem) Finish

func (p *TexasHoldem) Finish(winner string)

Finish ends the game, recording the winner

func (*TexasHoldem) Start

func (p *TexasHoldem) Start(numberOfPlayers int, alertsDestination io.Writer)

Start will schedule blind alerts dependant on the number of players

Directories

Path Synopsis
cmd
cli

Jump to

Keyboard shortcuts

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