acquire

package module
v0.0.0-...-7fdf73f Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2018 License: MIT Imports: 11 Imported by: 0

README

Acquire

A library written in Go implementing Sid Sackson's board game. Click here for game instructions.

Player actions flow

player actions flow diagram

Documentation

Overview

Package acquire manages the flow and status of an acquire game. It acts like a finite state machine (FSM), in which received inputs modify machine state

Index

Constants

View Source
const (
	// Returned when action not allowed at current state
	ActionNotAllowed = "action_%s_not_allowed_expecting_%s"
	// Returned when stock shares from a corporation not on board are not buyable
	StockSharesNotBuyable = "stock_shares_not_buyable"
	// Returned when not enough stock shares of a corporation to buy
	NotEnoughStockShares = "not_enough_stock_shares"
	// Returned when tile temporarily unplayable
	TileTemporarilyUnplayable = "tile_temporarily_unplayable"
	// Returned when tile permanently unplayable
	TilePermanentlyUnplayable = "tile_permanently_unplayable"
	// Returned when player has not enough cash to buy stock shares
	NotEnoughCash = "not_enough_cash"
	// Returned when player can not buy more than 3 stock shares per round
	TooManyStockSharesToBuy = "too_many_stock_shares_to_buy"
	// Returned when some corporation names are repeated
	CorpNamesNotUnique = "corp_names_not_unique"
	// Returned when corporations classes do not fit rules
	WrongNumberCorpsClass = "wrong_number_corps_class"
	// Returned when corporation is already on board and cannot be founded
	CorporationAlreadyOnBoard = "corporation_already_on_board"
	// Returned when there must be between 3 and 6 players
	WrongNumberPlayers = "wrong_number_players"
	// Returned when player does not own stock shares of a certain corporation
	NoCorporationSharesOwned = "no_corporation_shares_owned"
	// Returned when player does not own enough stock shares of a certain corporation
	NotEnoughCorporationSharesOwned = "not_enough_corporation_shares_owned"
	// Returned when player does not have tile on hand
	TileNotOnHand = "tile_not_on_hand"
	// Returned when corporation is not the acquirer in a merge
	NotAnAcquirerCorporation = "not_an_acquirer_corporation"
	// Returned when number of stock shares is not even in a trade
	TradeAmountNotEven = "trade_amount_not_even"
)

Error messages returned by the game

Variables

This section is empty.

Functions

This section is empty.

Types

type Game

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

Game stores state of game elements and provides methods to control game flow

func New

func New(players map[int]interfaces.Player, optional Optional) (*Game, error)

New initialises a new Acquire game

func (*Game) AreEndConditionsReached

func (g *Game) AreEndConditionsReached() bool

AreEndConditionsReached checks if game end conditions are reached

func (*Game) Board

func (g *Game) Board() interfaces.Board

Board returns game's board instance

func (*Game) BuyStock

func (g *Game) BuyStock(buys map[interfaces.Corporation]int) error

BuyStock buys stock from corporations

func (*Game) ClaimEndGame

func (g *Game) ClaimEndGame() *Game

ClaimEndGame allows the current player to claim end game This can be done at any time. After announcing that the game is over, the player may finish his/her turn.

func (*Game) Corporations

func (g *Game) Corporations() [7]interfaces.Corporation

Corporations returns an array with all seven corporations

func (*Game) CurrentPlayer

func (g *Game) CurrentPlayer() interfaces.Player

CurrentPlayer returns player currently in play

func (*Game) FoundCorporation

func (g *Game) FoundCorporation(corp interfaces.Corporation) error

FoundCorporation founds a new corporation

func (*Game) GameStateName

func (g *Game) GameStateName() string

GameStateName returns game's current state

func (*Game) IsCorporationDefunct

func (g *Game) IsCorporationDefunct(corp interfaces.Corporation) bool

IsCorporationDefunct return true if the passed corporation is in a merge process and will disappear from the board after that merge is complete, false otherwise

func (*Game) IsLastRound

func (g *Game) IsLastRound() bool

IsLastRound returns if the current round will be the last one or not

func (*Game) IsTilePlayable

func (g *Game) IsTilePlayable(tl interfaces.Tile) bool

IsTilePlayable returns false if the passed tile is either temporary or permanently unplayable, true otherwise

func (*Game) PlayTile

func (g *Game) PlayTile(tl interfaces.Tile) error

PlayTile puts the given tile on board and triggers related actions

func (*Game) Player

func (g *Game) Player(playerNumber int) interfaces.Player

Player returns player with passed number

func (*Game) RemovePlayer

func (g *Game) RemovePlayer(pl interfaces.Player)

RemovePlayer gets the received player and removes him/her from the game because the player has left the game. All player's assets are returned to its respective origin sets. If the removed player was in his/her turn, turn passes to the next player.

func (*Game) Round

func (g *Game) Round() int

Round returns the current round number

func (*Game) SellTrade

func (g *Game) SellTrade(sell map[interfaces.Corporation]int, trade map[interfaces.Corporation]int) error

SellTrade sells and trades stock shares from defunct corporations

func (*Game) TiedCorps

func (g *Game) TiedCorps() []interfaces.Corporation

TiedCorps returns all corporations that are tied in a merge

func (*Game) UntieMerge

func (g *Game) UntieMerge(acquirer interfaces.Corporation) error

UntieMerge resolves a tied merge selecting which corporation will be the acquirer, marking the rest as defunct

type Optional

type Optional struct {
	Board        interfaces.Board
	Corporations [7]interfaces.Corporation
	Tileset      interfaces.Tileset
	StateMachine interfaces.StateMachine
}

Optional is a struct which stores the fields that are optional when creating a new Game instance with the New() method.

Directories

Path Synopsis
Package board holds the struct and related methods that model the game board
Package board holds the struct and related methods that model the game board
Package corporation contains the model Corporation and attahced methods which manages corporations in game
Package corporation contains the model Corporation and attahced methods which manages corporations in game
Package interfaces holds the declaration of all the interfaces used through the Acquire library.
Package interfaces holds the declaration of all the interfaces used through the Acquire library.
Package mocks holds all mock implementations of the interfaces used by the Acquire library
Package mocks holds all mock implementations of the interfaces used by the Acquire library
Package player containst the struct Player and attached methods which manages player status in game.
Package player containst the struct Player and attached methods which manages player status in game.
Package tile contains the struct and related methods which models a tile.
Package tile contains the struct and related methods which models a tile.
Package tileset holds the Tileset struct and related methods
Package tileset holds the Tileset struct and related methods

Jump to

Keyboard shortcuts

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