Documentation ¶
Index ¶
Constants ¶
View Source
const ( DefaultCols = 7 DefaultRows = 6 DefaultNPlayers = 2 DefaultNWin = 4 DefaultMode = "terminal" )
Common defaults.
View Source
const ( Empty = iota Red Yellow Green Magenta Blue Cyan Black Stale PlayerUnicode = '●' )
GridState is the enum values
Variables ¶
AvailablePlayers is the list of available player colors.
View Source
var (
ErrInvalidMove = errors.New("invalid move")
)
Common errors.
Functions ¶
This section is empty.
Types ¶
type Four ¶
type Four struct { sync.RWMutex // Lock to protect the Players map. Content [][]State `json:"content"` NWin int `json:"nwin"` NPlayers int `json:"nplayers"` Columns int `json:"columns"` Rows int `json:"rows"` CurPlayerIdx int `json:"cur_player_idx"` CurPlayer State `json:"cur_player"` AvailablePlayers []State `json:"available_players"` Players map[State]string `json:"players"` // Used for the server mode. ActivityChan chan State `json:"-"` // Channel populated with latest game state. GridState State `json:"grid_state"` // If not "Empty", then the game is finished. }
Four holds the game state.
func NewConnectFour ¶
NewConnectFour instantiates a new game. TODO: Use a single dimension slice.
func (*Four) ColumnCount ¶
ColumnCount returns the count of occupied cells in the requested column.
func (*Four) PlayerMove ¶
PlayerMove plays a move for the given player.
Click to show internal directories.
Click to hide internal directories.