go_codenames

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2023 License: MIT Imports: 9 Imported by: 0

README

Go-codenames

Go-codenames is a Go implementation of the board game Codenames. Please note that this repo only includes game logic and a basic API to interact with the game but does NOT include any form of GUI.

Usage

To play a game create a new Codenames instance:

builder := Builder{}
game, err := builder.Create(&bg.BoardGameOptions{
    Teams: []string{"TeamA", "TeamB"}, // must contain exactly 2 teams
    MoreOptions: CodenamesMoreOptions{
        Seed: 123, // seed used to generate deterministic randomness
    }
})

To flip a card do the following action:

err := game.Do(&bg.BoardGameAction{
    Team: "TeamA",
    ActionType: "FlipCard",
    MoreDetails: FlipCardActionDetails{
        Row: 0,    // rows 0 to 4 are valid
        Column: 0, // columns 0 to 4 are valid
    },
})

To end your turn do the following action:

err := game.Do(&bg.BoardGameAction{
    Team: "TeamA",
    ActionType: "EndTurn",
})

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

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

Documentation

Index

Constants

View Source
const (
	ActionFlipCard = "FlipCard"
	ActionEndTurn  = "EndTurn"
)

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

func (b *Builder) Key() string

func (*Builder) Load

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

type Codenames

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

func NewCodenames

func NewCodenames(options *bg.BoardGameOptions) (*Codenames, error)

func (*Codenames) Do

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

func (*Codenames) GetBGN

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

func (*Codenames) GetSnapshot

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

type CodenamesMoreOptions

type CodenamesMoreOptions struct {
	// Words must be 25 words in length - optional, one of Words or Seed required
	Words []string

	// Seed used to generate deterministic randomness - optional, one of Words or Seed required
	Seed int64
}

CodenamesMoreOptions are the additional options for creating a game of Codenames

type CodenamesSnapshotData

type CodenamesSnapshotData struct {
	Board [][]*card
}

CodenamesSnapshotData is the game data unique to Codenames

type FlipCardActionDetails

type FlipCardActionDetails struct {
	Row, Column int
}

FlipCardActionDetails is the action details for flipping a card at the desired row and column

Jump to

Keyboard shortcuts

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