Nicolas Winkler 3 years ago
parent
commit
9862ae21c6
4 changed files with 20 additions and 8 deletions
  1. 2 2
      src/evaluate.rs
  2. 2 1
      src/main.rs
  3. 1 1
      src/movegen.rs
  4. 15 4
      src/search.rs

+ 2 - 2
src/evaluate.rs

@@ -30,8 +30,8 @@ fn side_value(game: &Game, side: Side) -> u32 {
         k_attacks += targets.count_ones() * 4;
         k_attacks += targets.count_ones() * 4;
     }
     }
 
 
-    let adv_pawn_mask = match side { WHITE => ROW_6 | ROW_7, BLACK => ROW_2 | ROW_3 };
-    let advanced_pawns = (game.get_piece(PAWN, side) & adv_pawn_mask).count_ones() * 70;
+    let adv_pawn_mask = match side { WHITE => ROW_7, BLACK => ROW_2 };
+    let advanced_pawns = (game.get_piece(PAWN, side) & adv_pawn_mask).count_ones() * 200;
 
 
     advanced_pawns + k_attacks
     advanced_pawns + k_attacks
     + game.get_piece(PAWN, side).count_ones() * 100
     + game.get_piece(PAWN, side).count_ones() * 100

+ 2 - 1
src/main.rs

@@ -25,7 +25,8 @@ fn main() {
         .init();
         .init();
         */
         */
     
     
-    //simplelog::WriteLogger::init(LevelFilter::Info, Config::default(), logfile).unwrap();
+    let logfile = File::create("C:\\\\Users\\Nicolas\\debug.log").unwrap();
+    simplelog::WriteLogger::init(LevelFilter::Info, Config::default(), logfile).unwrap();
 
 
     let (esend, erecv) = mpsc::channel();
     let (esend, erecv) = mpsc::channel();
     let (isend, irecv) = mpsc::channel();
     let (isend, irecv) = mpsc::channel();

+ 1 - 1
src/movegen.rs

@@ -190,7 +190,7 @@ pub fn sort_moves(game: &Game, move_list: &mut Vec<Move>) {
         match mov {
         match mov {
             Move::Default { mov, piece_type } => if (from_square(mov.to) & all_pieces) != 0 { -10 } else { 0 },
             Move::Default { mov, piece_type } => if (from_square(mov.to) & all_pieces) != 0 { -10 } else { 0 },
             Move::Castling { side: _, left: _ } => 0,
             Move::Castling { side: _, left: _ } => 0,
-            Move::Promotion { mov, promote_to } => -5,
+            Move::Promotion { mov, promote_to } => -15,
             Move::EnPassant { mov: _, beaten: _ } => -10,
             Move::EnPassant { mov: _, beaten: _ } => -10,
         }
         }
     });
     });

+ 15 - 4
src/search.rs

@@ -16,7 +16,7 @@ enum MoveUndo {
     Promotion {
     Promotion {
         promoted_to: PieceType,
         promoted_to: PieceType,
         promoted_to_before: Bitboard,
         promoted_to_before: Bitboard,
-
+        pawns_before: Bitboard
     }
     }
 }
 }
 
 
@@ -59,14 +59,15 @@ pub fn search(game: &Game, depth: i32) -> (Move, SearchInfo) {
 
 
     let mut valued_moves = moves.iter().map(|mov| {
     let mut valued_moves = moves.iter().map(|mov| {
         let new_game = apply_move(game, *mov);
         let new_game = apply_move(game, *mov);
+        //info!("searching {}", mov.to_string());
         let val = -negamax(&new_game, &mut si, -beta, -alpha, depth - 1);
         let val = -negamax(&new_game, &mut si, -beta, -alpha, depth - 1);
+        info!("searched {} -> {}", mov.to_string(), val);
 
 
         if val > alpha {
         if val > alpha {
             alpha = val - ALPHA_OFFSET;
             alpha = val - ALPHA_OFFSET;
             //info!("updated alpha to {}", alpha);
             //info!("updated alpha to {}", alpha);
         }
         }
 
 
-        info!("searched {} = {}", mov.to_string(), val);
         (*mov, -val)
         (*mov, -val)
     }).collect::<Vec<(Move, i32)>>();
     }).collect::<Vec<(Move, i32)>>();
     //info!("movvalues: {:?}", valued_moves.iter().map(|mv| mv.0.to_string() + " - " + &mv.1.to_string()).collect::<Vec<String>>());
     //info!("movvalues: {:?}", valued_moves.iter().map(|mv| mv.0.to_string() + " - " + &mv.1.to_string()).collect::<Vec<String>>());
@@ -89,7 +90,7 @@ pub fn search(game: &Game, depth: i32) -> (Move, SearchInfo) {
 
 
 fn negamax(game: &Game, si: &mut SearchInfo, mut alpha: i32, beta: i32, depth: i32) -> i32 {
 fn negamax(game: &Game, si: &mut SearchInfo, mut alpha: i32, beta: i32, depth: i32) -> i32 {
     if depth == 0 {
     if depth == 0 {
-        return quiescence_search(game, si, alpha, beta, 15);
+        return quiescence_search(game, si, alpha, beta, 7);
         let eval = evaluate(game);
         let eval = evaluate(game);
         if eval != 0 {
         if eval != 0 {
             //info!("eval: {}", eval);
             //info!("eval: {}", eval);
@@ -107,7 +108,7 @@ fn negamax(game: &Game, si: &mut SearchInfo, mut alpha: i32, beta: i32, depth: i
 
 
     if game.get_piece(KING, game.turn) == 0 { return MIN_VALUE; }
     if game.get_piece(KING, game.turn) == 0 { return MIN_VALUE; }
 
 
-    let moves = generate_moves(game, game.turn);
+    let moves = generate_legal_moves(game, game.turn);
 
 
     if moves.len() == 0 {
     if moves.len() == 0 {
         if is_check(game, game.turn) {
         if is_check(game, game.turn) {
@@ -172,6 +173,16 @@ fn quiescence_search(game: &Game, si: &mut SearchInfo, mut alpha: i32, beta: i32
     return alpha;
     return alpha;
 }
 }
 
 
+
+pub fn apply(game: &mut Game, mov: Move) {
+    
+}
+
+
+pub fn undo(game: &mut Game, mov: Move) {
+    
+}
+
 pub fn apply_move(game: &Game, mov: Move) -> Game {
 pub fn apply_move(game: &Game, mov: Move) -> Game {
     let mut new_game = game.clone();
     let mut new_game = game.clone();