set

package
v0.0.0-...-04ace94 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SetLen       = 3
	NAxes        = 4
	FullDeckLen  = 81
	InitBoardLen = 12
)

Variables

This section is empty.

Functions

func IsSet

func IsSet(cs CardTriple) bool

IsSet returns true if the given cards are a set, false otherwise

Types

type Board

type Board []*Card

Board is a layout of cards

func (Board) FindCard

func (b Board) FindCard(c Card) int

FindCard returns the index of the given card on the Board or -1 if not found

func (Board) FindSet

func (b Board) FindSet(set bool) *CardTriple

FindSet returns a set or non-set from the given board or nil if there are none

type Card

type Card struct {
	Color   Color   `json:"color"`
	Count   byte    `json:"count"`
	Shading Shading `json:"shading"`
	Shape   Shape   `json:"shape"`
}

Card is a set game card

func CardBase3ToCard

func CardBase3ToCard(cb3 CardBase3) *Card

CardBase3ToCard returns the Card for the given CardBase3

func (Card) MarshalJSON

func (c Card) MarshalJSON() ([]byte, error)

func (*Card) String

func (c *Card) String() string

func (*Card) UnmarshalJSON

func (c *Card) UnmarshalJSON(b []byte) error

type CardBase3

type CardBase3 int

CardBase3 is representation of a card as a 4-digit, base-3 integer

func CardToCardBase3

func CardToCardBase3(c *Card) CardBase3

CardToCardBase3 returns the CardBase3 for the given Card

type CardTriple

type CardTriple [SetLen]Card

CardTriple set of three cards that are a Potential Set

type Color

type Color byte
const (
	Green Color = iota
	Purple
	Red
)

func (Color) String

func (i Color) String() string

type Deck

type Deck []*Card

Deck is a deck of set Set cards

func (*Deck) Pop

func (d *Deck) Pop() *Card

Pop removes and returns to top of the deck

type Game

type Game struct {
	ID              uuid.UUID          `json:"id"`
	Players         map[string]*Player `json:"players"`
	Deck            Deck               `json:"deck"`
	Board           Board              `json:"board"`
	ClaimedSet      CardTriple         `json:"claimedSet"`
	ClaimedUsername string             `json:"claimedUsername"`
}

Game is an instance of a set game

func NewGame

func NewGame(usernames ...string) (*Game, error)

func (*Game) ClaimSet

func (g *Game) ClaimSet(username string, cs CardTriple) error

ClaimSet validates and processes a set claim from a player.

If a set has already been claimed for this round, an InvalidMethodError() is returned.

If the given username is not a player in the Game, an InvalidArgError(Arg="username") is returned.

If the given cards are not a set or not present in the deck, nil is returned and (per game rules) the most recent set in the player's collection is returned to the Deck. NOTE: we need to add Game.logicalTime to avoid race where set was valid for an earlier logicalTime (should fail but not penalize)

If the given set is valid and the cards are all still present on the board, the given set is copied to the Game's ClaimedSet (so that it can be displayed prior to the next round) and is added to the given player's collection and nil is returned.

func (*Game) Expand

func (g *Game) Expand() error

Expand adds the next Card triplet when no players can find a set. Only valid in playing state.

func (*Game) FindExpandSet

func (g *Game) FindExpandSet() *CardTriple

FindExpandSet return a set on the board, expanding until one is found or the game's deck is exhausted

func (*Game) GetState

func (g *Game) GetState() State

func (*Game) NextRound

func (g *Game) NextRound() error

NextRound transitions a game in Claimed Set state to the next round

type InvalidArgError

type InvalidArgError struct {
	Arg   string
	Value string
}

InvalidArgError indicates an argument is invalid

func (InvalidArgError) Error

func (e InvalidArgError) Error() string

type InvalidStateError

type InvalidStateError struct {
	Method  string
	Details string
}

InvalidStateError indicates the Method was called for an object that is not in the right state for it

func (InvalidStateError) Error

func (e InvalidStateError) Error() string

type Player

type Player struct {
	Username string       `json:"username"`
	Sets     []CardTriple `json:"sets"`
}

Player is a participant in a set game

type Shading

type Shading byte
const (
	Filled Shading = iota
	Outline
	Stripe
)

func (Shading) String

func (i Shading) String() string

type Shape

type Shape byte
const (
	Diamond Shape = iota
	Oval
	Squiggle
)

func (Shape) String

func (i Shape) String() string

type State

type State byte
const (
	Playing State = iota
	SetClaimed
)

Jump to

Keyboard shortcuts

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