Er spielt nicht, er liest nur mit - die Einschraenkung auf Cash NLH und Turniere gilt nur den Spielformaten (Owner 16.11.: "in swift gibts einen spectator mode in win nicht"). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
83 lines
3.4 KiB
Rust
83 lines
3.4 KiB
Rust
//! Wie viel das Cockpit zeigt. Vorgabe (seit 15.11. 23:30 immer, Owner mehrfach): nur Cash Game
|
|
//! NLH und Turniere stehen (Owner 15.11.: "alle modi disablen außer cash und turniere, nur noch NLH"):
|
|
//! weg sind PLO und die Sonderformate (All-In or Fold, Bomb Pot, K-Poker); der Zuschauer bleibt (16.11.).
|
|
//! Ausgeblendete Formate fliegen auch aus der Wahl, damit der Laeufer sie nicht mehr spielt. Uebung
|
|
//! bleibt, damit ein Start nicht nur noch mit Echtgeld geht. (Spiegel: winui/Kern/Umfang.cs.)
|
|
//! Lehrer & Stimme, Streamer und das Klon-Abzeichen gibt es in diesem Cockpit (noch) nicht.
|
|
//! Nur `--alles` oder POKERFREAK_NUR_SPIEL=0/nein/false zeigt alles; `--nur-spiel` bleibt erlaubt.
|
|
|
|
use crate::formate::SpielFormat;
|
|
use crate::spielplan::Spielplan;
|
|
use std::sync::atomic::{AtomicBool, Ordering};
|
|
|
|
static NUR_SPIEL: AtomicBool = AtomicBool::new(true);
|
|
|
|
/// Aus Argumenten und Umgebung bestimmen; entfernt `--nur-spiel` und `--alles` aus `args`.
|
|
pub fn aus_aufruf(args: &mut Vec<String>) -> bool {
|
|
let env = std::env::var("POKERFREAK_NUR_SPIEL").ok();
|
|
let an = bestimmen(args, env.as_deref());
|
|
args.retain(|a| a != "--nur-spiel" && a != "--alles");
|
|
NUR_SPIEL.store(an, Ordering::Relaxed);
|
|
an
|
|
}
|
|
|
|
fn bestimmen(args: &[String], env: Option<&str>) -> bool {
|
|
!args.iter().any(|a| a == "--alles")
|
|
&& !matches!(env.map(|e| e.trim().to_lowercase()).as_deref(), Some("0" | "nein" | "false"))
|
|
}
|
|
|
|
pub fn nur_spiel() -> bool {
|
|
NUR_SPIEL.load(Ordering::Relaxed)
|
|
}
|
|
|
|
/// Ob ein Format gezeigt und gespielt wird (Freeroll und VIP sind Turnier-Typen).
|
|
pub fn erlaubt(f: SpielFormat) -> bool {
|
|
!nur_spiel() || matches!(f, SpielFormat::Cash | SpielFormat::Turnier | SpielFormat::Vip | SpielFormat::Freeroll)
|
|
}
|
|
|
|
/// Ob eine Formatkarte (nach ihrer Kennung) gezeigt wird.
|
|
pub fn karte_sichtbar(id: &str) -> bool {
|
|
SpielFormat::ALLE.into_iter().find(|f| f.roh() == id).map_or(true, erlaubt)
|
|
}
|
|
|
|
/// Nicht erlaubte Formate aus der Wahl nehmen; true, wenn sich etwas aenderte.
|
|
pub fn bereinigen(w: &mut Spielplan) -> bool {
|
|
let weg: Vec<SpielFormat> = SpielFormat::ALLE.into_iter().filter(|f| !erlaubt(*f) && w.anzahl(*f) > 0).collect();
|
|
for f in &weg {
|
|
w.setzen(*f, 0);
|
|
}
|
|
!weg.is_empty()
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn schalter_aus_argument_und_umgebung() {
|
|
// Vorgabe AN - auch ohne jedes Argument (Taskleiste, 15.11. 23:24)
|
|
assert!(bestimmen(&[], None));
|
|
assert!(bestimmen(&["--nur-spiel".into()], None));
|
|
assert!(bestimmen(&[], Some(" ja ")) && bestimmen(&[], Some("1")));
|
|
assert!(!bestimmen(&["--alles".into()], None));
|
|
assert!(!bestimmen(&[], Some("0")) && !bestimmen(&[], Some(" Nein ")) && !bestimmen(&[], Some("false")));
|
|
}
|
|
|
|
#[test]
|
|
fn nur_cash_nlh_und_turnier() {
|
|
NUR_SPIEL.store(true, Ordering::Relaxed);
|
|
for id in ["cash_plo", "aof", "bombpot", "kpoker"] {
|
|
assert!(!karte_sichtbar(id), "{id}");
|
|
}
|
|
assert!(karte_sichtbar("cash") && karte_sichtbar("turnier"));
|
|
let mut w = Spielplan::standard();
|
|
w.setzen(SpielFormat::CashPlo, 2);
|
|
w.setzen(SpielFormat::Aof, 1);
|
|
assert!(bereinigen(&mut w));
|
|
assert_eq!((w.anzahl(SpielFormat::CashPlo), w.anzahl(SpielFormat::Aof)), (0, 0));
|
|
assert!(!bereinigen(&mut w));
|
|
NUR_SPIEL.store(false, Ordering::Relaxed);
|
|
assert!(karte_sichtbar("cash_plo"));
|
|
}
|
|
}
|