<commit_before>use uci::{UciEngine, UciEngineFactory, EngineReply, OptionName, OptionDescription};
use position::board::Board;
use position::chess_move::*;

pub const VERSION: &'static str = "0.1";


pub struct DummyEngine {
    board: Board,
    replies: Vec<EngineReply>,
    is_thinking: bool,
    infinite: bool,
    ponder: bool,
    best_move: String,
    move_stack: MoveStack,
}


impl DummyEngine {
    pub fn new() -> DummyEngine {
        DummyEngine {
            board: Board::from_fen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w QKqk - 0 1")
                       .ok()
                       .unwrap(),
            replies: vec![],
            is_thinking: false,
            infinite: false,
            ponder: false,
            best_move: "0000".to_string(),
            move_stack: MoveStack::new(),
        }
    }
}


impl UciEngine for DummyEngine {
    #[allow(unused_variables)]
    fn set_option(&mut self, name: &str, value: &str) {
        self.replies.push(EngineReply::Info(vec![("string".to_string(),
                                                  format!("{} -> {}", name, value))]));
    }

    fn new_game(&mut self) {}

    #[allow(unused_variables)]
    fn position(&mut self, fen: &str, moves: Vec<String>) {
        if self.is_thinking {
            return
        }
        self.board = match Board::from_fen(fen) {
            Ok(x) => x,
            Err(_) => return,
        };
        let s = &mut self.move_stack;
        let b = &mut self.board;
        'played_move: for played_move in moves {
            b.generate_moves(true, s);
            while let Some(m) = s.pop() {
                if played_move == m.notation() {
                    s.remove_all();
                    if b.do_move(m) {
                        continue 'played_move;
                    } else {
                        break 'played_move;
                    }
                }
            }
            break 'played_move;
        }
    }

    #[allow(unused_variables)]
    fn go(&mut self,
          searchmoves: Option<Vec<String>>,
          ponder: bool,
          wtime: Option<u64>,
          btime: Option<u64>,
          winc: Option<u64>,
          binc: Option<u64>,
          movestogo: Option<u64>,
          depth: Option<u64>,
          nodes: Option<u64>,
          mate: Option<u64>,
          movetime: Option<u64>,
          infinite: bool) {
        if self.is_thinking {
            return
        }
        let s = &mut self.move_stack;
        let b = &mut self.board;
        b.generate_moves(true, s);
        while let Some(m) = s.pop() {
            if b.do_move(m) {
                b.undo_move(m);
                self.best_move = m.notation();
                s.remove_all();
                break;
            }
        }
        self.ponder = ponder;
        self.infinite = infinite;
        self.is_thinking = infinite | ponder;
        if !self.is_thinking {
            self.replies.push(EngineReply::BestMove {
                best_move: self.best_move.clone(),
                ponder_move: None,
            });
            self.best_move = "0000".to_string();
        }
    }

    fn ponder_hit(&mut self) {
        if self.is_thinking && self.ponder {
            self.ponder = false;
            if !self.infinite {
                self.stop()
            }
        }
    }

    fn stop(&mut self) {
        if !self.is_thinking {
            return
        }
        self.replies.push(EngineReply::BestMove {
            best_move: self.best_move.clone(),<commit_msg>make the engine move randomly<commit_after>use uci::{UciEngine, UciEngineFactory, EngineReply, OptionName, OptionDescription};
use position::board::Board;
use position::chess_move::*;
use rand;
use rand::distributions::{Sample, Range};


pub const VERSION: &'static str = "0.1";


pub struct DummyEngine {
    board: Board,
    replies: Vec<EngineReply>,
    is_thinking: bool,
    infinite: bool,
    ponder: bool,
    best_move: String,
    move_stack: MoveStack,
}


impl DummyEngine {
    pub fn new() -> DummyEngine {
        DummyEngine {
            board: Board::from_fen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w QKqk - 0 1")
                       .ok()
                       .unwrap(),
            replies: vec![],
            is_thinking: false,
            infinite: false,
            ponder: false,
            best_move: "0000".to_string(),
            move_stack: MoveStack::new(),
        }
    }
}


impl UciEngine for DummyEngine {
    #[allow(unused_variables)]
    fn set_option(&mut self, name: &str, value: &str) {
        self.replies.push(EngineReply::Info(vec![("string".to_string(),
                                                  format!("{} -> {}", name, value))]));
    }

    fn new_game(&mut self) {}

    #[allow(unused_variables)]
    fn position(&mut self, fen: &str, moves: Vec<String>) {
        if self.is_thinking {
            return
        }
        self.board = match Board::from_fen(fen) {
            Ok(x) => x,
            Err(_) => return,
        };
        let s = &mut self.move_stack;
        let b = &mut self.board;
        'played_move: for played_move in moves {
            b.generate_moves(true, s);
            while let Some(m) = s.pop() {
                if played_move == m.notation() {
                    s.remove_all();
                    if b.do_move(m) {
                        continue 'played_move;
                    } else {
                        break 'played_move;
                    }
                }
            }
            break 'played_move;
        }
    }

    #[allow(unused_variables)]
    fn go(&mut self,
          searchmoves: Option<Vec<String>>,
          ponder: bool,
          wtime: Option<u64>,
          btime: Option<u64>,
          winc: Option<u64>,
          binc: Option<u64>,
          movestogo: Option<u64>,
          depth: Option<u64>,
          nodes: Option<u64>,
          mate: Option<u64>,
          movetime: Option<u64>,
          infinite: bool) {
        if self.is_thinking {
            return
        }
        let s = &mut self.move_stack;
        let b = &mut self.board;
        b.generate_moves(true, s);
        let mut legal_moves = vec![];   
        while let Some(m) = s.pop() {
            if b.do_move(m) {
                b.undo_move(m);
                legal_moves.push(m.notation()); 
            }
        }
        let mut rng = rand::thread_rng();
        let mut between = Range::new(0, legal_moves.len());
        self.best_move = legal_moves[between.sample(&mut rng)].clone();
            
        self.ponder = ponder;
        self.infinite = infinite;
        self.is_thinking = infinite | ponder;
        if !self.is_thinking {
            self.replies.push(EngineReply::BestMove {
                best_move: self.best_move.clone(),
                ponder_move: None,
            });
            self.best_move = "0000".to_string();
        }
    }

    fn ponder_hit(&mut self) {
        if self.is_thinking && self.ponder {
            self.ponder = false;
            if !self.infinite {
                self.stop()
            }
        }
    }

    fn stop(&mut self) {
        if !self.is_thinking {
            return
        }
        self.replies.push(EngineReply::BestMove {
            best_move: self.best_move.clone(),
{'fraction_non_alphanumeric': 0.12196452933151432, 'fraction_numerical': 0.00941336971350614, 'mean_word_length': 1.4758527524484972, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4388483', 'n_tokens_mistral': 2291, 'n_tokens_neox': 2212, 'n_words': 455}