Documentation ¶
Index ¶
- Constants
- type Action
- type ActionType
- type EncodedAction
- type GameState
- func (gs *GameState) Apply(action Action, visible bool)
- func (gs *GameState) GetDrawPile() cards.Stack
- func (gs *GameState) GetHistory() History
- func (gs *GameState) GetInfoSet(player Player) InfoSet
- func (gs *GameState) GetPlayerHand(p Player) cards.Set
- func (gs *GameState) LastAction() Action
- func (gs *GameState) String() string
- type History
- func (h *History) Append(action Action)
- func (h *History) AppendPacked(packed EncodedAction)
- func (h *History) AsSlice() []Action
- func (h *History) Clear()
- func (h *History) Get(i int) Action
- func (h *History) GetInfoSet(player Player, hand cards.Set) InfoSet
- func (h *History) GetPacked(i int) EncodedAction
- func (h *History) Len() int
- func (h *History) Slice(n int) History
- func (h History) String() string
- type InfoSet
- type Player
Constants ¶
const MaxNumActions = 58
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Action ¶
type Action struct { Player Player Type ActionType Card cards.Card // When inserting the exploding kitten, this is the position that // the player chose to insert it to. NOTE: 1-based so that we can // distinguish no knowledge / random (0) from actual positions. PositionInDrawPile uint8 // Private information. CardsSeen [3]cards.Card // Private information. }
Action records each transition/edge in the game history.
func (Action) HasPrivateInfo ¶
type ActionType ¶
type ActionType uint8
ActionType is the type of action a player performed in the game's history.
const ( DrawCard ActionType PlayCard GiveCard InsertExplodingKitten )
func (ActionType) String ¶
func (t ActionType) String() string
type EncodedAction ¶
type EncodedAction [3]uint8
func EncodeAction ¶
func EncodeAction(a Action) EncodedAction
Action is packed as bits within a [3]uint8:
[0] Player (0 or 1) [1-2] Type (1 - 4, encoded as 0-3) [3-6] Card (1 - 10) [7] Indicates whether there is additional private info (remaining bits) (0 or 1) [8-11] PositionInDrawPile (0 - 14) [12-24] 3 Cards (1 - 10)
Thus the first byte is public info, the second two bytes are private info.
func EncodeActions ¶
func EncodeActions(actions []Action) []EncodedAction
func (EncodedAction) Decode ¶
func (packed EncodedAction) Decode() Action
func (EncodedAction) HasPrivateInfo ¶
func (packed EncodedAction) HasPrivateInfo() bool
func (EncodedAction) Player ¶
func (packed EncodedAction) Player() Player
func (EncodedAction) String ¶
func (packed EncodedAction) String() string
type GameState ¶
type GameState struct {
// contains filtered or unexported fields
}
GameState represents the current state of the game.
func New ¶
New returns a new GameState created with the given draw pile and deals of cards to each of the players.
func NewShuffled ¶
NewShuffled returns a new GameState created by applying the given shuffling of the draw pile to an existing GameState.
func (*GameState) GetDrawPile ¶
func (*GameState) GetHistory ¶
func (*GameState) GetInfoSet ¶
InfoSet represents the state of the game from the point of view of one of the players. Note that multiple distinct game states may have the same InfoSet due to hidden information that the player is not privy to.
func (*GameState) LastAction ¶
type History ¶
type History struct {
// contains filtered or unexported fields
}
History records the history of game actions to reach this state. It is pre-sized to avoid allocations and keep GameState easily copyable.
func NewHistoryFromActions ¶
func (*History) AppendPacked ¶
func (h *History) AppendPacked(packed EncodedAction)
func (*History) GetInfoSet ¶
Gets the current infoset for the given player.
func (*History) GetPacked ¶
func (h *History) GetPacked(i int) EncodedAction
type InfoSet ¶
func (*InfoSet) MarshalBinary ¶
MarshalBinary implements encoding.BinaryMarshaler.
func (*InfoSet) MarshalBinarySize ¶
func (*InfoSet) UnmarshalBinary ¶
MarshalBinary implements encoding.BinaryUnmarshaler.