implemented some basics utils

This commit is contained in:
clizia 2025-01-07 19:50:15 +01:00
parent 3800511b3d
commit 8b925c7758
3 changed files with 23 additions and 5 deletions

View file

@ -1,12 +1,18 @@
use crate::card::Card;
use crate::card::Suit;
use rand::seq::SliceRandom;
use rand::rng;
pub struct Deck {
pub deck: Vec<Card>,
}
impl Deck {
pub fn new() -> Deck {
// possible values go from 0 to 8 because Durak is played
// without cards with a value lower than 6 in real life
// and ace is the highest card
let values: [u8; 9] = [0, 1, 2, 3, 4, 5, 6, 7, 8];
let suits: [Suit; 4] = [Suit::Hearts, Suit::Diamonds, Suit::Clubs, Suit::Spades];
@ -19,14 +25,15 @@ impl Deck {
}
}
println!("{:?}\n{}", deck_cards, deck_cards.len());
Deck {
deck: deck_cards,
}
}
fn shuffle(deck: Deck) -> Deck {
todo!()
pub fn shuffle(mut deck: Deck) -> Deck {
let mut rng = rng();
deck.deck.shuffle(&mut rng);
deck
}
}

View file

@ -2,7 +2,11 @@ use deck::Deck;
mod card;
mod deck;
mod player;
fn main() {
let deck: Deck = Deck::new();
let mut deck: Deck = Deck::new();
deck = Deck::shuffle(deck);
println!("{:?}\n{}", deck.deck, deck.deck.len());
}

7
src/player.rs Normal file
View file

@ -0,0 +1,7 @@
use crate::card::Card;
pub struct Player {
ip: u8,
name: String,
hand: Vec<Card>,
}