battleline

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

Documentation

Overview

Package battleline contains the card game battleline.

Index

Constants

View Source
const (
	//NOFlags is the numbers of flags
	NOFlags = 9
	//NOHandInit number of cards in init hand.
	NOHandInit = 7
	//SMPass is the move pass
	SMPass = -1
	//SMGiveUp is the move give up
	SMGiveUp = -2
)
View Source
const (
	//TURNFlag player claim flags.
	TURNFlag = 0
	//TURNHand player plays a card from hand.
	TURNHand = 1
	//TURNScout2 player picks second of tree scout cards.
	TURNScout2 = 2
	//TURNScout1 player picks last of tree scout cards.
	TURNScout1 = 3
	//TURNScoutR player return 3 cards to decks.
	TURNScoutR = 4
	//TURNDeck playe pick a card from a deck.
	TURNDeck = 5
	//TURNFinish game is over.
	TURNFinish = 6
	//TURNQuit player quit game is over.
	TURNQuit = 7

	//DECKTac the tactic card deck.
	DECKTac = 1
	//DECKTroop the troop card deck.
	DECKTroop = 2
	//REDeployDishix
	REDeployDishix = -1
)

Variables

This section is empty.

Functions

func GobRegistor

func GobRegistor()

GobRegistor register all move interfaces.

func Save

func Save(game *Game, file *os.File, savePos bool) (err error)

Save save a game. Warning it set gamePos to nil before saving with savePos false, the pos is return after save.

Types

type Dish

type Dish TroopTac

Dish a container for dished troops and tactics.

func NewDish

func NewDish() (dish *Dish)

func (*Dish) Copy

func (dish *Dish) Copy() *Dish

func (*Dish) DishCard

func (dish *Dish) DishCard(cardix int)

DishCard add card to the dish.

func (*Dish) Equal

func (dish *Dish) Equal(other *Dish) bool

func (*Dish) String

func (dish *Dish) String() (txt string)

type Game

type Game struct {
	PlayerIds     [2]int
	Pos           *GamePos
	InitDeckTac   deck.Deck
	InitDeckTroop deck.Deck
	Starter       int
	Moves         [][2]int
}

Game The struct that holds all information about a game

func Load

func Load(file *os.File) (game *Game, err error)

Load load a game.

func New

func New(playerIds [2]int) (game *Game)

func (*Game) CalcPos

func (game *Game) CalcPos()

CalcPos calculate the current posistion from the initial position and the moves. The new position replace the old position.

func (*Game) Equal

func (game *Game) Equal(other *Game) (equal bool)

func (*Game) GameMoveLoop

func (game *Game) GameMoveLoop(posFunc func(
	gameMoveix int,
	prePos, postPos *GamePos,
	moveCardix, dealtix, moveix int,
	move Move,
	isGiveUp, isPass bool,
	claimFailExs [9][]int,
	mudDishixs []int,
))

func (*Game) Move

func (game *Game) Move(move int) (dealtix int, claimsFailExs [9][]int)

Move makes a none card move. Claim flags, Getting or returning cards to deck. dealtix the card in deal move. claimFailMap the failed claim map in a claim flag move. Is never nil.

func (*Game) MoveHand

func (game *Game) MoveHand(cardix int, moveix int) (dealtix int, dishixs []int)

MoveHand play a card from hand. dealtix the delt cardix when the scout card is played. dishixs the dished cards witch may results of a redeploy or desert of the mud card. in case of redeploy it also holds the redeploy card if it is dished.

func (*Game) Pass

func (game *Game) Pass()

Pass player choose not to make a move.

func (*Game) Quit

func (game *Game) Quit(playerix int)

Quit handle player giving up.

func (*Game) ResetGame

func (game *Game) ResetGame() (moves [][2]int)

ResetGame reset the game to the first position and returns and clear the moves.

func (*Game) Start

func (game *Game) Start(starter int)

type GamePos

type GamePos struct {
	Flags     [NOFlags]*flag.Flag
	Dishs     [2]*Dish
	Hands     [2]*Hand
	DeckTac   deck.Deck
	DeckTroop deck.Deck
	Turn
	Info string
}

GamePos a game position.

func NewGamePos

func NewGamePos() *GamePos

func (*GamePos) Copy

func (pos *GamePos) Copy() (c *GamePos)

func (*GamePos) Equal

func (pos *GamePos) Equal(other *GamePos) (equal bool)

type Hand

type Hand TroopTac

Hand a battleline hand.

func NewHand

func NewHand() (hand *Hand)

func (*Hand) Copy

func (hand *Hand) Copy() *Hand

func (*Hand) Draw

func (hand *Hand) Draw(cardix int)

Draw adds card to hand.

func (*Hand) Equal

func (hand *Hand) Equal(other *Hand) bool

func (*Hand) Play

func (hand *Hand) Play(cardix int)

Play removes a card from the hand.

func (*Hand) PlayMulti

func (hand *Hand) PlayMulti(cardixs []int)

PlayMulti removes cards from hand.

func (*Hand) Size

func (hand *Hand) Size() int

Size the total number of cards in hand.

func (*Hand) String

