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

source

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(())
}
source

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)
}
source

pub fn shuffled(self, rng: &mut (impl Rng + ?Sized), seats: SeatFlags) -> Self

Shuffle existing hands while preserving the numbers of cards

Trait Implementations§

source§

impl Clone for Deal

source§

fn clone(&self) -> Deal

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Deal

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Deal

source§

fn default() -> Deal

Returns the “default value” for a type. Read more
source§

impl From<Deal> for ddTableDeal

source§

fn from(deal: Deal) -> Self

Converts to this type from the input type.
source§

impl Hash for Deal

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Index<Seat> for Deal

§

type Output = Hand

The returned type after indexing.
source§

fn index(&self, seat: Seat) -> &Hand

Performs the indexing (container[index]) operation. Read more
source§

impl IndexMut<Seat> for Deal

source§

fn index_mut(&mut self, seat: Seat) -> &mut Hand

Performs the mutable indexing (container[index]) operation. Read more
source§

impl PartialEq for Deal

source§

fn eq(&self, other: &Deal) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Copy for Deal

source§

impl Eq for Deal

source§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V