cards

package module
v0.0.0-...-2019472 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2014 License: Apache-2.0 Imports: 4 Imported by: 1

README

cards provides methods to abstract operations on decks of playing cards. See the War example.

GoDoc


License

Copyright 2014 Jason Hall

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Documentation

Overview

Package cards provides methods for common operations on a deck of cards

Index

Constants

This section is empty.

Variables

View Source
var Ranks = 13

The number of ranks (values) per suit. By default this is 13

View Source
var Suits = []rune{'♠', '♡', '♢', '♣'}

The possible suits to use. By default this is {'♠', '♡', '♢', '♣'}

Functions

This section is empty.

Types

type Card

type Card int

Card represents a Card in a Deck

func (Card) Rank

func (c Card) Rank() int

Rank returns the value of the card, for comparison with the rank of other cards.

func (Card) String

func (c Card) String() string

String returns a string representation of the card, e.g., "4♡", "A♠"

With the default value of Ranks, the rank of the card will be returned starting at 2 until 10, then J, Q, K, A.

If Ranks has been modified from its default, the zero-indexed rank will be returned instead.

func (Card) Suit

func (c Card) Suit() Suit

Suit returns the suit of the card

type Deck

type Deck []Card

Deck represents a deck of cards

func NewDeck

func NewDeck() Deck

NewDeck returns a new deck of cards, in order

One card will be included of each suit and rank, for a total of Ranks*len(Suits) cards

func Riffle

func Riffle(d1, d2 Deck) Deck

Combines two decks using a strictly mechanical riffle, alternating a card from each deck

func (*Deck) Add

func (dp *Deck) Add(cards ...Card)

Add adds card(s) to the bottom of the deck

func (Deck) Cut

func (d Deck) Cut() (Deck, Deck)

Cut splits the deck into two decks of equal size

func (Deck) Empty

func (d Deck) Empty() bool

Empty returns whether the deck is empty

func (Deck) Shuffle

func (d Deck) Shuffle()

Shuffle randomizes the order of the cards in the deck

func (*Deck) Sort

func (dp *Deck) Sort()

Sort sorts the deck into the same order it was in when it was created

func (*Deck) Top

func (dp *Deck) Top() *Card

Top deals the top card from the deck, removing it from the deck

func (*Deck) TopN

func (dp *Deck) TopN(n int) []Card

TopN deals the top n cards from the deck

If the deck does not have n cards, it will return all its cards and become empty

type Suit

type Suit int

Suit represents the Suit of the card, one of Suits

func (Suit) String

func (s Suit) String() string

String returns the string representation of the card, e.g., "Hearts"

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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