func (hand *Hand) String() (txt string)

type Move

type Move interface {
	MoveEqual(Move) bool
	Copy() Move
}

Move a interface for moves.

type MoveCardFlag

type MoveCardFlag struct {
	Flagix   int
	JsonType string
}

MoveCardFlag the place a card on a flag move. Its is just int for the flag index.

func NewMoveCardFlag

func NewMoveCardFlag(flagix int) *MoveCardFlag

func (MoveCardFlag) Copy

func (m MoveCardFlag) Copy() (c Move)

func (MoveCardFlag) MoveEqual

func (m MoveCardFlag) MoveEqual(other Move) (equal bool)

type MoveClaim

type MoveClaim struct {
	Flags    []int
	JsonType string
}

MoveClaim the claim flags move. The slice contain the list of flags to claim.

func NewMoveClaim

func NewMoveClaim(flags []int) *MoveClaim

func (MoveClaim) Copy

func (m MoveClaim) Copy() (c Move)

func (MoveClaim) Equal

func (m MoveClaim) Equal(other MoveClaim) (equal bool)

func (MoveClaim) MoveEqual

func (m MoveClaim) MoveEqual(other Move) (equal bool)

type MoveDeck

type MoveDeck struct {
	Deck     int
	JsonType string
}

MoveDeck the deck move. DECK_TAC or DECK_TROOP

func NewMoveDeck

func NewMoveDeck(deck int) *MoveDeck

func (MoveDeck) Copy

func (m MoveDeck) Copy() (c Move)

func (MoveDeck) MoveEqual

func (m MoveDeck) MoveEqual(other Move) (equal bool)

type MoveDeserter

type MoveDeserter struct {
	Flag     int
	Card     int
	JsonType string
}

MoveDeserter the deserter move. The flag and the index of the card to kill.

func NewMoveDeserter

func NewMoveDeserter(flagix int, cardix int) *MoveDeserter

func (MoveDeserter) Copy

func (m MoveDeserter) Copy() (c Move)

func (MoveDeserter) MoveEqual

func (m MoveDeserter) MoveEqual(other Move) (equal bool)

type MoveRedeploy

type MoveRedeploy struct {
	OutFlag  int
	OutCard  int
	InFlag   int //may be -1 no flag goes to dish.
	JsonType string
}

MoveRedeploy the redeploy move, the flag and card index of the card to move and the destination flag.

func NewMoveRedeploy

func NewMoveRedeploy(outFlagix int, outCardix int, inFlagix int) *MoveRedeploy

func (MoveRedeploy) Copy

func (m MoveRedeploy) Copy() (c Move)

func (MoveRedeploy) MoveEqual

func (m MoveRedeploy) MoveEqual(other Move) (equal bool)

type MoveScoutReturn

type MoveScoutReturn struct {
	Tac      []int
	Troop    []int
	JsonType string
}

MoveScoutReturn the scout return move. The tactic cards and the troop cards. It is first in last out. The first card of the slice will be delt last.

func NewMoveScoutReturn

func NewMoveScoutReturn(tac []int, troop []int) *MoveScoutReturn

func (MoveScoutReturn) Copy

func (m MoveScoutReturn) Copy() Move

func (MoveScoutReturn) Equal

func (m MoveScoutReturn) Equal(other MoveScoutReturn) (equal bool)

func (MoveScoutReturn) MoveEqual

func (m MoveScoutReturn) MoveEqual(other Move) (equal bool)

type MoveTraitor

type MoveTraitor struct {
	OutFlag  int
	OutCard  int
	InFlag   int
	JsonType string
}

MoveTraitor the traitor move, the flag and card index of the card to move and destination flag.

func NewMoveTraitor

func NewMoveTraitor(outFlagix int, outCardix int, inFlagix int) *MoveTraitor

func (MoveTraitor) Copy

func (m MoveTraitor) Copy() (c Move)

func (MoveTraitor) MoveEqual

func (m MoveTraitor) MoveEqual(other Move) (equal bool)

type TroopTac

type TroopTac struct {
	Troops []int
	Tacs   []int
}

func (*TroopTac) Copy

func (hand *TroopTac) Copy() (c *TroopTac)

func (*TroopTac) Equal

func (hand *TroopTac) Equal(other *TroopTac) (equal bool)

type Turn

type Turn struct {
	Player    int
	State     int
	Moves     []Move
	MovesHand map[int][]Move
	MovePass  bool
}

Turn hold the information of a turn, whos turn is it, what kind of turn (State) and the possible moves.

func (*Turn) Copy

func (turn *Turn) Copy() (c *Turn)

func (*Turn) Equal

func (turn *Turn) Equal(other *Turn) (equal bool)

func (*Turn) GetMoveix

func (turn *Turn) GetMoveix(handCardix int, move Move) (ix int)

GetMoveix find the move index.

func (*Turn) Opp

func (turn *Turn) Opp() int

Opp the opponent to the player that have the turn.

Directories

Path Synopsis
Package cards contain the cards of battleline.
Package cards contain the cards of battleline.
flag contains a battleline flag.
flag contains a battleline flag.

Jump to

Keyboard shortcuts

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