Skip to content

Commit

Permalink
tweaks and performance enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
diceroll123 committed Oct 13, 2024
1 parent 5d03bab commit 905b941
Show file tree
Hide file tree
Showing 10 changed files with 253 additions and 270 deletions.
48 changes: 1 addition & 47 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ chrono = "0.4.38"
chrono-tz = "0.10.0"
comfy-table = "7.1.1"

[dev-dependencies]
rayon = "1.10.0"

[lib]
name = "neofoodclub"

Expand Down
16 changes: 8 additions & 8 deletions src/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ impl Arena {
}

/// Returns a vector of pirates in this arena sorted from least to greatest odds.
pub fn best(&self) -> Vec<Pirate> {
let mut pirates = self.pirates.clone();
pub fn best(&self) -> Vec<&Pirate> {
let mut pirates: Vec<&Pirate> = self.pirates.iter().collect();
pirates.sort_by_key(|pirate| pirate.current_odds);
pirates
}
Expand Down Expand Up @@ -159,8 +159,8 @@ impl Arenas {
let indices = binary_to_indices(binary);
self.arenas
.iter()
.filter_map(|arena| {
let pirate_index = indices[arena.id as usize];
.zip(indices.iter())
.filter_map(|(arena, &pirate_index)| {
if pirate_index == 0 {
None
} else {
Expand All @@ -171,16 +171,16 @@ impl Arenas {
}

/// Returns a vector of all pirates in their arenas.
pub fn get_all_pirates(&self) -> Vec<Vec<Pirate>> {
pub fn get_all_pirates(&self) -> Vec<Vec<&Pirate>> {
self.arenas
.iter()
.map(|arena| arena.pirates.clone())
.map(|arena| arena.pirates.iter().collect())
.collect()
}

/// Returns the arenas sorted by best odds.
pub fn best(&self) -> Vec<Arena> {
let mut best: Vec<Arena> = self.arenas.clone();
pub fn best(&self) -> Vec<&Arena> {
let mut best: Vec<&Arena> = self.arenas.iter().collect();
best.sort_by(|a, b| a.odds.total_cmp(&b.odds));
best
}
Expand Down
39 changes: 19 additions & 20 deletions src/bets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,18 @@ pub struct Bets {
impl Bets {
/// Creates a new Bets struct from a list of indices mapped to the RoundDictData of the NFC object
pub fn new(nfc: &NeoFoodClub, indices: Vec<usize>, amounts: Option<BetAmounts>) -> Self {
let bet_binaries = indices
.iter()
.map(|&i| nfc.round_dict_data().bins[i])
.collect();

let odds = Odds::new(nfc, &indices);

let mut bets = Self {
array_indices: indices.clone(),
bet_binaries: indices
.iter()
.map(|&i| nfc.round_dict_data().bins[i])
.collect(),
array_indices: indices,
bet_binaries,
bet_amounts: None,
odds: Odds::new(nfc, indices),
odds,
};

bets.set_bet_amounts(&amounts);
Expand Down Expand Up @@ -231,7 +235,7 @@ impl Bets {
/// Returns whether or not this set is capable of busting
/// if there are no odds, returns None
pub fn is_bustproof(&self) -> bool {
self.odds.bust.is_none()
self.odds.bust().is_none()
}

/// Returns whether or not this set is "crazy"
Expand All @@ -247,20 +251,15 @@ impl Bets {
return false;
}

let anded = self
.bet_binaries
.iter()
.fold(None, |acc, &b| {
if let Some(result) = acc {
Some(result & b)
} else {
Some(b)
}
})
.unwrap()
.count_ones();
self.count_tenbets() > 0
}

anded > 0
/// Returns the number of tenbets in this set
pub fn count_tenbets(&self) -> u32 {
self.bet_binaries
.iter()
.fold(u32::MAX, |acc, &b| acc & b)
.count_ones()
}

/// Returns whether or not this set is a "gambit" set.
Expand Down
Loading

0 comments on commit 905b941

Please sign in to comment.