Documentation
¶
Overview ¶
Package base contains a number of base classes for common objects in boardgame. Technically all of these base objects are fully optional, but in practice almost every game will use them (or a class that embeds them).
Index ¶
- func IsFixUp(move boardgame.Move) bool
- type ComponentValues
- type GameDelegate
- func (g *GameDelegate) BeginSetUp(state boardgame.State, variant boardgame.Variant) error
- func (g *GameDelegate) CheckGameFinished(state boardgame.ImmutableState) (finished bool, winners []boardgame.PlayerIndex)
- func (g *GameDelegate) ComputedGlobalProperties(state boardgame.ImmutableState) boardgame.PropertyCollection
- func (g *GameDelegate) ComputedPlayerGroupMembership(groupName string, playerMembership, viewingAsPlayerMembership map[int]bool) (bool, error)
- func (g *GameDelegate) ComputedPlayerProperties(player boardgame.ImmutableSubState) boardgame.PropertyCollection
- func (g *GameDelegate) ConfigureAgents() []boardgame.Agent
- func (g *GameDelegate) ConfigureConstants() boardgame.PropertyCollection
- func (g *GameDelegate) ConfigureDecks() map[string]*boardgame.Deck
- func (g *GameDelegate) ConfigureEnums() *enum.Set
- func (g *GameDelegate) CurrentPhase(state boardgame.ImmutableState) int
- func (g *GameDelegate) CurrentPlayerIndex(state boardgame.ImmutableState) boardgame.PlayerIndex
- func (g *GameDelegate) DefaultNumPlayers() int
- func (g *GameDelegate) Description() string
- func (g *GameDelegate) Diagram(state boardgame.ImmutableState) string
- func (g *GameDelegate) DisplayName() string
- func (g *GameDelegate) DistributeComponentToStarterStack(state boardgame.ImmutableState, c boardgame.Component) (boardgame.ImmutableStack, error)
- func (g *GameDelegate) DynamicComponentValuesConstructor(deck *boardgame.Deck) boardgame.ConfigurableSubState
- func (g *GameDelegate) FinishSetUp(state boardgame.State) error
- func (g *GameDelegate) GameEndConditionMet(state boardgame.ImmutableState) bool
- func (g *GameDelegate) GroupEnum() enum.Enum
- func (g *GameDelegate) GroupMembership(playerState boardgame.ImmutableSubState) map[int]bool
- func (g *GameDelegate) LegalNumPlayers(numPlayers int) bool
- func (g *GameDelegate) LowScoreWins() bool
- func (g *GameDelegate) Manager() *boardgame.GameManager
- func (g *GameDelegate) MaxNumPlayers() int
- func (g *GameDelegate) MinNumPlayers() int
- func (g *GameDelegate) NumActivePlayers(state boardgame.ImmutableState) int
- func (g *GameDelegate) NumSeatedActivePlayers(state boardgame.ImmutableState) int
- func (g *GameDelegate) NumSeatedPlayers(state boardgame.ImmutableState) int
- func (g *GameDelegate) PhaseEnum() enum.Enum
- func (g *GameDelegate) PlayerMayBeActive(player boardgame.ImmutableSubState) bool
- func (g *GameDelegate) PlayerScore(pState boardgame.ImmutableSubState) int
- func (g *GameDelegate) ProposeFixUpMove(state boardgame.ImmutableState) boardgame.Move
- func (g *GameDelegate) SanitizationPolicy(prop boardgame.StatePropertyRef, groupMembership map[string]bool) boardgame.Policy
- func (g *GameDelegate) SetManager(manager *boardgame.GameManager)
- func (g *GameDelegate) Variants() boardgame.VariantConfig
- type Move
- func (m *Move) CustomConfiguration() boardgame.PropertyCollection
- func (m *Move) DefaultsForState(state boardgame.ImmutableState)
- func (m *Move) HelpText() string
- func (m *Move) Info() *boardgame.MoveInfo
- func (m *Move) IsFixUp() bool
- func (m *Move) Name() string
- func (m *Move) ReadSetConfigurer() boardgame.PropertyReadSetConfigurer
- func (m *Move) ReadSetter() boardgame.PropertyReadSetter
- func (m *Move) Reader() boardgame.PropertyReader
- func (m *Move) SetInfo(info *boardgame.MoveInfo)
- func (m *Move) SetTopLevelStruct(t boardgame.Move)
- func (m *Move) TopLevelStruct() boardgame.Move
- func (m *Move) ValidConfiguration(exampleState boardgame.State) error
- type PlayerGameScorer
- type SubState
- func (s *SubState) ConnectContainingState(state boardgame.State, ref boardgame.StatePropertyRef)
- func (s *SubState) FinishStateSetUp()
- func (s *SubState) ImmutableState() boardgame.ImmutableState
- func (s *SubState) PlayerIndex() boardgame.PlayerIndex
- func (s *SubState) State() boardgame.State
- func (s *SubState) StatePropertyRef() boardgame.StatePropertyRef
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsFixUp ¶
IsFixUp is a convenience method that takes the given move and returns whehter its IsFixUp method returns true. If no IsFixUp exists, will return false. Used by base.GameDelegate, since IsFixUp() isn't defined in the core library, which means that moves fetched via the GameManager will have to be casted to an interface.
Types ¶
type ComponentValues ¶
type ComponentValues struct {
// contains filtered or unexported fields
}
ComponentValues is an optional convenience struct designed to be embedded anoymously in your component values to implement boardgame.ContainingComponent() and boardgame.SetContainingComponent() automatically.
func (*ComponentValues) ContainingComponent ¶
func (v *ComponentValues) ContainingComponent() boardgame.Component
ContainingComponent returns the component set via SetContainingComponent.
func (*ComponentValues) SetContainingComponent ¶
func (v *ComponentValues) SetContainingComponent(c boardgame.Component)
SetContainingComponent sets the return value of ContainingComponent.
type GameDelegate ¶
type GameDelegate struct {
// contains filtered or unexported fields
}
GameDelegate is a struct that implements stubs for all of GameDelegate's methods. This makes it easy to override just one or two methods by creating your own struct that anonymously embeds this one. Name, GameStateConstructor, PlayerStateConstructor, and ConfigureMoves are not implemented, since those almost certainly must be overridden for your particular game.
func (*GameDelegate) BeginSetUp ¶
BeginSetUp does not do anything and returns nil.
func (*GameDelegate) CheckGameFinished ¶
func (g *GameDelegate) CheckGameFinished(state boardgame.ImmutableState) (finished bool, winners []boardgame.PlayerIndex)
CheckGameFinished by default checks delegate.GameEndConditionMet(). If true, then it fetches delegate.PlayerScore() for each player and returns all players who have the highest score as winners. (If delegate.LowScoreWins() is true, instead of highest score, it does lowest score.) It skips any players who are Inactive (according to behaviors.PlayerIsInactive). To use this implementation simply implement those methods. This is sufficient for many games, but not all, so sometimes needs to be overriden.
func (*GameDelegate) ComputedGlobalProperties ¶
func (g *GameDelegate) ComputedGlobalProperties(state boardgame.ImmutableState) boardgame.PropertyCollection
ComputedGlobalProperties returns nil.
func (*GameDelegate) ComputedPlayerGroupMembership ¶
func (g *GameDelegate) ComputedPlayerGroupMembership(groupName string, playerMembership, viewingAsPlayerMembership map[int]bool) (bool, error)
ComputedPlayerGroupMembership is the override point where advanced groups like 'same-ENUMNAME' are supported. Typically you leave this as-is without overriding. If you override this, always fall back in the base case to returning the value from this implementation, so you don't lose the ability to have the special group names it provides.
The special names it supports are of the form 'TYPE-ENUMMNAME'. ENUMNAME must be a named enum in the game's chest that is also a subset of delegate.GroupEnum. TYPE must be one of the following types:
'same' returns true if all of the keys for that enum in playerMembership and viewingAsPlayerMembership are the same.
'different' returns true if any of the keys for that enum in playerMembership and viewingAsPlayerMembership are different.
Example: 'same-color': true if the two players are precisely the same color as returned by GroupMembership.
func (*GameDelegate) ComputedPlayerProperties ¶
func (g *GameDelegate) ComputedPlayerProperties(player boardgame.ImmutableSubState) boardgame.PropertyCollection
ComputedPlayerProperties returns nil.
func (*GameDelegate) ConfigureAgents ¶
func (g *GameDelegate) ConfigureAgents() []boardgame.Agent
ConfigureAgents by default returns nil. If you want agents in your game, override this.
func (*GameDelegate) ConfigureConstants ¶
func (g *GameDelegate) ConfigureConstants() boardgame.PropertyCollection
ConfigureConstants returns a zero-entry map. If you have any constants you wa8nt to use client-side or in tag-based struct auto-inflaters, you will want to override this.
func (*GameDelegate) ConfigureDecks ¶
func (g *GameDelegate) ConfigureDecks() map[string]*boardgame.Deck
ConfigureDecks returns a zero-entry map. You want to override this if you have any components in your game (which the vast majority of games do)
func (*GameDelegate) ConfigureEnums ¶
func (g *GameDelegate) ConfigureEnums() *enum.Set
ConfigureEnums simply returns nil. In general you want to override this with a body of `return Enums`, if you're using `boardgame-util config` to generate your enum set.
func (*GameDelegate) CurrentPhase ¶
func (g *GameDelegate) CurrentPhase(state boardgame.ImmutableState) int
CurrentPhase by default with return the value of gameState.Phase, if it is an enum. If it is not, it will return -1 instead, to make it more clear that it's an invalid CurrentPhase (phase 0 is often valid).
func (*GameDelegate) CurrentPlayerIndex ¶
func (g *GameDelegate) CurrentPlayerIndex(state boardgame.ImmutableState) boardgame.PlayerIndex
CurrentPlayerIndex returns gameState.CurrentPlayer, if that is a PlayerIndex property. If not, returns ObserverPlayerIndex. If you use behaviors.CurrentPlayerBehavior it works well with this. Will use EnsureValid.
func (*GameDelegate) DefaultNumPlayers ¶
func (g *GameDelegate) DefaultNumPlayers() int
DefaultNumPlayers returns 2.
func (*GameDelegate) Description ¶
func (g *GameDelegate) Description() string
Description defaults to "" if not overriden.
func (*GameDelegate) Diagram ¶
func (g *GameDelegate) Diagram(state boardgame.ImmutableState) string
Diagram returns the string "This should be overriden to render a reasonable state here"
func (*GameDelegate) DisplayName ¶
func (g *GameDelegate) DisplayName() string
DisplayName by default just returns the title-case of Name() that is returned from the delegate in use.
func (*GameDelegate) DistributeComponentToStarterStack ¶
func (g *GameDelegate) DistributeComponentToStarterStack(state boardgame.ImmutableState, c boardgame.Component) (boardgame.ImmutableStack, error)
DistributeComponentToStarterStack does nothing any returns an error. If your game has components, it should override this to tell the engine where to stash the components to start. If your game doesn't have any components, then this won't be called on GameManager boot up, and this stub will have prevented you from needing to define a no-op.
func (*GameDelegate) DynamicComponentValuesConstructor ¶
func (g *GameDelegate) DynamicComponentValuesConstructor(deck *boardgame.Deck) boardgame.ConfigurableSubState
DynamicComponentValuesConstructor returns nil, as not all games have DynamicComponentValues. Override this if your game does require DynamicComponentValues.
func (*GameDelegate) FinishSetUp ¶
func (g *GameDelegate) FinishSetUp(state boardgame.State) error
FinishSetUp doesn't do anything and returns nil.
func (*GameDelegate) GameEndConditionMet ¶
func (g *GameDelegate) GameEndConditionMet(state boardgame.ImmutableState) bool
GameEndConditionMet is used in the default CheckGameFinished implementation. It should return true when the game is over and ready for scoring. CheckGameFinished uses this by default; if you override CheckGameFinished you don't need to override this. The default implementation of this simply returns false.
func (*GameDelegate) GroupEnum ¶
func (g *GameDelegate) GroupEnum() enum.Enum
GroupEnum will return the enum named 'group', if it exists, otherwise nil. 'group' is the name of the special combine group that codegen treats specially and combines with boardgame.BaseGroupEnum.
func (*GameDelegate) GroupMembership ¶
func (g *GameDelegate) GroupMembership(playerState boardgame.ImmutableSubState) map[int]bool
GroupMembership will look for any Enum properties on playerState, and if any of them are part of GroupEnum(), will return true for the values that they are. This handles many common cases correctly. For example, if you use behaviors.Color, and your color enum is combined into the enum called 'group', then this will automatically report that membership for the player.
func (*GameDelegate) LegalNumPlayers ¶
func (g *GameDelegate) LegalNumPlayers(numPlayers int) bool
LegalNumPlayers checks that the number of players is between MinNumPlayers and MaxNumPlayers, inclusive. You'd only want to override this if some player numbers in that range are not legal, for example a game where only even numbers of players may play.
func (*GameDelegate) LowScoreWins ¶
func (g *GameDelegate) LowScoreWins() bool
LowScoreWins is used in base.GameDelegate's CheckGameFinished. If false (default) higher scores are better. If true, however, then lower scores win (similar to golf), and all of the players with the lowest score win.
func (*GameDelegate) Manager ¶
func (g *GameDelegate) Manager() *boardgame.GameManager
Manager returns the manager object that was provided to SetManager.
func (*GameDelegate) MaxNumPlayers ¶
func (g *GameDelegate) MaxNumPlayers() int
MaxNumPlayers returns 16
func (*GameDelegate) MinNumPlayers ¶
func (g *GameDelegate) MinNumPlayers() int
MinNumPlayers returns 1
func (*GameDelegate) NumActivePlayers ¶
func (g *GameDelegate) NumActivePlayers(state boardgame.ImmutableState) int
NumActivePlayers returns the number of players who are active (whether or not they are seated). See also NumSeatedActivePlayers, which is typically what you want. See boardgame/behaviors package doc for more.
func (*GameDelegate) NumSeatedActivePlayers ¶
func (g *GameDelegate) NumSeatedActivePlayers(state boardgame.ImmutableState) int
NumSeatedActivePlayers returns the number of players who are both seated and active. This is typically the number you want to decide how many 'real' players there are at the moment. See boardgame/behaviors package doc for more.
func (*GameDelegate) NumSeatedPlayers ¶
func (g *GameDelegate) NumSeatedPlayers(state boardgame.ImmutableState) int
NumSeatedPlayers returns the number of players who are seated (whether or not they are active.) See also NumSeatedActivePlayers, which is typically what you want. See boardgame/behaviors package doc for more.
func (*GameDelegate) PhaseEnum ¶
func (g *GameDelegate) PhaseEnum() enum.Enum
PhaseEnum defaults to the enum named "phase" (or "Phase", if that doesn't exist) which is the convention for the name of the Phase enum. moves.Default will handle cases where that isn't a valid enum gracefully.
func (*GameDelegate) PlayerMayBeActive ¶
func (g *GameDelegate) PlayerMayBeActive(player boardgame.ImmutableSubState) bool
PlayerMayBeActive returns true for all players, unless they implement moves/interfaces.PlayerInactiverer, in which case IsInactive is consulted, and if it's true then this returns false. Designed to work well with behaviors.InactivePlayer
func (*GameDelegate) PlayerScore ¶
func (g *GameDelegate) PlayerScore(pState boardgame.ImmutableSubState) int
PlayerScore is used in the default CheckGameFinished implementation. It should return the score for the given player. CheckGameFinished uses this by default; if you override CheckGameFinished you don't need to override this. The default implementation returns pState.GameScore() (if pState implements the PlayerGameScorer interface), or 0 otherwise.
func (*GameDelegate) ProposeFixUpMove ¶
func (g *GameDelegate) ProposeFixUpMove(state boardgame.ImmutableState) boardgame.Move
ProposeFixUpMove runs through all moves in Moves, in order, and returns the first one that returns true from IsFixUp and is legal at the current state. In many cases, this behavior should be suficient and need not be overwritten. Be extra sure that your FixUpMoves have a conservative Legal function, otherwise you could get a panic from applying too many FixUp moves. Wil emit debug information about why certain fixup moves didn't apply if the Manager's log level is Debug or higher.
func (*GameDelegate) SanitizationPolicy ¶
func (g *GameDelegate) SanitizationPolicy(prop boardgame.StatePropertyRef, groupMembership map[string]bool) boardgame.Policy
SanitizationPolicy uses struct tags to identify the right policy to apply (see the package doc on SanitizationPolicy for how to configure those tags). It sees which policies apply given the provided group membership, and then returns the LEAST restrictive policy that applies. This behavior is almost always what you want; it is rare to need to override this method.
func (*GameDelegate) SetManager ¶
func (g *GameDelegate) SetManager(manager *boardgame.GameManager)
SetManager keeps a reference to the passed manager, and returns it when Manager() is called.
func (*GameDelegate) Variants ¶
func (g *GameDelegate) Variants() boardgame.VariantConfig
Variants returns a VariantConfig with no entries.
type Move ¶
type Move struct {
// contains filtered or unexported fields
}
Move is an optional, convenience struct designed to be embedded anonymously in your own Moves. Although technically optional to embed this struct, in almost all cases you will embed it or a move that transitively embeds it.
It provides minimal stubs for all of the expected methods Moves should have, other than Legal() and Apply(), which generally have logic specific to the move.
See also moves.Default, which embeds this but adds logic about overriding configuration via auto.Config(), as well as robust base logic for phases and phase progressions. Typically your moves will use that (or something that embeds that).
boardgame:codegen
func (*Move) CustomConfiguration ¶
func (m *Move) CustomConfiguration() boardgame.PropertyCollection
CustomConfiguration returns the custom configuration associated with this move, according to MoveInfo.CustomConfiguration(). A simple convenience wrapper that allows you to avoid a nil check.
func (*Move) DefaultsForState ¶
func (m *Move) DefaultsForState(state boardgame.ImmutableState)
DefaultsForState doesn't do anything
func (*Move) IsFixUp ¶
IsFixUp always returns false; it's designed ot be overriden. It is designed to work well with base.IsFixUp, for use in base.GameDelegate.ProposeFixUp.
func (*Move) Name ¶
Name returns the name of this move according to MoveInfo.Name(). A simple convenience wrapper that allows you to avoid a nil check.
func (*Move) ReadSetConfigurer ¶
func (m *Move) ReadSetConfigurer() boardgame.PropertyReadSetConfigurer
ReadSetConfigurer returns an autp-generated boardgame.PropertyReadSetConfigurer for Move
func (*Move) ReadSetter ¶
func (m *Move) ReadSetter() boardgame.PropertyReadSetter
ReadSetter returns an autp-generated boardgame.PropertyReadSetter for Move
func (*Move) Reader ¶
func (m *Move) Reader() boardgame.PropertyReader
Reader returns an autp-generated boardgame.PropertyReader for Move
func (*Move) SetTopLevelStruct ¶
SetTopLevelStruct sets the return value of TopLevelStruct.
func (*Move) TopLevelStruct ¶
TopLevelStruct returns the object that was set via SetTopLevelStruct.
type PlayerGameScorer ¶
type PlayerGameScorer interface { //Score returns the overall score for the game for the player at this //point in time. GameScore() int }
PlayerGameScorer is an optional interface that can be implemented by PlayerSubStates. If it is implemented, base.GameDelegate's default PlayerScore() method will return it.
type SubState ¶
type SubState struct {
// contains filtered or unexported fields
}
SubState is a simple struct designed to be anonymously embedded in the boardgame.SubStates you create, so you don't have to implement SetState yourself.
func (*SubState) ConnectContainingState ¶
func (s *SubState) ConnectContainingState(state boardgame.State, ref boardgame.StatePropertyRef)
ConnectContainingState sets the State to the given state and the ref to the given ref.
func (*SubState) FinishStateSetUp ¶
func (s *SubState) FinishStateSetUp()
FinishStateSetUp doesn't do anything. Typically if you embed a Connectable behavior, you override this and call ConnectBehavior() within it.
func (*SubState) ImmutableState ¶
func (s *SubState) ImmutableState() boardgame.ImmutableState
ImmutableState returns the immutablestate set via SetImmutableState.
func (*SubState) PlayerIndex ¶
func (s *SubState) PlayerIndex() boardgame.PlayerIndex
PlayerIndex is a conveniece warpper that returns StatePropertyRef().PlayerIndex. Only really useful for when the SubState is of type PlayerState.
func (*SubState) StatePropertyRef ¶
func (s *SubState) StatePropertyRef() boardgame.StatePropertyRef
StatePropertyRef returns the ref passed via SetStatePropertyRef()