Parcourir la source

added necessary stuff

Nicolas Winkler il y a 6 ans
Parent
commit
be8c8e06e1
4 fichiers modifiés avec 138 ajouts et 2 suppressions
  1. 92 0
      src/bitboard.rs
  2. 19 0
      src/engine.rs
  3. 25 2
      src/interface.rs
  4. 2 0
      src/search.rs

+ 92 - 0
src/bitboard.rs

@@ -0,0 +1,92 @@
+/*!
+ *
+ * arranged like this:
+ *
+ * 63 62 61 60 59 58 57 56
+ * 55 54 ...
+ *
+ */
+pub type Bitboard = u64;
+
+
+pub struct BitboardIterator { pub board: Bitboard }
+
+impl Iterator for BitboardIterator {
+    type Item = Bitboard;
+
+    fn next(&mut self) -> Option<Bitboard> {
+        if self.board != 0 {
+            let lsb = self.board & (0_u64.wrapping_sub(self.board));
+            self.board &= !lsb;
+            //Some(lsb.trailing_zeros())
+            Some(lsb)
+        }
+            else {
+                None
+            }
+    }
+}
+
+
+pub const A_FILE: Bitboard = 0x_8080_8080_8080_8080;
+pub const H_FILE: Bitboard = 0x_0101_0101_0101_0101;
+
+
+pub fn north_one(b: Bitboard) -> Bitboard {
+    b << 8
+}
+
+pub fn south_one(b: Bitboard) -> Bitboard {
+    b >> 8
+}
+
+pub fn west_one(b: Bitboard) -> Bitboard {
+    (b << 1) & !H_FILE
+}
+
+pub fn east_one(b: Bitboard) -> Bitboard {
+    (b >> 1) & !A_FILE
+}
+
+pub fn northeast_one(b: Bitboard) -> Bitboard {
+    (b << 7) & !A_FILE
+}
+
+pub fn northwest_one(b: Bitboard) -> Bitboard {
+    (b << 9) & !H_FILE
+}
+
+pub fn southwest_one(b: Bitboard) -> Bitboard {
+    (b >> 7) & !H_FILE
+}
+
+pub fn southeast_one(b: Bitboard) -> Bitboard {
+    (b >> 9) & !A_FILE
+}
+
+pub fn bit_at_index(b: Bitboard, index: u32) -> bool {
+    ((b >> index) & 1) != 0
+}
+
+pub fn bit_at(b: Bitboard, i: i32, j: i32) -> bool {
+    ((b >> (7 - i) * 8 + 7 - j) & 1) == 1
+}
+
+pub fn set_bit(b: &mut Bitboard, i: i32, j: i32) {
+    *b |= 1 << ((7 - i) * 8 + 7 - j);
+}
+
+pub fn set_bit_index(b: &mut Bitboard, index: u32) {
+    *b |= 1 << index;
+}
+
+pub fn print_board(b: Bitboard) -> String {
+    (0..8).map(
+        |i| (0..8).map(
+            |j| if bit_at(b, i, j) { "x " }
+                else { ". " }
+        ).collect::<String>() + "\n"
+    ).collect::<String>()
+}
+
+

+ 19 - 0
src/engine.rs

@@ -0,0 +1,19 @@
+
+
+
+
+pub enum Message {
+    SetBoard,
+    SetPiece(Bitboard),
+    Search(i32),
+    Ping,
+    Stop,
+    GetInfo,
+}
+
+
+
+pub fn run_engine(r: Receiver<Message>) {
+
+}
+

+ 25 - 2
src/interface.rs

@@ -1,7 +1,10 @@
 use std::io::{self, BufRead};
+use std::collections::HashMap;
 
 pub fn run() {
     let stdin = io::stdin();
+    println!("id name bishop 1.0");
+    println!("id author bishop");
     for line_m in stdin.lock().lines() {
         let line = line_m.unwrap();
         let mut split = line.split_whitespace().collect::<Vec<&str>>();
@@ -9,8 +12,28 @@ pub fn run() {
     }
 }
 
-fn run_command(cmd: Vec<&str>) {
-    println!("{}", cmd[0]);
+fn run_command(mut cmd: Vec<&str>) {
+    if cmd.len() > 0 {
+        let command = cmd[0];
+        cmd.drain(0..1);
+        match command {
+            "uci" => cmd_uci(cmd),
+            "isready" => cmd_isready(cmd),
+            "register" => cmd_register(cmd),
+            _ => {}
+        }
+    }
+}
+
+fn cmd_uci(args: Vec<&str>) {
+    println!("uciok");
+}
+
+fn cmd_isready(args: Vec<&str>) {
+    println!("readyok");
+}
+
+fn cmd_register(args: Vec<&str>) {
 }
 
 

+ 2 - 0
src/search.rs

@@ -0,0 +1,2 @@
+use std::sync::mpsc::Receiver;
+