go_tsuro

package module
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2023 License: MIT Imports: 10 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-tsuro

Go-tsuro is a Go implementation of the board game Tsuro.

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

Quibbble Tsuro

Usage

To play a game create a new Tsuro instance:

builder := Builder{}
game, err := builder.Create(&bg.BoardGameOptions{
    Teams: []string{"TeamA", "TeamB"}, // must contain at least 2 and at most 8 teams
    MoreOptions: TsuroMoreOptions{
        Seed: 123, // OPTIONAL - seed used to generate deterministic randomness which defaults to 0
        Variant: "Classic" // OPTIONAL - variants that change the game rules i.e. Classic (default), LongestPath, MostCrossings, OpenTiles, or Solo
    }
})

To rotate a tile in your hand do the following action:

err := game.Do(&bg.BoardGameAction{
    Team: "TeamA",
    ActionType: "RotateTileRight", // can also be "RotateTileLeft"
    MoreDetails: RotateTileActionDetails{
        Tile: "ABCDEFGH"
    },
})

To place a tile on the board do the following action:

err := game.Do(&bg.BoardGameAction{
    Team: "TeamA",
    ActionType: "PlaceTile",
    MoreDetails: PlaceTileActionDetails{
        Row: 0,
        Column: 1,
        Tile: "ABCDEFGH"
    },
})

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

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

Documentation

Index

Constants

View Source
const (
	ActionPlaceTile       = "PlaceTile"
	ActionRotateTileRight = "RotateTileRight"
	ActionRotateTileLeft  = "RotateRileLeft"
)

Action types

View Source
const (
	VariantClassic       = "Classic"       // normal Tsuro
	VariantLongestPath   = "LongestPath"   // player with the longest path wins
	VariantMostCrossings = "MostCrossings" // player whose path crosses itself the most wins
	VariantOpenTiles     = "OpenTiles"     // tiles are shared globally
	VariantSolo          = "Solo"          // place tiles while keeping all tokens on the board
)

Tsuro Variants

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.10

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 PlaceTileActionDetails

type PlaceTileActionDetails struct {
	Row, Column int
	Tile        string
}

PlaceTileActionDetails is the action details for placing a tile in the desired location on the board

type RotateTileActionDetails

type RotateTileActionDetails struct {
	Tile string
}

RotateTileActionDetails is the action details for rotating a tile in hand

type Tsuro

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

func NewTsuro

func NewTsuro(options *bg.BoardGameOptions) (*Tsuro, error)

func (*Tsuro) Do

func (t *Tsuro) Do(action *bg.BoardGameAction) error

func (*Tsuro) GetBGN

func (t *Tsuro) GetBGN() *bgn.Game

func (*Tsuro) GetSnapshot

func (t *Tsuro) GetSnapshot(team ...string) (*bg.BoardGameSnapshot, error)

type TsuroMoreInfo added in v1.0.10

type TsuroMoreInfo struct {
	Variants []string
}

TsuroMoreInfo provides additional info about the game

type TsuroMoreOptions

type TsuroMoreOptions struct {
	Seed    int64
	Variant string
}

TsuroMoreOptions are the additional options for creating a game of Tsuro

type TsuroSnapshotData

type TsuroSnapshotData struct {
	Board          [][]*tile
	TilesRemaining int
	Hands          map[string][]*tile
	Tokens         map[string]*token
	Dragon         string `json:",omitempty"`
	Variant        string
	Points         map[string]int `json:",omitempty"`
}

TsuroSnapshotData is the game data unique to Tsuro

Jump to

Keyboard shortcuts

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