From 3938530912e8e820eb76bbf24dfbd766e56ebff8 Mon Sep 17 00:00:00 2001 From: Artlef Date: Sun, 5 Jan 2020 22:51:57 +0100 Subject: [PATCH] Manage the end of the game. --- src/bin/client.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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.