Files
pokerfreak/src/main.rs
T
mmintel 04d5251acf Welt ohne fremden Namen: Pruefordner vollstaendig mitkopieren, Engine nur im eigenen Baum
Die Welt nannte 'pokerfreak' nur noch in zwei Harness-Zeilen - der Rest waren veraltete
Rust-Pruefungen im Pruefordner, die der Aufbau nie auffrischte.
2026-11-01 23:37:11 +01:00

36 lines
1.0 KiB
Rust

//! The only impure part: read lines from stdin, write lines to stdout.
use rechner::game::Decision;
use rechner::wire::encode::encode;
use rechner::wire::respond::respond;
use std::io::{self, BufRead, Write};
use std::panic::{catch_unwind, set_hook, AssertUnwindSafe};
/// A panic anywhere in the core still yields a valid ABSTAIN line.
fn guarded(line: &str) -> String {
catch_unwind(AssertUnwindSafe(|| respond(line)))
.unwrap_or_else(|_| encode(&Decision::abstain("internal error")))
}
fn serve(input: impl BufRead, mut output: impl Write) -> io::Result<()> {
for line in input.lines() {
let line = line?;
if line.trim().is_empty() {
continue;
}
writeln!(output, "{}", guarded(&line))?;
output.flush()?;
}
Ok(())
}
fn main() {
set_hook(Box::new(|_| {}));
let stdin = io::stdin();
let stdout = io::stdout();
if let Err(error) = serve(stdin.lock(), stdout.lock()) {
eprintln!("io error: {error}");
std::process::exit(1);
}
}