Manage the end of the game.
This commit is contained in:
parent
2c97d4b023
commit
3938530912
@ -1,5 +1,5 @@
|
||||
use shakmaty::fen::Fen;
|
||||
use shakmaty::{Chess, Setup};
|
||||
use shakmaty::{Chess, Color, Outcome, Position, Setup};
|
||||
use std::io;
|
||||
use std::io::{BufRead, BufReader};
|
||||
use std::os::unix::net::UnixStream;
|
||||
@ -33,6 +33,10 @@ fn main() {
|
||||
"{}",
|
||||
clichess::board_representation(¤t_position, clichess::to_color(client.side))
|
||||
);
|
||||
//check if game is over.
|
||||
if current_position.is_game_over() {
|
||||
break;
|
||||
}
|
||||
if clichess::is_player_turn(&client, current_position.turn()) {
|
||||
//it's the user turn, taking user input
|
||||
io::stdin().read_line(&mut buffer).unwrap();
|
||||
@ -45,6 +49,17 @@ fn main() {
|
||||
|
||||
//come back at the beginning of the loop to wait for incoming moves.
|
||||
}
|
||||
match current_position.outcome() {
|
||||
None => panic!("Game should be over."),
|
||||
Some(Outcome::Draw) => println!("Draw game."),
|
||||
Some(Outcome::Decisive { winner }) => {
|
||||
if winner == Color::White {
|
||||
println!("White has won the game.")
|
||||
} else {
|
||||
println!("Black has won the game.")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//wait for next position from server, then return the current board.
|
||||
|
Loading…
Reference in New Issue
Block a user