diff --git a/src/bin/client.rs b/src/bin/client.rs index 0b45671..5544e3c 100644 --- a/src/bin/client.rs +++ b/src/bin/client.rs @@ -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.