Struct dds_bridge::Deal
source · pub struct Deal(pub [Hand; 4]);Expand description
A deal of four hands
Tuple Fields§
§0: [Hand; 4]Implementations§
source§impl Deal
impl Deal
sourcepub fn new(rng: &mut (impl Rng + ?Sized)) -> Self
pub fn new(rng: &mut (impl Rng + ?Sized)) -> Self
Create a deal from a shuffled standard 52-card deck
Examples found in repository?
examples/notrump-tricks/main.rs (line 26)
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
fn analyze_deals(n: usize) -> Result<(), dds::Error> {
let deals: Vec<_> = core::iter::repeat_with(|| dds::Deal::new(&mut rand::thread_rng()))
.take(n)
.collect();
let histogram = dds::solve_deals(&deals, dds::StrainFlags::NOTRUMP)?
.into_iter()
.map(|table| table[dds::Strain::Notrump])
.fold(Histogram::default(), |mut acc, row| {
let (n, e, s, w) = (
usize::from(row.get(dds::Seat::North)),
usize::from(row.get(dds::Seat::East)),
usize::from(row.get(dds::Seat::South)),
usize::from(row.get(dds::Seat::West)),
);
acc.each[n] += 1;
acc.each[e] += 1;
acc.each[s] += 1;
acc.each[w] += 1;
acc.right[n.max(s)] += 1;
acc.right[e.max(w)] += 1;
acc.max[n.max(e).max(s).max(w)] += 1;
acc
});
dbg!(&to_cumulative_probability(histogram.each)[6..]);
dbg!(&to_cumulative_probability(histogram.right)[6..]);
dbg!(&to_cumulative_probability(histogram.max)[6..]);
Ok(())
}sourcepub fn display(self, seat: Seat) -> impl Display
pub fn display(self, seat: Seat) -> impl Display
PBN-compatible display from a seat’s perspective
Examples found in repository?
examples/compute-hot-deals/main.rs (line 66)
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
fn main() -> Result<ExitCode, dds::Error> {
let deals = match std::env::args().nth(1) {
Some(string) => {
if let Ok(n) = string.parse::<usize>() {
n
} else {
eprintln!("{}", include_str!("README.md"));
return Ok(ExitCode::FAILURE);
}
}
None => 1,
};
for _ in 0..deals {
let (deal, tricks) = compute_deal(&mut rand::thread_rng())?;
println!(
"{} {:X}",
deal.display(dds::Seat::North),
tricks.hex(dds::Seat::North, dds::Strain::SYS)
);
}
Ok(ExitCode::SUCCESS)
}Trait Implementations§
source§impl From<Deal> for ddTableDeal
impl From<Deal> for ddTableDeal
source§impl PartialEq for Deal
impl PartialEq for Deal
impl Copy for Deal
impl Eq for Deal
impl StructuralPartialEq for Deal
Auto Trait Implementations§
impl Freeze for Deal
impl RefUnwindSafe for Deal
impl Send for Deal
impl Sync for Deal
impl Unpin for Deal
impl UnwindSafe for Deal
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more