Browse Source

some comments

Nicolas Winkler 2 years ago
parent
commit
ef6e8a6980
4 changed files with 57 additions and 20 deletions
  1. 12 9
      src/bitboard.rs
  2. 11 0
      src/engine.rs
  3. 17 11
      src/evaluate.rs
  4. 17 0
      src/game.rs

+ 12 - 9
src/bitboard.rs

@@ -1,15 +1,18 @@
 
 
-/*!
- *
- * arranged like this:
- *
- * 63 62 61 60 59 58 57 56
- * 55 54 ...
- *
- */
-
+///
+/// 64 bit integer type to be used as bitboard type.
+/// 
+/// arranged like this:
+/// 
+/// 63 62 61 60 59 58 57 56
+/// 55 54 ...
+/// 
 pub type Bitboard = u64;
+
+///
+/// type to store one square index
+/// 
 pub type Square = u8;
 
 pub const FILE_A: Bitboard = 0x_8080_8080_8080_8080;

+ 11 - 0
src/engine.rs

@@ -12,6 +12,9 @@ use hash::{Cache, RepetitionTable};
 use std::sync::Arc;
 use std::sync::mpsc::{Receiver, Sender};
 
+///
+/// Message types that are sent from the uci interface to the engine thread.
+/// 
 pub enum EngineMsg {
     SetBoard{ pos: Game, moves: Vec<String> },
     SetPiece(Bitboard),
@@ -25,6 +28,9 @@ pub enum EngineMsg {
     GetInfo,
 }
 
+///
+/// Structure holding information for a search command.
+/// 
 pub struct SearchInfo {
     pub depth: Option<i32>,
     pub movetime: Option<i32>,
@@ -40,6 +46,11 @@ pub struct SearchInfo {
 pub enum InterfaceMsg {
 }
 
+///
+/// Stores the state of the chess engine.
+/// 
+/// The engine is run in a dedicated thread and will receive messages on [Engine::r] 
+/// 
 pub struct Engine {
     game: Game,
     move_history: RepetitionTable,

+ 17 - 11
src/evaluate.rs

@@ -4,6 +4,9 @@ use movegen::*;
 
 use std::i32;
 
+///
+/// type that is returned by the evaluate funcion
+/// 
 pub type PosValue = i32;
 
 pub const MIN_VALUE: PosValue = i32::MIN + 1;
@@ -16,10 +19,10 @@ pub fn mate() -> PosValue {
     mate_in_p1(1)
 }
 
-/**
- * constructs a PosValue that indicates that from a given position mate
- * can be achieved in turns-1 moves (not halfmoves)
- */
+/// 
+/// constructs a PosValue that indicates that from a given position mate
+/// can be achieved in turns-1 moves (not halfmoves)
+/// 
 pub fn mate_in_p1(turns: i32) -> PosValue {
     if turns < 0 {
         return -mate_in_p1(-turns);
@@ -29,13 +32,13 @@ pub fn mate_in_p1(turns: i32) -> PosValue {
     }
 }
 
-/**
- * returns Some(turns) if the pos_val indicates that mate
- * can be reached in turns-1 moves
- * 
- * turns is negative if the moving side is getting mated
- * in turns moves
- */
+/// 
+/// returns Some(turns) if the pos_val indicates that mate
+/// can be reached in turns-1 moves
+/// 
+/// turns is negative if the moving side is getting mated
+/// in turns moves
+/// 
 pub fn is_mate_in_p1(pos_val: PosValue) -> Option<i32> {
     if pos_val > MATE_CUTOFF && pos_val <= MATE_VALUE {
         Some(-pos_val + MATE_VALUE)
@@ -146,6 +149,9 @@ fn king_there(game: &Game, side: Side) -> PosValue {
     if game.get_piece(KING, side) != 0 { 10000 } else { 0 }
 }
 
+///
+/// The evaluate function of the engine
+/// 
 pub fn evaluate(game: &Game) -> PosValue {
     let sv = side_value(game, game.turn) as PosValue - side_value(game, !game.turn) as PosValue;
     let material_value_us = material_value(game, game.turn);

+ 17 - 0
src/game.rs

@@ -895,4 +895,21 @@ impl Game {
             *zv = val;
         }*/
     }
+    
+    pub fn to_vector(&self) -> Vec<f64> {
+        let mut v = Vec::new();
+        for side in [WHITE, BLACK] {
+            for pt in 0..6 {
+                for sq in 0..64 {
+                    if self.get_square(sq) == (pt, side) {
+                        v.push(1f64);
+                    }
+                    else {
+                        v.push(0f64);
+                    }
+                }
+            }
+        }
+        v
+    }
 }