gamestate

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 10, 2020 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const MaxHandSize = 10

MaxHandSize is the maximum hand size in the game

View Source
const MaxPlayers = 6

MaxPlayers is the most players the game supports

View Source
const (
	RulesText = `` /* 1253-byte string literal not displayed */

)

Variables

View Source
var CardHelpText = [...]string{
	Fighter:     fmt.Sprintf("A Warship with %d base strength", CardStrengths[Fighter]),
	Escort:      fmt.Sprintf("A Warship with %d base strength", CardStrengths[Escort]),
	Frigate:     fmt.Sprintf("A Warship with %d base strength", CardStrengths[Frigate]),
	Destroyer:   fmt.Sprintf("A Warship with %d base strength", CardStrengths[Destroyer]),
	Cruiser:     fmt.Sprintf("A Warship with %d base strength", CardStrengths[Cruiser]),
	Battleship:  fmt.Sprintf("A Warship with %d base strength", CardStrengths[Battleship]),
	Dreadnaught: fmt.Sprintf("A Warship with %d base strength", CardStrengths[Dreadnaught]),
	Tactician:   "Doubles the strength of all Warships (black cards).",
	Probe:       "Has N strength where N is the number of Probes you've played this battle.",
	Singularity: "Destroys all copies of the warship with the highest base strength.",
	Tesseract:   "Immediately ends the battle. The current leading player wins.",
	Asteroids:   "All warships have effective strength 1; Cancels the effects of Solar Wind when played.",
	SolarWind:   "The warships in play with the highest base strength gain a +3 strength bonus; Cancels the effects of Asteroids when played.",
	Hologram:    "When played, return the warship you most recently played to your hand.",
}
View Source
var CardNames = [...]string{
	Fighter:     "Fighter",
	Escort:      "Escort",
	Frigate:     "Frigate",
	Destroyer:   "Destroyer",
	Cruiser:     "Cruiser",
	Battleship:  "Battleship",
	Dreadnaught: "Dreadnaught",
	Tactician:   "Tactician",
	Probe:       "Probe",
	Singularity: "Singularity",
	Tesseract:   "Tesseract",
	Asteroids:   "Asteroids",
	SolarWind:   "Solar Wind",
	Hologram:    "Hologram",
}
View Source
var CardStrengths = [...]int{
	Fighter:     1,
	Escort:      2,
	Frigate:     3,
	Destroyer:   4,
	Cruiser:     5,
	Battleship:  6,
	Dreadnaught: 10,
	Tactician:   0,
	Probe:       1,
	Singularity: 0,
	Tesseract:   0,
	Asteroids:   0,
	SolarWind:   0,
	Hologram:    0,
}
View Source
var CardText = [...]string{
	Fighter:     "1",
	Escort:      "2",
	Frigate:     "3",
	Destroyer:   "4",
	Cruiser:     "5",
	Battleship:  "6",
	Dreadnaught: "10",
	Tactician:   "x2",
	Probe:       "N",
	Singularity: ".",
	Tesseract:   "#",
	Asteroids:   "=",
	SolarWind:   "~",
	Hologram:    "@",
}

Functions

This section is empty.

Types

type Card

type Card uint8

Card represents a single playing card

const (
	NoCard Card = iota
	Fighter
	Escort
	Frigate
	Destroyer
	Cruiser
	Battleship
	Dreadnaught
	Tactician
	Probe
	Singularity
	Tesseract
	Asteroids
	SolarWind
	Hologram
)

type CardList

type CardList []Card

CardList is a collection of ordered cards

func NewDeck

func NewDeck() CardList

func (*CardList) PlayCardInto

func (h *CardList) PlayCardInto(cardIndex int, destination *CardList)

PlayCardInto removes the card at `cardIndex` from `h` and inserts it into destination (at the end)

func (*CardList) RemoveAll

func (h *CardList) RemoveAll(card Card)

func (*CardList) RemoveCardAt

func (h *CardList) RemoveCardAt(cardIndex int)

func (CardList) Same

func (h CardList) Same(other CardList) bool

Same returns true if the cardlist contains the same cards in the same order as the other cardlist

func (CardList) Score

func (h CardList) Score(g *GameState) int

Score computes the score of this set of cards

func (CardList) Shuffle

func (h CardList) Shuffle()

type CardType

type CardType uint8
const (
	Warship CardType = iota
	Special
	Battlefield
)

func (CardType) String

func (c CardType) String() string

type GameState

type GameState struct {
	Deck CardList

	Players []Player

	Phase

	Turn int // if Phase is WaitingOnPlayer, this is the index of the player

	// if a global modifier card has been played, it will be this
	Battlefield Card
}

GameState holds the state of the entire game

func (*GameState) AddPlayer

func (g *GameState) AddPlayer(name string)

func (*GameState) Advance

func (g *GameState) Advance()

Advance makes all of the AI players take a turn

func (*GameState) CensoredCopy

func (g *GameState) CensoredCopy(playerNum int) GameState

CensoredCopy copies the state of the game, but includes only information that should be available to the provided player.

NOTE: uncensored elements of the copy may share storage with the original

func (*GameState) ClearTable

func (g *GameState) ClearTable()

ClearTable resets the game state between battles

func (*GameState) DealCards

func (g *GameState) DealCards()

DealCards distributes cards from the deck to all players

func (*GameState) FinishBattle

func (g *GameState) FinishBattle()

FinishBattle scores a battle, awards a victory to the winning player, and resets the game state

func (*GameState) HandleHologram

func (g *GameState) HandleHologram(playerNum int)

func (*GameState) HandleSingularity

func (g *GameState) HandleSingularity()

func (*GameState) HandleTesseract

func (g *GameState) HandleTesseract()

func (*GameState) IsPlayersTurn

func (g *GameState) IsPlayersTurn(playerNum int) bool

func (*GameState) MakeDeck

func (g *GameState) MakeDeck()

MakeDeck initializes a new deck of cards for the game

func (*GameState) Pass

func (g *GameState) Pass(playerNum int)

func (*GameState) PlayerMustPass

func (g *GameState) PlayerMustPass(playerNum int) bool

func (*GameState) Setup

func (g *GameState) Setup()

func (*GameState) SetupPlayers

func (g *GameState) SetupPlayers(players int)

SetupPlayers creates the given number of players

func (*GameState) SetupWithPlayers

func (g *GameState) SetupWithPlayers(players int)

SetupWithPlayers initializes all players' hands

func (*GameState) StartBattle

func (g *GameState) StartBattle()

func (*GameState) StrongestWarshipPlayed

func (g *GameState) StrongestWarshipPlayed() Card

func (*GameState) TakeTurn

func (g *GameState) TakeTurn(playerNum int, playsCardAt int)

func (*GameState) Winners

func (g *GameState) Winners() []int

Winner returns the numbers of the players who won the battle. It can only be called from within the FinishingBattle phase. It only returns multiple results in the case of a tie

type Phase

type Phase uint

Phase is a discrete state of the game, such as "waiting for players" or "waiting for player 2"

const (
	Lobby Phase = iota
	Dealing
	WaitingOnPlayer
	FinishingBattle
	FinishingGame
)

type Player

type Player struct {
	Name string
	// cards still in this player's hand
	Hand CardList
	// cards that this player has played
	Played CardList
	// whether this player has passed this battle or not
	IsPassing bool
	// how many battles this player has won
	Victories int
}

Player is the state of a single player within the game

func (*Player) PlayCardAt

func (p *Player) PlayCardAt(index int)

PlayCardAt moves the card at the specified index in this player's hand into the Played slice

Jump to

Keyboard shortcuts

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