go_connect4

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2023 License: MIT Imports: 7 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Go-connect4

Go-connect4 is a Go implementation of the board game Connect4.

Check out connect4.quibbble.com to play a live version of this game. This website utilizes connect4 frontend code, go-connect4 game logic, and go-quibbble server logic.

Quibbble Connect4

Usage

To play a game create a new Connect4 instance:

builder := Builder{}
game, err := builder.Create(&bg.BoardGameOptions{
    Teams: []string{"TeamA", "TeamB"}, // must contain at least 2 and at most 3 teams
})

To place a disk do the following action:

err := game.Do(&bg.BoardGameAction{
    Team: "TeamA",
    ActionType: "PlaceDisk",
    MoreDetails: PlaceDiskActionDetails{
        Column: 0, // columns 0 to 6 are valid
    },
})

To get the current state of the game call the following:

snapshot, err := game.GetSnapshot("TeamA")

Documentation

Index

Constants

View Source
const (
	// ActionPlaceDisk allows players place a disk in a column
	ActionPlaceDisk = "PlaceDisk"
)

Action types

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder struct{}

func (*Builder) Create

func (b *Builder) Create(options *bg.BoardGameOptions) (bg.BoardGame, error)

func (*Builder) CreateWithBGN

func (b *Builder) CreateWithBGN(options *bg.BoardGameOptions) (bg.BoardGameWithBGN, error)

func (*Builder) Info added in v1.0.4

func (b *Builder) Info() *bg.BoardGameInfo

func (*Builder) Key

func (b *Builder) Key() string

func (*Builder) Load

func (b *Builder) Load(game *bgn.Game) (bg.BoardGameWithBGN, error)

type Connect4

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

func NewConnect4

func NewConnect4(options *bg.BoardGameOptions) (*Connect4, error)

func (*Connect4) Do

func (c *Connect4) Do(action *bg.BoardGameAction) error

func (*Connect4) GetBGN

func (c *Connect4) GetBGN() *bgn.Game

func (*Connect4) GetSnapshot

func (c *Connect4) GetSnapshot(team ...string) (*bg.BoardGameSnapshot, error)

type Connect4SnapshotData

type Connect4SnapshotData struct {
	Board [][]*string
}

Connect4SnapshotData is the game data unique to Connect4

type PlaceDiskActionDetails

type PlaceDiskActionDetails struct {
	Column int
}

PlaceDiskActionDetails is the action details for placing a disk in the desired column of the board

Jump to

Keyboard shortcuts

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