File size: 2,392 Bytes
3014f14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90030df
 
 
bfb4653
 
 
90030df
 
 
bfb4653
90030df
 
bfb4653
90030df
 
 
 
 
 
 
 
 
 
bfb4653
90030df
 
bfb4653
90030df
bfb4653
 
90030df
bfb4653
 
90030df
bfb4653
 
 
 
 
 
90030df
bfb4653
90030df
bfb4653
 
 
 
 
 
 
 
 
 
90030df
 
 
 
3014f14
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// main.rs
mod bitboard;
mod types;
mod position;
mod movegen;
mod search;
mod evaluate;
mod uci;
mod tt;
mod zobrist;
mod timeman;
mod movepick;
mod perft;

use std::io::{self, BufRead};

fn main() {
    let stdin = io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buffer = String::new();

    // Store the moves played in the game so far
    let mut current_moves: Vec<String> = Vec::new();

    loop {
        buffer.clear();
        let bytes_read = stdin_lock.read_line(&mut buffer).unwrap_or(0);
        if bytes_read == 0 { break; }

        let command = buffer.trim();
        if command.is_empty() { continue; }

        if command == "uci" {
            println!("id name VeloCT_Base");
            println!("id author Taperx");
            println!("uciok");
        } 
        else if command == "isready" {
            println!("readyok");
        } 
        else if command == "ucinewgame" {
            current_moves.clear();
        } 
        else if command.starts_with("position") {
            // Example Lichess input: "position startpos moves e2e4 e7e5 g1f3"
            
            // Clear old moves
            current_moves.clear();
            
            // Split the command into words to find the moves
            let parts: Vec<&str> = command.split_whitespace().collect();
            
            if let Some(moves_index) = parts.iter().position(|&x| x == "moves") {
                // Save all the moves played in the game into our vector
                for move_str in &parts[moves_index + 1..] {
                    current_moves.push(move_str.to_string());
                }
            }
            
            // TODO: Feed `current_moves` into your engine's internal board state!
        } 
        else if command.starts_with("go") {
            // TODO: Generate a list of legal moves for the CURRENT board state
            // TODO: Evaluate the position and pick the best legal move
            
            // For now, this is pseudocode. You must replace this with your engine's logic!
            // let best_move = my_engine.find_best_move();
            // println!("bestmove {}", best_move);
            
            // WARNING: If you hardcode this, Lichess will abort the game if it's illegal.
            println!("bestmove d7d5"); 
        } 
        else if command == "quit" {
            break;
        }
    }
}