Documentation ¶
Index ¶
Constants ¶
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 ¶
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 ¶
CardBase3ToCard returns the Card for the given CardBase3
func (Card) MarshalJSON ¶
func (*Card) UnmarshalJSON ¶
type CardBase3 ¶
type CardBase3 int
CardBase3 is representation of a card as a 4-digit, base-3 integer
func CardToCardBase3 ¶
CardToCardBase3 returns the CardBase3 for the given Card
type CardTriple ¶
CardTriple set of three cards that are a Potential Set
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 (*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 ¶
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
type InvalidArgError ¶
InvalidArgError indicates an argument is invalid
func (InvalidArgError) Error ¶
func (e InvalidArgError) Error() string
type InvalidStateError ¶
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