pub struct Contract {
pub bid: Bid,
pub penalty: Penalty,
}Expand description
The statement of the pair winning the bidding that they will take at least the number of tricks (in addition to the book of 6 tricks), and the strain denotes the trump suit.
Fields§
§bid: BidThe basic part of a contract
penalty: PenaltyThe penalty inflicted on the contract
Implementations§
Source§impl Contract
impl Contract
Sourcepub const fn new(level: u8, strain: Strain, penalty: Penalty) -> Self
pub const fn new(level: u8, strain: Strain, penalty: Penalty) -> Self
Create a contract from a level, strain, and penalty
§Panics
When the level is not in 1..=7. In const contexts, this is a
compile-time error.
Sourcepub const fn contract_points(self) -> i32
pub const fn contract_points(self) -> i32
Base score for making this contract
https://en.wikipedia.org/wiki/Bridge_scoring#Contract_points
Sourcepub const fn score(self, tricks: u8, vulnerable: bool) -> i32
pub const fn score(self, tricks: u8, vulnerable: bool) -> i32
Score for this contract given the number of taken tricks and vulnerability
The vulnerable parameter refers to the declaring side’s
vulnerability, not the defenders’.
The score is positive if the declarer makes the contract, and negative if the declarer fails.
§Examples
use dds_bridge::{Contract, Penalty, Strain};
// 4♠ making exactly, not vulnerable: 120 (contract) + 300 (game) = 420
let four_spades = Contract::new(4, Strain::Spades, Penalty::Undoubled);
assert_eq!(four_spades.score(10, false), 420);
// 3NT with one overtrick, vulnerable: 100 + 500 (game) + 30 (overtrick) = 630
let three_nt = Contract::new(3, Strain::Notrump, Penalty::Undoubled);
assert_eq!(three_nt.score(10, true), 630);
// 3NT doubled, down one, vulnerable: -200
let three_nt_x = Contract::new(3, Strain::Notrump, Penalty::Doubled);
assert_eq!(three_nt_x.score(8, true), -200);Trait Implementations§
Source§impl Ord for Contract
impl Ord for Contract
Source§impl PartialOrd for Contract
impl PartialOrd for Contract
impl Copy for Contract
impl Eq for Contract
impl StructuralPartialEq for Contract
Auto Trait Implementations§
impl Freeze for Contract
impl RefUnwindSafe for Contract
impl Send for Contract
impl Sync for Contract
impl Unpin for Contract
impl UnsafeUnpin for Contract
impl UnwindSafe for Contract
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