go_stratego

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: 10 Imported by: 0

README

Go-stratego

Go-stratego is a Go implementation of the board game Stratego.

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

Quibbble Stratego

Usage

To play a game create a new Stratego instance:

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

To reoganize your board and switch units before the game starts do the following action:

err := game.Do(&bg.BoardGameAction{
    Team: "TeamA",
    ActionType: "SwitchUnits",
    MoreDetails: SwitchUnitsActionDetails{
        UnitRow: 0,
        UnitColumn: 0,
        SwitchUnitRow: 1,
        SwitchUnitColumn: 0,
    },
})

To move a unit do the following action:

err := game.Do(&bg.BoardGameAction{
    Team: "TeamA",
    ActionType: "MoveUnit",
    MoreDetails: MoveUnitActionDetails{
        UnitRow: 0,
        UnitColumn: 0,
        MoveRow: 1,
        MoveColumn: 0,
    },
})

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

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

Documentation

Index

Constants

View Source
const (
	BoardSize            = 10
	QuickBattleBoardSize = 8
)
View Source
const (
	ActionSwitchUnits = "SwitchUnits"
	ActionMoveUnit    = "MoveUnit"
	ActionToggleReady = "ToggleReady"
)

Action types

View Source
const (
	VariantClassic     = "Classic"     // normal Stratego
	VariantQuickBattle = "QuickBattle" // 8x8 quick play Stratego
)

Stratego Variants

Variables

View Source
var UnitTyes = []string{flag, bomb, spy, scout, miner, sergeant, lieutenant, captain, major, colonel, general, marshal}

UnitTyes ordered in ascending order by battle winner

Functions

This section is empty.

Types

type Battle added in v1.1.0

type Battle struct {
	MoveUnitActionDetails
	AttackingUnit, AttackedUnit Unit
	WinningTeam                 string
}

type Board

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

func NewEmptyBoard

func NewEmptyBoard(variant string) (*Board, error)

func NewRandomBoard

func NewRandomBoard(teams []string, variant string, random *rand.Rand) (*Board, error)

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 MoveUnitActionDetails

type MoveUnitActionDetails struct {
	UnitRow, UnitColumn int
	MoveRow, MoveColumn int
}

type StategoSnapshotData

type StategoSnapshotData struct {
	Board       [][]Unit
	Battle      *Battle
	JustBattled bool
	Started     bool
	Ready       map[string]bool
	Variant     string
}

StategoSnapshotData is the game data unique to Statego

type Stratego

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

func NewStratego

func NewStratego(options *bg.BoardGameOptions) (*Stratego, error)

func (*Stratego) Do

func (s *Stratego) Do(action *bg.BoardGameAction) error

func (*Stratego) GetBGN

func (s *Stratego) GetBGN() *bgn.Game

func (*Stratego) GetSnapshot

func (s *Stratego) GetSnapshot(team ...string) (*bg.BoardGameSnapshot, error)

type StrategoMoreInfo added in v1.1.6

type StrategoMoreInfo struct {
	Variants []string
}

type StrategoMoreOptions

type StrategoMoreOptions struct {
	Seed    int64
	Variant string
}

StrategoMoreOptions are the additional options for creating a game of Stratego

type SwitchUnitsActionDetails

type SwitchUnitsActionDetails struct {
	UnitRow, UnitColumn             int
	SwitchUnitRow, SwitchUnitColumn int
}

type Unit

type Unit struct {
	Type string
	Team *string
}

func NewUnit

func NewUnit(typ, team string) *Unit

func Water

func Water() *Unit

func (*Unit) Attack

func (u *Unit) Attack(unit *Unit) (winner *Unit, err error)

Jump to

Keyboard shortcuts

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