chess_game 0.2.0

Simple Chess game
Documentation
use std::{time::Duration, thread};
use chess::{ChessMove, Board, MoveGen};
use method_shorthands::methods::*;
use rand::prelude::*;

use super::Player;

#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub struct RandomBot;

impl Player for RandomBot {
    fn get_move(board: Board, _: usize, bot_wait_ms: u64) -> Result<ChessMove, ()> {
        if bot_wait_ms > 0 { thread::sleep(Duration::from_millis(bot_wait_ms)) };

        let move_gen = MoveGen::new_legal(&board);
        let move_list: Vec<ChessMove> = move_gen.collect();

        let random_move = *move_list.choose(&mut rand::thread_rng()).uw();

        Ok(random_move)
    }
}