Documentation ¶
Index ¶
- Constants
- Variables
- type Action
- type ActionType
- type Card
- type CardType
- type Deck
- type Game
- type GameMode
- type History
- type MockAction
- type MockCard
- type MockDeck
- type MockGame
- func (_m *MockGame) Completed() bool
- func (_m *MockGame) Copy() Game
- func (_m *MockGame) CreatePlayerView(color PlayerColor) (PlayerView, error)
- func (_m *MockGame) Deck() Deck
- func (_m *MockGame) History() []History
- func (_m *MockGame) PlayerCount() int
- func (_m *MockGame) Players() map[PlayerColor]Player
- func (_m *MockGame) Started() bool
- func (_m *MockGame) Track(action string, player Player, card Card)
- func (_m *MockGame) Winner() *Player
- type MockHistory
- type MockMove
- type MockPawn
- type MockPlayer
- func (_m *MockPlayer) AllPawnsInHome() bool
- func (_m *MockPlayer) AppendToHand(card Card)
- func (_m *MockPlayer) Color() PlayerColor
- func (_m *MockPlayer) Copy() Player
- func (_m *MockPlayer) FindFirstPawnInStart() *Pawn
- func (_m *MockPlayer) Hand() []Card
- func (_m *MockPlayer) IncrementTurns()
- func (_m *MockPlayer) Pawns() []Pawn
- func (_m *MockPlayer) PublicData() Player
- func (_m *MockPlayer) RemoveFromHand(card Card)
- func (_m *MockPlayer) Turns() int
- type MockPlayerView
- type MockPosition
- func (_m *MockPosition) Copy() Position
- func (_m *MockPosition) Home() bool
- func (_m *MockPosition) MoveToHome() error
- func (_m *MockPosition) MoveToPosition(position Position) error
- func (_m *MockPosition) MoveToSafe(safe int) error
- func (_m *MockPosition) MoveToSquare(square int) error
- func (_m *MockPosition) MoveToStart() error
- func (_m *MockPosition) Safe() *int
- func (_m *MockPosition) Square() *int
- func (_m *MockPosition) Start() bool
- type MockSlide
- type Move
- type Pawn
- type Player
- type PlayerColor
- type PlayerView
- type Position
- type Slide
Constants ¶
const AdultHand = 5
AdultHand for an adult-mode game, we deal out 5 cards
const BoardSquares = 60
BoardSquares there are 60 squares around the outside of the board, numbered 0-59
const MaxPlayers = 4
MaxPlayers a game consists of no more than 4 players
const MinPlayers = 2
MinPlayers a game consists of at least 2 players
const Pawns = 4
Pawns there are 4 pawns per player, numbered 0-3
const SafeSquares = 5
SafeSquares there are 5 safe squares for each color, numbered 0-4
Variables ¶
var ( CardTypes = enum.NewValues[CardType](Card1, Card2, Card3, Card4, Card5, Card7, Card8, Card10, Card11, Card12, CardApologies) Card1 = CardType{"1"} Card2 = CardType{"2"} Card3 = CardType{"3"} Card4 = CardType{"4"} Card5 = CardType{"5"} Card7 = CardType{"7"} Card8 = CardType{"8"} Card10 = CardType{"10"} Card11 = CardType{"11"} Card12 = CardType{"12"} CardApologies = CardType{"A"} )
var ( GameModes = enum.NewValues[GameMode](AdultMode, StandardMode) StandardMode = GameMode{"StandardMode"} AdultMode = GameMode{"AdultMode"} )
var ( ActionTypes = enum.NewValues[ActionType](MoveToStart, MoveToPosition) MoveToStart = ActionType{"MoveToStart"} MoveToPosition = ActionType{"MoveToPosition"} )
var ( PlayerColors = enum.NewValues[PlayerColor](Red, Yellow, Green, Blue) Red = PlayerColor{"Red"} Yellow = PlayerColor{"Yellow"} Blue = PlayerColor{"Blue"} Green = PlayerColor{"Green"} )
var DeckCounts = map[CardType]int{ Card1: 5, Card2: 4, Card3: 4, Card4: 4, Card5: 4, Card7: 4, Card8: 4, Card10: 4, Card11: 4, Card12: 4, CardApologies: 4, }
DeckCounts defines the number of each type of card is in the deck
var DeckSize = func(counts map[CardType]int) int { total := 0 for _, v := range counts { total += v } return total }(DeckCounts)
DeckSize is the total size of the deck
var DrawAgain = map[CardType]bool{ Card1: false, Card2: true, Card3: false, Card4: false, Card5: false, Card7: false, Card8: false, Card10: false, Card11: false, Card12: false, CardApologies: false, }
DrawAgain defines whether a given type of card draws again
var Slides = map[PlayerColor][]Slide{
Red: {newSlide(1, 4), newSlide(9, 13)},
Blue: {newSlide(16, 19), newSlide(24, 28)},
Yellow: {newSlide(31, 34), newSlide(39, 43)},
Green: {newSlide(46, 49), newSlide(54, 58)},
}
Slides defines the start positions for each color
var StartCircles = map[PlayerColor]Position{
Red: newPositionAtSquare(4),
Blue: newPositionAtSquare(19),
Yellow: newPositionAtSquare(34),
Green: newPositionAtSquare(49),
}
StartCircles defines the start circles for each color
var TurnSquares = map[PlayerColor]Position{
Red: newPositionAtSquare(2),
Blue: newPositionAtSquare(17),
Yellow: newPositionAtSquare(32),
Green: newPositionAtSquare(47),
}
TurnSquares defines the turn squares for each color, where forward movement turns into the safe zone
Functions ¶
This section is empty.
Types ¶
type Action ¶
type Action interface { // Type The type of the action Type() ActionType // Pawn the pawn that the action operates on Pawn() Pawn // Position a position that the pawn should move to (optional) Position() Position // optional // SetPosition Set the position on the action (can be nil) SetPosition(position Position) }
Action is an action that can be taken as part of a move
type ActionType ¶
type ActionType struct {
// contains filtered or unexported fields
}
ActionType defines all actions that a character can take
func (ActionType) MarshalText ¶
func (e ActionType) MarshalText() (text []byte, err error)
func (*ActionType) UnmarshalText ¶
func (e *ActionType) UnmarshalText(text []byte) error
func (ActionType) Value ¶
func (e ActionType) Value() string
type Card ¶
type Card interface { // Id Unique identifier for this card Id() string // Type The type of the card Type() CardType // Copy Return a fully-independent copy of the card. Copy() Card }
Card is a card in a deck or in a player's hand
type CardType ¶
type CardType struct {
// contains filtered or unexported fields
}
CardType defines all legal types of cards The "A" card (CardApologies) is like the "Sorry" card in the original game
func (CardType) MarshalText ¶
func (*CardType) UnmarshalText ¶
type Deck ¶
type Deck interface { // Copy Return a fully-independent copy of the deck. Copy() Deck // Draw a card from the draw pile Draw() (Card, error) // Discard a card to the discard pile Discard(card Card) error }
Deck The deck of cards associated with a game.
type Game ¶
type Game interface { // PlayerCount Number of players in the game PlayerCount() int // Players All players in the game Players() map[PlayerColor]Player // Deck The deck of cards for the game Deck() Deck // History Game history History() []History // Copy Return a fully-independent copy of the game. Copy() Game // Started Whether the game has been started. Started() bool // Completed Whether the game is completed. Completed() bool // Winner The winner of the game, if any. Winner() *Player // Track Tracks an action taken during the game, optionally tracking player and/or card Track(action string, player Player, card Card) // CreatePlayerView Return a player-specific view of the game, showing only the information a player would have available on their turn. CreatePlayerView(color PlayerColor) (PlayerView, error) }
Game The game, consisting of state for a set of players.
type GameMode ¶
type GameMode struct {
// contains filtered or unexported fields
}
GameMode defines legal game modes
func (GameMode) MarshalText ¶
func (*GameMode) UnmarshalText ¶
type History ¶
type History interface { // Action String describing the action Action() string // Color Color of the player associated with the action Color() *PlayerColor // optional // Card Card associated with the action Card() *CardType // optional // Timestamp Timestamp tied to the action (defaults to current time) Timestamp() timestamp.Timestamp // Copy Return a fully-independent copy of the history. Copy() History }
History Tracks an action taken during the game.
func NewHistory ¶
func NewHistory(action string, color *PlayerColor, card *CardType, factory timestamp.Factory) History
NewHistory constructs a new History, optionally accepting a timestamp factory
type MockAction ¶
MockAction is an autogenerated mock type for the Action type
func NewMockAction ¶
func NewMockAction(t interface { mock.TestingT Cleanup(func()) }) *MockAction
NewMockAction creates a new instance of MockAction. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.
func (*MockAction) Pawn ¶
func (_m *MockAction) Pawn() Pawn
Pawn provides a mock function with given fields:
func (*MockAction) Position ¶
func (_m *MockAction) Position() Position
Position provides a mock function with given fields:
func (*MockAction) SetPosition ¶
func (_m *MockAction) SetPosition(position Position)
SetPosition provides a mock function with given fields: position
func (*MockAction) Type ¶
func (_m *MockAction) Type() ActionType
Type provides a mock function with given fields:
type MockCard ¶
MockCard is an autogenerated mock type for the Card type
func NewMockCard ¶
NewMockCard creates a new instance of MockCard. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.
type MockDeck ¶
MockDeck is an autogenerated mock type for the Deck type
func NewMockDeck ¶
NewMockDeck creates a new instance of MockDeck. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.
type MockGame ¶
MockGame is an autogenerated mock type for the Game type
func NewMockGame ¶
NewMockGame creates a new instance of MockGame. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.
func (*MockGame) CreatePlayerView ¶
func (_m *MockGame) CreatePlayerView(color PlayerColor) (PlayerView, error)
CreatePlayerView provides a mock function with given fields: color
func (*MockGame) PlayerCount ¶
PlayerCount provides a mock function with given fields:
func (*MockGame) Players ¶
func (_m *MockGame) Players() map[PlayerColor]Player
Players provides a mock function with given fields:
type MockHistory ¶
MockHistory is an autogenerated mock type for the History type
func NewMockHistory ¶
func NewMockHistory(t interface { mock.TestingT Cleanup(func()) }) *MockHistory
NewMockHistory creates a new instance of MockHistory. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.
func (*MockHistory) Action ¶
func (_m *MockHistory) Action() string
Action provides a mock function with given fields:
func (*MockHistory) Card ¶
func (_m *MockHistory) Card() *CardType
Card provides a mock function with given fields:
func (*MockHistory) Color ¶
func (_m *MockHistory) Color() *PlayerColor
Color provides a mock function with given fields:
func (*MockHistory) Copy ¶
func (_m *MockHistory) Copy() History
Copy provides a mock function with given fields:
func (*MockHistory) Timestamp ¶
func (_m *MockHistory) Timestamp() timestamp.Timestamp
Timestamp provides a mock function with given fields:
type MockMove ¶
MockMove is an autogenerated mock type for the Move type
func NewMockMove ¶
NewMockMove creates a new instance of MockMove. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.
func (*MockMove) AddSideEffect ¶
AddSideEffect provides a mock function with given fields: action
func (*MockMove) MergedActions ¶
MergedActions provides a mock function with given fields:
func (*MockMove) SideEffects ¶
SideEffects provides a mock function with given fields:
type MockPawn ¶
MockPawn is an autogenerated mock type for the Pawn type
func NewMockPawn ¶
NewMockPawn creates a new instance of MockPawn. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.
func (*MockPawn) Color ¶
func (_m *MockPawn) Color() PlayerColor
Color provides a mock function with given fields:
func (*MockPawn) SetPosition ¶
SetPosition provides a mock function with given fields: position
type MockPlayer ¶
MockPlayer is an autogenerated mock type for the Player type
func NewMockPlayer ¶
func NewMockPlayer(t interface { mock.TestingT Cleanup(func()) }) *MockPlayer
NewMockPlayer creates a new instance of MockPlayer. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.
func (*MockPlayer) AllPawnsInHome ¶
func (_m *MockPlayer) AllPawnsInHome() bool
AllPawnsInHome provides a mock function with given fields:
func (*MockPlayer) AppendToHand ¶
func (_m *MockPlayer) AppendToHand(card Card)
AppendToHand provides a mock function with given fields: card
func (*MockPlayer) Color ¶
func (_m *MockPlayer) Color() PlayerColor
Color provides a mock function with given fields:
func (*MockPlayer) Copy ¶
func (_m *MockPlayer) Copy() Player
Copy provides a mock function with given fields:
func (*MockPlayer) FindFirstPawnInStart ¶
func (_m *MockPlayer) FindFirstPawnInStart() *Pawn
FindFirstPawnInStart provides a mock function with given fields:
func (*MockPlayer) Hand ¶
func (_m *MockPlayer) Hand() []Card
Hand provides a mock function with given fields:
func (*MockPlayer) IncrementTurns ¶
func (_m *MockPlayer) IncrementTurns()
IncrementTurns provides a mock function with given fields:
func (*MockPlayer) Pawns ¶
func (_m *MockPlayer) Pawns() []Pawn
Pawns provides a mock function with given fields:
func (*MockPlayer) PublicData ¶
func (_m *MockPlayer) PublicData() Player
PublicData provides a mock function with given fields:
func (*MockPlayer) RemoveFromHand ¶
func (_m *MockPlayer) RemoveFromHand(card Card)
RemoveFromHand provides a mock function with given fields: card
func (*MockPlayer) Turns ¶
func (_m *MockPlayer) Turns() int
Turns provides a mock function with given fields:
type MockPlayerView ¶
MockPlayerView is an autogenerated mock type for the PlayerView type
func NewMockPlayerView ¶
func NewMockPlayerView(t interface { mock.TestingT Cleanup(func()) }) *MockPlayerView
NewMockPlayerView creates a new instance of MockPlayerView. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.
func (*MockPlayerView) AllPawns ¶
func (_m *MockPlayerView) AllPawns() []Pawn
AllPawns provides a mock function with given fields:
func (*MockPlayerView) Copy ¶
func (_m *MockPlayerView) Copy() PlayerView
Copy provides a mock function with given fields:
func (*MockPlayerView) GetPawn ¶
func (_m *MockPlayerView) GetPawn(prototype Pawn) Pawn
GetPawn provides a mock function with given fields: prototype
func (*MockPlayerView) Opponents ¶
func (_m *MockPlayerView) Opponents() map[PlayerColor]Player
Opponents provides a mock function with given fields:
func (*MockPlayerView) Player ¶
func (_m *MockPlayerView) Player() Player
Player provides a mock function with given fields:
type MockPosition ¶
MockPosition is an autogenerated mock type for the Position type
func NewMockPosition ¶
func NewMockPosition(t interface { mock.TestingT Cleanup(func()) }) *MockPosition
NewMockPosition creates a new instance of MockPosition. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.
func (*MockPosition) Copy ¶
func (_m *MockPosition) Copy() Position
Copy provides a mock function with given fields:
func (*MockPosition) Home ¶
func (_m *MockPosition) Home() bool
Home provides a mock function with given fields:
func (*MockPosition) MoveToHome ¶
func (_m *MockPosition) MoveToHome() error
MoveToHome provides a mock function with given fields:
func (*MockPosition) MoveToPosition ¶
func (_m *MockPosition) MoveToPosition(position Position) error
MoveToPosition provides a mock function with given fields: position
func (*MockPosition) MoveToSafe ¶
func (_m *MockPosition) MoveToSafe(safe int) error
MoveToSafe provides a mock function with given fields: safe
func (*MockPosition) MoveToSquare ¶
func (_m *MockPosition) MoveToSquare(square int) error
MoveToSquare provides a mock function with given fields: square
func (*MockPosition) MoveToStart ¶
func (_m *MockPosition) MoveToStart() error
MoveToStart provides a mock function with given fields:
func (*MockPosition) Safe ¶
func (_m *MockPosition) Safe() *int
Safe provides a mock function with given fields:
func (*MockPosition) Square ¶
func (_m *MockPosition) Square() *int
Square provides a mock function with given fields:
func (*MockPosition) Start ¶
func (_m *MockPosition) Start() bool
Start provides a mock function with given fields:
type MockSlide ¶
MockSlide is an autogenerated mock type for the Slide type
func NewMockSlide ¶
NewMockSlide creates a new instance of MockSlide. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.
type Move ¶
type Move interface { Card() Card Actions() []Action SideEffects() []Action AddSideEffect(action Action) MergedActions() []Action }
Move is a player's move on the board, which consists of one or more actions
Note that the actions associated with a move include both the immediate actions that the player chose (such as moving a pawn from start or swapping places with a different pawn), but also any side-effects (such as pawns that are bumped back to start because of a slide). As a result, executing a move becomes very easy and no validation is required. All of the work is done up-front.
type Pawn ¶
type Pawn interface { // Color the color of this pawn Color() PlayerColor // Index Zero-based index of this pawn for a given user Index() int // Name The full name of this pawn as "colorindex" Name() string // Position The position of this pawn on the board Position() Position // SetPosition Set the position of this pawn on the board SetPosition(position Position) // Copy Return a fully-independent copy of the pawn. Copy() Pawn }
Pawn is a pawn on the board, belonging to a player.
type Player ¶
type Player interface { // Color the color of this player Color() PlayerColor // Hand List of cards in the player's hand Hand() []Card // Pawns List of all pawns belonging to the player Pawns() []Pawn // Turns number of turns for this player Turns() int // Copy Return a fully-independent copy of the player. Copy() Player // PublicData Return a fully-independent copy of the player with only public data visible. PublicData() Player // AppendToHand appends a card into the player's hand AppendToHand(card Card) // RemoveFromHand removes a card from the player's hand RemoveFromHand(card Card) // FindFirstPawnInStart Find the first pawn in the start area, if any. FindFirstPawnInStart() *Pawn // optional // AllPawnsInHome Whether all of this user's pawns are in home. AllPawnsInHome() bool // IncrementTurns the number of turns for a player IncrementTurns() }
Player A player, which has a color and a set of pawns.
type PlayerColor ¶
type PlayerColor struct {
// contains filtered or unexported fields
}
PlayerColor defines all legal player colors, enumerated in order of use
func (PlayerColor) MarshalText ¶
func (e PlayerColor) MarshalText() (text []byte, err error)
func (*PlayerColor) UnmarshalText ¶
func (e *PlayerColor) UnmarshalText(text []byte) error
func (PlayerColor) Value ¶
func (e PlayerColor) Value() string
type PlayerView ¶
type PlayerView interface { // Player The player associated with the view. Player() Player // Opponents The player's opponents, with private information stripped Opponents() map[PlayerColor]Player // Copy Return a fully-independent copy of the player view. Copy() PlayerView // GetPawn Return the pawn from this view with the same color and index, possibly nil GetPawn(prototype Pawn) Pawn // AllPawns Return a list of all pawns on the board. AllPawns() []Pawn }
PlayerView A player-specific view of the game, showing only the information a player would have available on their turn.
func NewPlayerView ¶
func NewPlayerView(player Player, opponents map[PlayerColor]Player) PlayerView
NewPlayerView contructs a new PlayerView
func NewPlayerViewFromJSON ¶
func NewPlayerViewFromJSON(reader io.Reader) (PlayerView, error)
NewPlayerViewFromJSON constructs a new object from JSON in an io.Reader
type Position ¶
type Position interface { // Start Whether this pawn resides in its start area Start() bool // Home Whether this pawn resides in its home area Home() bool // Safe Zero-based index of the square in the safe area where this pawn resides Safe() *int // optional // Square Zero-based index of the square on the board where this pawn resides Square() *int // optional // Copy Return a fully-independent copy of the position. Copy() Position // MoveToPosition Move the pawn to a specific position on the board. MoveToPosition(position Position) error // MoveToStart Move the pawn back to its start area. MoveToStart() error // MoveToHome Move the pawn to its home area. MoveToHome() error // MoveToSafe Move the pawn to a square in its safe area. MoveToSafe(safe int) error // MoveToSquare Move the pawn to a square on the board. MoveToSquare(square int) error }
Position is the position of a pawn on the board.
func NewPosition ¶
NewPosition constructs a new Position