Skip to content

Commit

Permalink
Small cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
reinismu committed Oct 17, 2024
1 parent 33ae780 commit fef6606
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
13 changes: 9 additions & 4 deletions src/cards/card.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use super::rank::Rank;
use super::suit::Suit;

#[cfg(not(feature = "shortdeck"))]
const CARD_COUNT_IN_DECK: usize = 52;
pub const CARD_COUNT_IN_DECK: usize = 52;

#[cfg(feature = "shortdeck")]
const CARD_COUNT_IN_DECK: usize = 36;
pub const CARD_COUNT_IN_DECK: usize = 36;

/// Card represents a playing card
/// it is a tuple of Rank and Suit
Expand All @@ -21,8 +21,13 @@ impl Card {
}
pub fn draw() -> Card {
use rand::Rng;
let ref mut rng = rand::thread_rng();
Card::from(rng.gen_range(0..CARD_COUNT_IN_DECK) as u8)
let rng = &mut rand::thread_rng();
let suit = rng.gen_range(0..4) as u8;
#[cfg(not(feature = "shortdeck"))]
let rank = rng.gen_range(0..13) as u8;
#[cfg(feature = "shortdeck")]
let rank = rng.gen_range(4..13) as u8;
Card::from((Rank::from(rank), Suit::from(suit)))
}
}

Expand Down
8 changes: 2 additions & 6 deletions src/cards/hands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ pub struct HandIterator {
mask: u64,
}

#[cfg(not(feature = "shortdeck"))]
const CARD_COUNT_IN_DECK: usize = 52;

#[cfg(feature = "shortdeck")]
const CARD_COUNT_IN_DECK: usize = 36;

impl HandIterator {
/// returns the size of the iterator
/// by some cheap combinatorial calculations
Expand Down Expand Up @@ -122,6 +116,8 @@ impl From<(usize, Hand)> for HandIterator {

#[cfg(test)]
mod tests {
use crate::cards::card::CARD_COUNT_IN_DECK;

use super::*;

#[test]
Expand Down
2 changes: 0 additions & 2 deletions src/clustering/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ use super::datasets::AbstractionSpace;
use super::datasets::ObservationSpace;
use crate::cards::isomorphism::Isomorphism;
use crate::cards::observation::Observation;
use crate::cards::observations::ObservationIterator;
use crate::cards::street::Street;
use crate::clustering::abstraction::Abstraction;
use crate::clustering::histogram::Histogram;
use crate::clustering::metric::Metric;
use crate::clustering::xor::Pair;
use petgraph::algo::isomorphism;
use rand::distributions::Distribution;
use rand::distributions::WeightedIndex;
use rand::rngs::StdRng;
Expand Down

0 comments on commit fef6606

Please sign in to comment.