connectfour

package
v0.0.0-...-7b0ad5b Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2023 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const DropDiscCmd cg.CommandName = "drop_disc"

The `drop_disc` command can be sent to drop a disc into the game grid. Only allowed when it is the current player's turn.

View Source
const GameOverEvent cg.EventName = "game_over"
View Source
const GridEvent cg.EventName = "grid"

The game grid.

View Source
const InvalidActionEvent cg.EventName = "invalid_action"

The 'invalid_action' event notifies the player that their action was not allowed.

View Source
const PopOutCmd cg.CommandName = "pop_out"

The `pop_out` command can be sent to remove a disc of your color from the bottom of the grid. Only available if config.variation = pop_out.

View Source
const StartEvent cg.EventName = "start"

The `start` event is sent to all players when the game begins.

View Source
const TurnEvent cg.EventName = "turn"

The `turn` event is sent to all players when it is the next player's turn.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cell

type Cell struct {
	Row    int   `json:"row"`
	Column int   `json:"column"`
	Color  Color `json:"color"`
}

A cell on the game grid.

type Color

type Color string

A disc color.

const (
	// No color. Used for empty cells.
	ColorNone Color = "none"
	// A drops the first disc.
	ColorA Color = "a"
	// B drops the second disc.
	ColorB Color = "b"
)

type DropDiscCmdData

type DropDiscCmdData struct {
	// 0 <= column < config.width
	Column int `json:"column"`
}

type Game

type Game struct {
	// contains filtered or unexported fields
}

func NewGame

func NewGame(cgGame *cg.Game, config GameConfig) *Game

func (*Game) Run

func (g *Game) Run()

type GameConfig

type GameConfig struct {
	// The width of the game grid. min = 3, default = 7
	Width int `json:"width"`
	// The height of the game grid. min = 3, default = 6
	Height int `json:"height"`
	// The number of discs, which form a winning line. min = 2, default = 4
	WinLength int `json:"win_length"`
	// The rule variation to use. default: original
	Variation Variation `json:"variation"`
}

type GameOverEventData

type GameOverEventData struct {
	// The color of the winner.
	WinnerColor Color `json:"winner_color"`
	// The four cells which form a line.
	WinningLine []Cell `json:"winning_line"`
}

type GridEventData

type GridEventData struct {
	// The cells of the grid as columns (left to right) inside of rows (top to bottom).
	Cells [][]Cell `json:"cells"`
}

type InvalidActionEventData

type InvalidActionEventData struct {
	// The message containing details on what the player did wrong.
	Message string `json:"message"`
}

type PopOutCmdData

type PopOutCmdData struct {
	// 0 <= column < config.width
	Column int `json:"column"`
}

type StartEventData

type StartEventData struct {
	// A map of player IDs mapped to their respective disc colors.
	Colors map[string]Color `json:"colors"`
}

type TurnEventData

type TurnEventData struct {
	// The sign of the player whose turn it is now.
	Color Color `json:"color"`
}

type Variation

type Variation string
const (
	// The original Connect 4 game.
	VariationOriginal Variation = "original"
	// Instead of dropping a disc into a grid a player may choose to remove a disc of their own color from the bottom.
	VariationPopOut Variation = "pop_out"
)

Jump to

Keyboard shortcuts

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