game

package
v0.0.0-...-bd7b32e Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const MinResultToConquerNeutralRegion int = 4

Number to beat when attempting to conquer a neutral region.

View Source
const MinResultToSurviveDangerZone = 3

Number to beat when attempting to cross a danger zone.

Variables

This section is empty.

Functions

func ReadBoardFromConfigFile

func ReadBoardFromConfigFile(boardID string) (Board, BoardInfo, error)

Types

type Battle

type Battle struct {
	// If length is one, the battle was a neutral region conquest attempt or danger zone crossing.
	// If length is more than one, the battle was between players.
	Results []Result

	// If the battle is a danger zone crossing: name of the crossed danger zone.
	DangerZone DangerZone
}

Results of a battle between players, an attempt to conquer a neutral region, or an attempt to cross a danger zone.

type Board

type Board map[RegionName]*Region

type BoardInfo

type BoardInfo struct {
	ID                 string
	Name               string
	WinningCastleCount int
	PlayerFactions     []PlayerFaction
}

func GetAvailableBoards

func GetAvailableBoards() ([]BoardInfo, error)

type DangerZone

type DangerZone string

type Game

type Game struct {
	BoardInfo
	// contains filtered or unexported fields
}

func New

func New(
	board Board,
	boardInfo BoardInfo,
	messenger Messenger,
	logger log.Logger,
	customDiceRoller func() int,
) *Game

func (*Game) Run

func (game *Game) Run()

type Messenger

type Messenger interface {
	SendError(to PlayerFaction, err error)
	SendGameStarted(board Board)
	SendOrderRequest(to PlayerFaction, season Season) (succeeded bool)
	SendOrdersConfirmation(factionThatSubmittedOrders PlayerFaction)
	SendOrdersReceived(orders map[PlayerFaction][]Order)
	SendBattleAnnouncement(battle Battle)
	SendBattleResults(battle Battle)
	SendWinner(winner PlayerFaction)
	AwaitOrders(ctx context.Context, from PlayerFaction) ([]Order, error)
	AwaitDiceRoll(ctx context.Context, from PlayerFaction) error
	AwaitSupport(
		ctx context.Context,
		from PlayerFaction,
		embattledRegion RegionName,
	) (supported PlayerFaction, err error)
	ClearMessages()
}

type Modifier

type Modifier struct {
	Type  ModifierType
	Value int

	// Blank, unless Type is ModifierSupport.
	SupportingFaction PlayerFaction `json:",omitempty"`
}

Part of a player's result in a battle.

type ModifierType

type ModifierType uint8
const (
	// Bonus from a random dice roll.
	ModifierDice ModifierType = iota + 1

	// Bonus for the type of unit.
	ModifierUnit

	// Penalty for attacking a neutral or defended forested region.
	ModifierForest

	// Penalty for attacking a neutral or defended castle region.
	ModifierCastle

	// Penalty for attacking across a river, from the sea, or across a transport.
	ModifierWater

	// Bonus for attacking across a danger zone and surviving.
	ModifierSurprise

	// Bonus from supporting player in a battle.
	ModifierSupport
)

Valid values for a result modifier's type.

func (ModifierType) String

func (modifierType ModifierType) String() string

type MoveCycle

type MoveCycle []*Region

type Neighbor

type Neighbor struct {
	Name RegionName

	// Whether a river separates the neighboring regions, or this region is a sea and the neighbor
	// is a land region.
	AcrossWater bool

	// Whether coast between neighboring land regions have cliffs (impassable to ships).
	Cliffs bool

	// If not "": the name of the danger zone that the neighboring region lies across (requires
	// check to pass).
	DangerZone DangerZone `json:",omitempty"`
}

type Order

type Order struct {
	Type OrderType

	// For build orders: the type of unit moved.
	// For all other orders: the type of unit in the ordered region.
	UnitType UnitType

	// For move orders that lost a singleplayer battle or tied a multiplayer battle, and have to
	// fight their way back to their origin region. Must be false when submitting orders.
	Retreat bool

	// The faction of the player that submitted the order.
	Faction PlayerFaction

	// The region where the order was placed.
	Origin RegionName

	// For move and support orders: name of destination region.
	Destination RegionName

	// For move orders with knight units: optional name of second destination region to move to if
	// the first destination was reached.
	SecondDestination RegionName

	// For move orders: name of DangerZone the order tries to pass through, if any.
	ViaDangerZone DangerZone
}

An order submitted by a player for one of their units in a given round.

type OrderType

type OrderType uint8
const (
	// An order for a unit to move from one region to another.
	// Includes internal moves in winter.
	OrderMove OrderType = iota + 1

	// An order for a unit to support battles in adjacent regions.
	OrderSupport

	// For ship unit at sea: an order to transport a land unit across the sea.
	OrderTransport

	// For land unit in unconquered castle region: an order to besiege the castle.
	OrderBesiege

	// For empty player-controlled region in winter: an order to build a unit in the region.
	OrderBuild

	// For region with a player's own unit, in winter: an order to disband the unit, when their
	// current number of units exceeds their max number of units.
	OrderDisband
)

func (OrderType) String

func (orderType OrderType) String() string

type PlayerFaction

type PlayerFaction string

A faction on the board (e.g. green/red/yellow units) controlled by a player.

type Region

type Region struct {
	Name      RegionName
	Neighbors []Neighbor

	// Whether the region is a sea region that can only have ship units.
	Sea bool

	// For land regions: affects the difficulty of conquering the region.
	Forest bool

	// For land regions: affects the difficulty of conquering the region, and the points gained from
	// it.
	Castle bool

	// For land regions: the collection of regions that the region belongs to (affects units gained
	// from conquering).
	Nation string `json:",omitempty"`

	// For land regions that are a starting region for a player faction.
	HomeFaction PlayerFaction `json:",omitempty"`

	// The unit that currently occupies the region (if any).
	Unit opt.Option[Unit]

	// The player faction that currently controls the region.
	ControllingFaction PlayerFaction `json:",omitempty"`

	// For land regions with castles: the number of times an occupying unit has besieged the castle.
	SiegeCount int `json:",omitempty"`
	// contains filtered or unexported fields
}

A region on the board.

type RegionName

type RegionName string

type Result

type Result struct {
	Total int
	Parts []Modifier

	// If result of a move order to the battle: the move order in question, otherwise empty.
	// If the result is part of a danger zone crossing, the order is either a move or support order.
	Order opt.Option[Order]

	// If result of a defending unit in a region: the faction of the defender, otherwise blank.
	DefenderFaction PlayerFaction `json:",omitempty"`
}

Dice and modifier result for a battle.

type Season

type Season uint8

Current season of a round. Affects the type of orders that can be played.

const (
	SeasonWinter Season = iota + 1
	SeasonSpring
	SeasonSummer
	SeasonFall
)

func (Season) String

func (season Season) String() string

type Unit

type Unit struct {
	Type    UnitType
	Faction PlayerFaction
}

A unit on the board, controlled by a player faction.

type UnitType

type UnitType uint8
const (
	// A land unit that gets a +1 modifier in battle.
	UnitFootman UnitType = iota + 1

	// A land unit that moves 2 regions at a time.
	UnitKnight

	// A unit that can move into sea regions and coastal regions.
	UnitShip

	// A land unit that instantly conquers neutral castles, and gets a +1 modifier in attacks on
	// castles.
	UnitCatapult
)

func (UnitType) String

func (unitType UnitType) String() string

Jump to

Keyboard shortcuts

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