use super::System;
use super::array::Logits;
use contract_bridge::Hand;
use contract_bridge::auction::{Call, RelativeVulnerability};
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct Versus<A, B> {
dealer_side: A,
other: B,
}
impl<A, B> Versus<A, B> {
pub const fn new(dealer_side: A, other: B) -> Self {
Self { dealer_side, other }
}
}
impl<A: System, B: System> System for Versus<A, B> {
fn classify(&self, hand: Hand, vul: RelativeVulnerability, auction: &[Call]) -> Option<Logits> {
if auction.len().is_multiple_of(2) {
self.dealer_side.classify(hand, vul, auction)
} else {
self.other.classify(hand, vul, auction)
}
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct OrElse<A, B> {
first: A,
second: B,
}
impl<A, B> OrElse<A, B> {
pub const fn new(first: A, second: B) -> Self {
Self { first, second }
}
}
impl<A: System, B: System> System for OrElse<A, B> {
fn classify(&self, hand: Hand, vul: RelativeVulnerability, auction: &[Call]) -> Option<Logits> {
self.first
.classify(hand, vul, auction)
.filter(|logits| logits.values().any(|&logit| logit > f32::NEG_INFINITY))
.or_else(|| self.second.classify(hand, vul, auction))
}
}