gamestate

package
v0.0.0-...-014f423 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2020 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
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

func (a Action) HasPrivateInfo() bool

func (Action) String

func (a Action) String() string

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

func New(drawPile cards.Stack, player0Deal, player1Deal cards.Set) GameState

New returns a new GameState created with the given draw pile and deals of cards to each of the players.

func NewShuffled

func NewShuffled(prevState GameState, newDrawPile cards.Stack) GameState

NewShuffled returns a new GameState created by applying the given shuffling of the draw pile to an existing GameState.

func (*GameState) Apply

func (gs *GameState) Apply(action Action, visible bool)

Apply returns the new GameState created by applying the given Action.

func (*GameState) GetDrawPile

func (gs *GameState) GetDrawPile() cards.Stack

func (*GameState) GetHistory

func (gs *GameState) GetHistory() History

func (*GameState) GetInfoSet

func (gs *GameState) GetInfoSet(player Player) InfoSet

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) GetPlayerHand

func (gs *GameState) GetPlayerHand(p Player) cards.Set

func (*GameState) LastAction

func (gs *GameState) LastAction() Action

func (*GameState) String

func (gs *GameState) String() string

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 NewHistoryFromActions(actions []Action) History

func (*History) Append

func (h *History) Append(action Action)

func (*History) AppendPacked

func (h *History) AppendPacked(packed EncodedAction)

func (*History) AsSlice

func (h *History) AsSlice() []Action

func (*History) Clear

func (h *History) Clear()

func (*History) Get

func (h *History) Get(i int) Action

func (*History) GetInfoSet

func (h *History) GetInfoSet(player Player, hand cards.Set) InfoSet

Gets the current infoset for the given player.

func (*History) GetPacked

func (h *History) GetPacked(i int) EncodedAction

func (*History) Len

func (h *History) Len() int

func (*History) Slice

func (h *History) Slice(n int) History

func (History) String

func (h History) String() string

type InfoSet

type InfoSet struct {
	Player  Player
	History History
	Hand    cards.Set
}

func (*InfoSet) Key

func (is *InfoSet) Key() string

Key implements cfr.InfoSet.

func (*InfoSet) MarshalBinary

func (is *InfoSet) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler.

func (*InfoSet) MarshalBinarySize

func (is *InfoSet) MarshalBinarySize() int

func (*InfoSet) MarshalTo

func (is *InfoSet) MarshalTo(buf []byte) ([]byte, error)

func (*InfoSet) UnmarshalBinary

func (is *InfoSet) UnmarshalBinary(buf []byte) error

MarshalBinary implements encoding.BinaryUnmarshaler.

type Player

type Player uint8

Player represents the identity of a player in the game.

const (
	Player0 Player = iota
	Player1
)

func (Player) String

func (p Player) String() string

Jump to

Keyboard shortcuts

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