poker

package
v0.0.0-...-910dd66 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: MIT Imports: 9 Imported by: 13

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertPlayerWin

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

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

Types

type CLI

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

CLI helps players through a game of poker.

func NewCLI

func NewCLI(store PlayerStore, in io.Reader) *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, func(), 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 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) *PlayerServer

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 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.

Directories

Path Synopsis
cmd
cli

Jump to

Keyboard shortcuts

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