game

package
v0.0.0-...-0992052 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2017 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//NOHandInit  the starting numbers of cards.
	NOHandInit = 7
)

Variables

View Source
var (
	//BoardPieceAll all the board piece types
	//Cone or Card.
	BoardPieceAll = newBoardPieceAllST()
)

Functions

This section is empty.

Types

type BoardPiece

type BoardPiece uint8

BoardPiece the board piece type card or cone.

func (BoardPiece) IsCard

func (b BoardPiece) IsCard() bool

IsCard checks if the board piece is a Card.

func (BoardPiece) IsCone

func (b BoardPiece) IsCone() bool

IsCone checks if the board piece is cone.

func (BoardPiece) String

func (b BoardPiece) String() string

type BoardPieceAllST

type BoardPieceAllST struct {
	Cone BoardPiece
	Card BoardPiece
}

BoardPieceAllST the singleton of all the board pieces.

func (BoardPieceAllST) All

func (m BoardPieceAllST) All() []BoardPiece

All return all the board piece Card and Cone

func (BoardPieceAllST) Names

func (m BoardPieceAllST) Names() []string

Names returns all the names of the board pieces Card or Cone.

type BoardPieceMove

type BoardPieceMove struct {
	Index  int
	NewPos uint8
	OldPos uint8
	BoardPiece
}

BoardPieceMove a single board piece move.

func CreateBPMoveDish

func CreateBPMoveDish(cardix int, player int, oldPos pos.Card) *BoardPieceMove

CreateBPMoveDish create board piece move that moves a card to the dish.

func (*BoardPieceMove) IsEqual

func (b *BoardPieceMove) IsEqual(o *BoardPieceMove) bool

IsEqual checks is to Board Piece Move is equal.

func (*BoardPieceMove) String

func (b *BoardPieceMove) String() string

type Flag

type Flag struct {
	Players   [2]FlagPlayer
	Positions [2]pos.Card
	ConePos   pos.Cone
	IsWon     bool
	IsMud     bool
	IsFog     bool
}

Flag a flag both players cards connected to a cone.

func FlagsCreate

func FlagsCreate(posCards PosCards, conePos [10]pos.Cone) (flags [9]*Flag)

func NewFlag

func NewFlag(ix int, posCards PosCards, conePos [10]pos.Cone) (f *Flag)

NewFlag creates a flag.

func (*Flag) Copy

func (f *Flag) Copy() (c *Flag)

func (*Flag) Formation

func (f *Flag) Formation(playix int) (formation *card.Formation, strenght int)

Formation calculates the formation and strenght.

func (*Flag) FormationSize

func (f *Flag) FormationSize() (size int)

FormationSize the size of formation 3 or 4.

func (*Flag) HasFormation

func (f *Flag) HasFormation(player int) bool

HasFormation returns true if the player have enough cards to make a formation.

func (*Flag) IsClaimable

func (f *Flag) IsClaimable(player int, deckTroops []card.Troop) (isClaim bool, exCardixs []card.Card)

IsClaimable return true it the player can succesfully claim the flag.

func (*Flag) IsEnvPlayable

func (f *Flag) IsEnvPlayable(player int) bool

IsEnvPlayable returns true if it is possible to play a enviroment tactic card on the flag by the player.

func (*Flag) IsMoralePlayable

func (f *Flag) IsMoralePlayable(player int) bool

IsMoralePlayable returns true if it is possible to play a morale tactic card on the flag by the player.

func (*Flag) IsTroopPlayable

func (f *Flag) IsTroopPlayable(player int) (isPlayable bool)

IsTroopPlayable returns true if it is possible to play a troop on the flag by the player.

func (*Flag) PlayerFormationSize

func (f *Flag) PlayerFormationSize(playerix int) int

func (*Flag) String

func (f *Flag) String() string

type FlagPlayer

type FlagPlayer struct {
	Troops  []card.Troop
	Morales []card.Morale
	Envs    []card.Env
}

FlagPlayer the player in a flag.

func (FlagPlayer) Copy

func (f FlagPlayer) Copy() (c FlagPlayer)

type Game

type Game struct {
	Pos  *Pos
	Hist *Hist
}

Game a battleline game.

func NewGame

func NewGame() (g *Game)

NewGame creates a new battleline game.

func (*Game) GiveUp

func (g *Game) GiveUp(moves []*Move) (winner int)

GiveUp gives up the game.

func (*Game) IsAtBeginningOfHist

func (g *Game) IsAtBeginningOfHist() bool

IsAtBeginningOfHist checks is a game position is at the begining of history.

