20 lines
785 B
Rust
20 lines
785 B
Rust
use super::repair::{repair, Repair};
|
|
use crate::game::{Decision, Spot};
|
|
|
|
/// Last line of defence: the returned decision is legal for `spot` or it is ABSTAIN.
|
|
/// Repairs (fold to check, raise size snapped or clamped) are noted in the reason;
|
|
/// anything unrepairable becomes ABSTAIN with zero confidence.
|
|
pub fn enforce(spot: &Spot, decision: Decision) -> Decision {
|
|
match repair(spot, decision.choice) {
|
|
Repair::Kept(choice) => Decision { choice, ..decision },
|
|
Repair::Changed(choice, note) => Decision {
|
|
choice,
|
|
reason: format!("{} [enforced: {note}]", decision.reason),
|
|
..decision
|
|
},
|
|
Repair::Refused(why) => {
|
|
Decision::abstain(format!("{} [enforced: {why}]", decision.reason))
|
|
}
|
|
}
|
|
}
|