interface.rs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. use std::io::{self, BufRead};
  2. use std::sync::mpsc::{Receiver, Sender};
  3. use std::process::exit;
  4. use engine::{EngineMsg, InterfaceMsg};
  5. use game::{Game};
  6. pub fn run(r: Receiver<InterfaceMsg>, s: Sender<EngineMsg>) {
  7. let stdin = io::stdin();
  8. for line_m in stdin.lock().lines() {
  9. let line = line_m.unwrap();
  10. let split = line.split_whitespace().collect::<Vec<&str>>();
  11. run_command(split, &r, &s);
  12. }
  13. }
  14. fn run_command(mut cmd: Vec<&str>, r: &Receiver<InterfaceMsg>, s: &Sender<EngineMsg>) {
  15. if cmd.len() > 0 {
  16. let command = cmd[0];
  17. cmd.drain(0..1);
  18. match command {
  19. "uci" => cmd_uci(cmd),
  20. "isready" => cmd_isready(cmd),
  21. "position" => cmd_position(cmd, r, s),
  22. "go" => cmd_go(cmd, r, s),
  23. "ucinewgame" => cmd_newgame(cmd, r, s),
  24. "quit" | "exit" => cmd_quit(cmd, r, s),
  25. cmd => { println!("unknown command: {}", cmd); }
  26. }
  27. }
  28. }
  29. fn cmd_uci(_args: Vec<&str>) {
  30. println!("id name bishop 1.0");
  31. println!("id author Geile Siech");
  32. println!("uciok");
  33. }
  34. fn cmd_isready(_args: Vec<&str>) {
  35. println!("readyok");
  36. }
  37. fn cmd_position(mut args: Vec<&str>, r: &Receiver<InterfaceMsg>, s: &Sender<EngineMsg>) {
  38. let position = args[0];
  39. args.drain(0..1);
  40. let mut game = Game::default();
  41. if position == "startpos" {
  42. }
  43. else if position == "fen" {
  44. let fen_parts: Vec<String> = Vec::from(&args[1..6]).into_iter().map(|x| x.to_owned()).collect::<Vec<String>>();
  45. // "3N4/5P2/2K1P1pP/p2PNn2/1p3r2/2P4P/4k2B/8 w - - 0 1"
  46. }
  47. s.send(EngineMsg::SetBoard(game)).unwrap();
  48. }
  49. fn cmd_go(_args: Vec<&str>, _r: &Receiver<InterfaceMsg>, s: &Sender<EngineMsg>) {
  50. s.send(EngineMsg::Search(3)).unwrap();
  51. }
  52. fn cmd_newgame(_args: Vec<&str>, _r: &Receiver<InterfaceMsg>, s: &Sender<EngineMsg>) {
  53. s.send(EngineMsg::NewGame).unwrap();
  54. }
  55. fn cmd_quit(_args: Vec<&str>, _r: &Receiver<InterfaceMsg>, _s: &Sender<EngineMsg>) {
  56. exit(0);
  57. }