go_carcassonne

package module
v1.1.6 Latest Latest
Warning

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

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

Go-carcassonne is a Go implementation of the board game Carcassonne.

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

Quibbble Carcassonne

Usage

To play a game create a new Carcassonne instance:

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

To rotate the play tile (the tile about to be placed by the current team) do the following action:

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

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

err := game.Do(&bg.BoardGameAction{
    Team: "TeamA",
    ActionType: "PlaceTile",
    MoreDetails: PlaceTileActionDetails{
        X: 0,
        Y: 1,
    },
})

To place a token on the last placed tile do the following action:

err := game.Do(&bg.BoardGameAction{
    Team: "TeamA",
    ActionType: "PlaceToken",
    MoreDetails: PlaceTokenActionDetails{
        Pass: false, // true if you wish to pass placing a token
        X: 0,
        Y: 1,
        Type: "Knight", // can be "Farmer", "Knight", "Thief", or "Monk"
        Side: "Top", // if "Knight" or "Thief" can be "Top", "Right", "Bottom", "Left"; if "Farmer" can be "TopA", "TopB", "RightA", ...; if "Monk" then ""
    },
})

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

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

Documentation

Index

Constants

View Source
const (
	FarmNotchA = "A"
	FarmNotchB = "B"
)

Farm notch which is a piece of a farm side

View Source
const (
	FarmSideTopA    = SideTop + FarmNotchA
	FarmSideTopB    = SideTop + FarmNotchB
	FarmSideRightA  = SideRight + FarmNotchA
	FarmSideRightB  = SideRight + FarmNotchB
	FarmSideBottomA = SideBottom + FarmNotchA
	FarmSideBottomB = SideBottom + FarmNotchB
	FarmSideLeftA   = SideLeft + FarmNotchA
	FarmSideLeftB   = SideLeft + FarmNotchB
)

Farm sides of a tile

      TopA  TopB
        ——  ——
LeftB |        | RightA
LeftA |        | RightB
        ——  ——
   BottomB  BottomA
View Source
const (
	ActionPlaceTile       = "PlaceTile"
	ActionPlaceToken      = "PlaceToken"
	ActionRotateTileRight = "RotateTileRight"
	ActionRotateTileLeft  = "RotateTileLeft"
)

Action types

View Source
const (
	SideTop    = "Top"
	SideRight  = "Right"
	SideBottom = "Bottom"
	SideLeft   = "Left"
)

Sides of a tile

     Top
      ——
Left |  | Right
      ——
    Bottom
View Source
const (
	Farm         = "Farm"
	City         = "City"
	Road         = "Road"
	Cloister     = "Cloister"
	NilStructure = "NilStructure"
)

Structure types

View Source
const (
	Farmer = "Farmer"
	Knight = "Knight"
	Thief  = "Thief"
	Monk   = "Monk"
)

Token types

View Source
const OutOfBounds = 999

Variables

View Source
var StructureTypeToTokenType = map[string]string{Farm: Farmer, City: Knight, Road: Thief, Cloister: Monk}
View Source
var TokenTypes = []string{Farmer, Knight, Thief, Monk}

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

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 Carcassonne

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

func NewCarcassonne

func NewCarcassonne(options *bg.BoardGameOptions) (*Carcassonne, error)

func (*Carcassonne) Do

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

func (*Carcassonne) GetBGN

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

func (*Carcassonne) GetSnapshot

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

type CarcassonneMoreOptions

type CarcassonneMoreOptions struct {
	Seed int64
}

CarcassonneMoreOptions are the additional options for creating a game of Carcassonne

type CarcassonneSnapshotData

type CarcassonneSnapshotData struct {
	PlayTile        *tile
	LastPlacedTiles map[string]*tile
	Board           []*tile
	BoardTokens     []*token
	Tokens          map[string]int
	Scores          map[string]int
	TilesRemaining  int
}

CarcassonneSnapshotData is the game data unique to Carcassonne

type PlaceTileActionDetails

type PlaceTileActionDetails struct {
	// X and Y location where to place the tile
	X, Y int

	// Tile is the tile being placed
	Tile TileActionDetails
}

PlaceTileActionDetails is the action details for placing a tile

type PlaceTokenActionDetails

type PlaceTokenActionDetails struct {
	// Pass set to pass placing a token
	Pass bool

	// X and Y location where to place the token
	X, Y int

	// Type is the type of token to place
	Type string

	// Side is the side to place
	Side string
}

PlaceTokenActionDetails is the action details for placing a token

type TileActionDetails added in v1.1.0

type TileActionDetails struct {
	Top, Right, Bottom, Left, Center string
	ConnectedCitySides, Banner       bool
}

Jump to

Keyboard shortcuts

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