Generic deck of cards in V
vdeck
Deck<T>
vdeck
- add/draw/peek card from the top, middle and bottom
- add/draw/peek card from a specific position
- add/draw/peek card from a random position
- shuffle
- and more
Samples
Standard deck of cards
import { create_standard_deck } from vdeck
fn main() {
// it's important that the deck is a mutable variable
// so that, for example, when drawing cards they are
// automatically removed from the deck
mut deck := create_standard_deck()
deck.shuffle()
}
Custom deck of cards
Say you had a specific or custom deck of cards, worry not,
vdeck
The most simplistic custom card would be an integer. This is how you would go about creating a deck of integer cards:
import { create_deck } from vdeck
fn main() {
// specify the shape of the card as the generic type argument
// specify the deck of cards as the function argument
// boom! you got yourself a deck of cards!
mut deck := create_deck<int>([1, 2, 3, 4, 5, 6, 7, 8, 9])
deck.shuffle(4)
random_card := deck.draw_random()
}
For more customized (and reallistic) decks you can check out how
vdeck
vdeck_uno.v