Manage the end of the game.

This commit is contained in:
Artlef 2020-01-05 22:51:57 +01:00
parent 2c97d4b023
commit 3938530912

View File

@ -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(&current_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.