dpv007 commited on
Commit
83becff
·
verified ·
1 Parent(s): c00e1dc

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. neural_engine/src/main.rs +28 -1
neural_engine/src/main.rs CHANGED
@@ -92,7 +92,34 @@ fn evaluate_material(board: &Chess, color: shakmaty::Color) -> i32 {
92
  else if relative_rank == 6 { pawn_score += 3; }
93
  }
94
 
95
- pawn_score + knights as i32 * 3 + bishops as i32 * 3 + rooks as i32 * 5 + queens as i32 * 9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  }
97
 
98
  fn material_difference(board: &Chess, color: shakmaty::Color) -> i32 {
 
92
  else if relative_rank == 6 { pawn_score += 3; }
93
  }
94
 
95
+ let mut king_safety_penalty = 0;
96
+ if b.occupied().count() > 14 {
97
+ if let Some(k) = b.king_of(color) {
98
+ let k_file = k.file() as i8;
99
+ let k_rank = k.rank() as i8;
100
+ let mut pawn_shield = 0;
101
+
102
+ for sq in pawns {
103
+ let p_file = sq.file() as i8;
104
+ let p_rank = sq.rank() as i8;
105
+
106
+ if (p_file - k_file).abs() <= 1 {
107
+ if (color == shakmaty::Color::White && p_rank > k_rank && p_rank - k_rank <= 2) ||
108
+ (color == shakmaty::Color::Black && p_rank < k_rank && k_rank - p_rank <= 2) {
109
+ pawn_shield += 1;
110
+ }
111
+ }
112
+ }
113
+
114
+ if pawn_shield == 0 {
115
+ king_safety_penalty = 2;
116
+ } else if pawn_shield == 1 {
117
+ king_safety_penalty = 1;
118
+ }
119
+ }
120
+ }
121
+
122
+ pawn_score + knights as i32 * 3 + bishops as i32 * 3 + rooks as i32 * 5 + queens as i32 * 9 - king_safety_penalty
123
  }
124
 
125
  fn material_difference(board: &Chess, color: shakmaty::Color) -> i32 {