engine

package
v0.0.0-...-9eb930a Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const EndedPlayerId int = -2
View Source
const ErrorPlayerId int = -3
View Source
const NotStartedPlayerId int = -1

Variables

View Source
var StandardDeck []Card = newStandardDeck()

Functions

func NumericCompare

func NumericCompare(a, b Card) int

Compares cards by their ranks and suits directly without game specific rules.

Types

type Card

type Card struct {
	Suit Suit
	Rank Rank
}
var ErrorCard Card = Card{Suit: ErrorSuit, Rank: ErrorRank}

func (Card) String

func (card Card) String() string

type CardComparator

type CardComparator interface {
	Compare(a, b Card) int
}
var BasicComparator CardComparator = CardComparatorImpl{
	// contains filtered or unexported fields
}

type CardComparatorImpl

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

func (CardComparatorImpl) Compare

func (comparator CardComparatorImpl) Compare(a, b Card) int

CardComparatorImpl implements the CardComparator interface. It uses a function to compare two cards and can chain to another comparator. If the compareFunc returns _terminate, it stops the comparison and returns the result. If it returns _continue, it passes the comparison to the next comparator in the chain.

type CardCompare

type CardCompare func(a, b Card) int

type Deck

type Deck struct {
	Cards []Card
}

func NewDeck

func NewDeck() *Deck

func (*Deck) AddCard

func (deck *Deck) AddCard(card Card)

func (*Deck) DrawCard

func (deck *Deck) DrawCard() (Card, error)

func (*Deck) String

func (deck *Deck) String() string

type Game

type Game struct {
	DrawPile    *Deck
	InPlayPile  *Deck
	DiscardPile *Deck
	Hands       []Hand
	// contains filtered or unexported fields
}

func NewGame

func NewGame(numOfPlayers int) *Game

func (*Game) CurrentHand

func (game *Game) CurrentHand() Hand

func (*Game) Init

func (game *Game) Init()

func (*Game) PlayHand

func (game *Game) PlayHand(play Play) PlayResult

func (*Game) String

func (game *Game) String() string

type Hand

type Hand struct {
	Id       int
	InHand   []Card
	FaceUp   []Card
	FaceDown []Card
}

type Play

type Play struct {
	Hand *Hand
	Card Card
}

type PlayResult

type PlayResult struct {
	Round        int
	Success      bool
	Status       Status
	NextPlayerId int
}

type Rank

type Rank uint8
const (
	ErrorRank Rank = 0
	Ace       Rank = 1
	Two       Rank = 2
	Three     Rank = 3
	Four      Rank = 4
	Five      Rank = 5
	Six       Rank = 6
	Seven     Rank = 7
	Eight     Rank = 8
	Nine      Rank = 9
	Ten       Rank = 10
	Jack      Rank = 11
	Queen     Rank = 12
	King      Rank = 13
	Joker     Rank = math.MaxUint8
)

func (Rank) String

func (rank Rank) String() string

type Status

type Status int
const (
	Success          Status = 0
	Error            Status = 1
	Play_WrongPlayer Status = 101
	Play_CardTooLow  Status = 102
	Hand_NotFound    Status = 201
	Hand_NotInHand   Status = 202
	Hand_NotFaceUp   Status = 203
	Hand_NotFaceDown Status = 204
)

type Suit

type Suit uint8
const (
	ErrorSuit  Suit = 0
	Club       Suit = 1
	Diamond    Suit = 2
	Heart      Suit = 3
	Spade      Suit = 4
	JokerSmall Suit = 5
	JokerLarge Suit = 6
)

func (Suit) String

func (suit Suit) String() string

Jump to

Keyboard shortcuts

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