func (*Game) LoadHist

func (g *Game) LoadHist(hist *Hist)

LoadHist loads a old history in to a game. the game postion is not upddate, use resume or scroll to use the history.

func (*Game) Move

func (g *Game) Move(move *Move) (winner int, failedClaimsExs [9][]card.Card)

Move makes a move.

func (*Game) Pause

func (g *Game) Pause(moves []*Move) (winner int)

Pause pauses the game.

func (*Game) Resume

func (g *Game) Resume() (ok bool)

Resume moves a game to the last postion of it history and wait for new moves. Returns ok if the game is not finished.

func (*Game) ScrollBackward

func (g *Game) ScrollBackward() (ok bool)

ScrollBackward scrolls the game position one move back. returns false if at the end.

func (*Game) ScrollForward

func (g *Game) ScrollForward() (winner int, ok bool)

ScrollForward scrolls the game postion one move forward using history

func (*Game) Start

func (g *Game) Start(playerIDs [2]int, dealer int)

Start starts a game.

type Hist

type Hist struct {
	Moves     []*Move
	PlayerIDs [2]int
	Time      time.Time
}

Hist the history of a battleline game, every move made.

func (*Hist) AddMove

func (h *Hist) AddMove(move *Move)

AddMove adds a move to history.

func (*Hist) Copy

func (h *Hist) Copy() (copy *Hist)

Copy makes a copy of game history

func (*Hist) IsEqual

func (h *Hist) IsEqual(o *Hist) bool

IsEqual checks if two moves are equal.

func (*Hist) LastMove

func (h *Hist) LastMove() (move *Move)

LastMove return last move maybe nil

func (*Hist) RemovePause

func (h *Hist) RemovePause() bool

RemovePause remove the last move if it is pause.

func (*Hist) Winner

func (h *Hist) Winner() (winner int)

Winner returns winner may be NoPlayer if game is paused.

type Move

type Move struct {
	Mover int
	MoveType
	Moves []*BoardPieceMove
}

Move a battleline move.

func CreateMoveCone

func CreateMoveCone(flagixs []int, mover int) *Move

CreateMoveCone creates a cone move.

func CreateMoveDeserter

func CreateMoveDeserter(oldPos pos.Card, killedCardix, mover int, dishGuileMove *BoardPieceMove) (move *Move)

CreateMoveDeserter creates a deserter move.

func CreateMoveDouble

func CreateMoveDouble(oldPos, newPos pos.Card, moveCardix, mover int, dishGuileMove *BoardPieceMove) (move *Move)

CreateMoveDouble creates a redeploy or traitor move.

func CreateMoveGivUp

func CreateMoveGivUp(conePos [10]pos.Cone, mover int) *Move

CreateMoveGivUp creates a give up move

func CreateMoveHand

func CreateMoveHand(cardix, flagix, mover int) (move *Move)

CreateMoveHand creates a card move from the hand to a flag.

func CreateMoveScout

func CreateMoveScout(dishMove, deckMove *BoardPieceMove, mover int) (move *Move)

CreateMoveScout creates a scout move.

func CreateMoveScoutReturn

func CreateMoveScoutReturn(tacixs, troopixs []int, mover int) *Move

CreateMoveScoutReturn creates a scout return move.

func NewMove

func NewMove(mover int, moveType MoveType) (move *Move)

NewMove create a Move with out any board piece moves.

func (*Move) Copy

func (move *Move) Copy() (copy *Move)

Copy makes a copy of move.

func (*Move) GetMoverAndType

func (move *Move) GetMoverAndType() (int, MoveType)

GetMoverAndType returns mover and move type. Works with nil.

func (*Move) IsEqual

func (move *Move) IsEqual(o *Move) bool

IsEqual checks if two moves are equal.

func (*Move) String

func (move *Move) String() string

type MoveType

type MoveType uint8

MoveType a move type Cone,Hand,Init,Deck ... WARNING json of slice of uint8 behaves different that a single value see card or pos implementation if that is need.

func (MoveType) HasNext

func (m MoveType) HasNext() bool

HasNext true if the game continues after this move.

func (MoveType) IsHand

func (m MoveType) IsHand() bool

IsHand returns true if moveType is hand or scout1

func (MoveType) IsPause

func (m MoveType) IsPause() bool

IsPause is the move the pause move.

func (MoveType) IsScout

func (m MoveType) IsScout() bool

IsScout returns true if the move is part of the scout move. play scout and draw one card, draw second card and draw 3 card.

func (MoveType) Next

