api/gameserv: type email ExpiryTarget and chess Ending as enums (drop stringly returns)
All checks were successful
CI / check (push) Successful in 3m53s
All checks were successful
CI / check (push) Successful in 3m53s
This commit is contained in:
parent
2cdc7f820a
commit
f5c976eb56
4 changed files with 43 additions and 20 deletions
|
|
@ -476,16 +476,24 @@ pub fn legal(st: &State) -> Vec<Move> {
|
|||
.collect()
|
||||
}
|
||||
|
||||
/// `""` ongoing; `"draw"` for stalemate; or the winning side (`"w"`/`"b"`) on
|
||||
/// checkmate.
|
||||
pub fn over(st: &State) -> String {
|
||||
/// How a position has ended.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum Ending {
|
||||
Draw,
|
||||
Checkmate(u8), // the winning colour byte: b'w' or b'b'
|
||||
}
|
||||
|
||||
/// `None` while the side to move still has a legal move; else the ending
|
||||
/// (stalemate → `Draw`, checkmate → `Checkmate(winner)`).
|
||||
pub fn over(st: &State) -> Option<Ending> {
|
||||
if !legal(st).is_empty() {
|
||||
return String::new();
|
||||
return None;
|
||||
}
|
||||
if in_check(st, st.turn) {
|
||||
return if st.turn == b'w' { "b" } else { "w" }.to_string();
|
||||
Some(Ending::Checkmate(if st.turn == b'w' { b'b' } else { b'w' }))
|
||||
} else {
|
||||
Some(Ending::Draw)
|
||||
}
|
||||
"draw".to_string()
|
||||
}
|
||||
|
||||
fn name_sq(s: i32) -> String {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue