https://github.com/presmihaylov/decks
A golang package for creating decks of cards
https://github.com/presmihaylov/decks
deckofcards go golang
Last synced: 10 months ago
JSON representation
A golang package for creating decks of cards
- Host: GitHub
- URL: https://github.com/presmihaylov/decks
- Owner: presmihaylov
- License: bsd-2-clause
- Created: 2019-08-02T06:28:06.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-08-02T08:08:28.000Z (almost 7 years ago)
- Last Synced: 2025-04-05T12:43:57.741Z (about 1 year ago)
- Topics: deckofcards, go, golang
- Language: Go
- Size: 19.5 KB
- Stars: 8
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# decks
Package decks provides a simple API for creating and customizing decks of cards in Go.
## Installation
```
go get github.com/preslavmihaylov/decks
```
## Quickstart
```go
// get a default, ordered deck of 52 cards
d, err := decks.New()
if err != nil {
// handle error
}
// Make sure you specify a random seed before shuffling the deck
rand.Seed(time.Now().UnixNano())
// Shuffle deck of cards
d.Shuffle()
// draw cards
myHand := []decks.Card{}
myHand = append(myHand, d.Draw())
myHand = append(myHand, d.Draw())
// print hand
for _, c := range myHand {
fmt.Println(c)
}
// discard hand
d.InsertBottom(myHand)
```
[Try it on The Go Playground](https://play.golang.org/p/Jw9jvqQhtKc)
Check out the [full documentation](https://godoc.org/github.com/preslavmihaylov/decks)
## Contributing
Pull requests and feature requests are welcome. Feel free to submit a new issue and/or a PR.
Make sure your Pull Request is well documented and reasoned.