func (m MoveType) Next(mover int) (moveType MoveType, nextMover int)

Next returns the move type that follow.

func (MoveType) String

func (m MoveType) String() string

type MoveTypeAllST

type MoveTypeAllST struct {
	Init        MoveType
	Cone        MoveType
	Deck        MoveType
	Hand        MoveType
	Scout1      MoveType
	Scout2      MoveType
	Scout3      MoveType
	ScoutReturn MoveType
	GiveUp      MoveType
	Pause       MoveType
	None        MoveType
}

MoveTypeAllST All the move types.

var (
	//MoveTypeAll all the move types
	MoveTypeAll MoveTypeAllST
)

func (MoveTypeAllST) All

func (m MoveTypeAllST) All() []MoveType

All returns all the move types.

func (MoveTypeAllST) Names

func (m MoveTypeAllST) Names() []string

Names returns all the move types name.

type Pos

type Pos struct {
	CardPos [71]pos.Card
	ConePos [10]pos.Cone

	PlayerReturned int
	CardsReturned  [2]card.Card

	LastMoveType MoveType
	LastMover    int
	LastMoveIx   int
}

Pos is a battleline game position.

func NewPos

func NewPos() (g *Pos)

NewPos creates a new postion.

func (*Pos) AddMove

func (g *Pos) AddMove(gameMove *Move) (winner int)

AddMove adds a move to the postion.

func (*Pos) CalcMoves

func (g *Pos) CalcMoves() (moves []*Move)

CalcMoves calulates all the possible moves for the postion.

func (*Pos) IsEqual

func (g *Pos) IsEqual(o *Pos) bool

IsEqual check if two postion is equal.

func (*Pos) RemoveMove

func (g *Pos) RemoveMove(gameMove, beforeGameMove *Move)

RemoveMove removes a move from postion.

func (*Pos) RemovePause

func (g *Pos) RemovePause(lastMoveType MoveType, lastMover int)

RemovePause removes a pause move. Assume pause is always after initMove. Arg: lastMoveType the new last move type. Arg: lastMover the new last mover.

func (*Pos) String

func (g *Pos) String() string

type PosCards

type PosCards [][]card.Card

PosCards cards sorted according to their current position

func NewPosCards

func NewPosCards(cardPos [71]pos.Card) (posCards PosCards)

NewPosCards creates a list of cards for every postion.

func (PosCards) Cards

func (posCards PosCards) Cards(posCard pos.Card) []card.Card

Cards return the cards belong to a position.

func (PosCards) SimDeckTroops

func (posCards PosCards) SimDeckTroops() (deckTroops []card.Troop)

SimDeckTroops returns the cards in the deck used to evalue flag claim. deck plus the cards on the hands.

func (PosCards) SortedCards

func (posCards PosCards) SortedCards(posCard pos.Card) (sortedCards *card.Cards)

SortedCards returns the cards belonging to a postion sorted after type and the troops is sorted after strenght strongest first.

type View

type View uint8

View a view of the gane position.

func (View) DontSeePos

func (v View) DontSeePos(position pos.Card) (dont bool)

DontSeePos return true if the position is not possible to see, by the viewer.

func (View) IsPlayer

func (v View) IsPlayer() bool

IsPlayer return true if the view is a player.

func (View) IsViewSeePlayer

func (v View) IsViewSeePlayer(player int) (dont bool)

IsViewSeePlayer return true if the viewer can see the players card.

func (View) Playerix

func (v View) Playerix() int

Playerix returns the player index if the view is a player else pos.NoPlayer.

type ViewAllST

type ViewAllST struct {
	Players   [2]View
	Spectator View
	God       View
}

ViewAllST All the Views singleton

var (
	//ViewAll all views.
	ViewAll ViewAllST
)

func (ViewAllST) All

func (v ViewAllST) All() []View

All returns all views.

type ViewPos

type ViewPos struct {
	*Pos
	View
	Winner   int
	NoTacs   [2]int
	NoTroops [2]int
	Moves    []*Move
}

ViewPos a view of a game postion.

func NewViewPos

func NewViewPos(gamePos *Pos, view View, winner int) (v *ViewPos)

NewViewPos create new view of a game postion.

func (*ViewPos) Copy

func (v *ViewPos) Copy() (c *ViewPos)

Copy copys viewPos.

func (*ViewPos) IsEqual

func (v *ViewPos) IsEqual(o *ViewPos) bool

IsEqual checks if two views are equal.

Directories

Path Synopsis
Package card contain the cards of battleline.
Package card contain the cards of battleline.

Jump to

Keyboard shortcuts

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