implemented some basics utils
This commit is contained in:
parent
3800511b3d
commit
8b925c7758
3 changed files with 23 additions and 5 deletions
15
src/deck.rs
15
src/deck.rs
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
7
src/player.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
use crate::card::Card;
|
||||
|
||||
pub struct Player {
|
||||
ip: u8,
|
||||
name: String,
|
||||
hand: Vec<Card>,
|
||||
}
|
Loading…
Add table
Reference in a new issue