dpv007 commited on
Commit
ef858e8
·
verified ·
1 Parent(s): 0ae9fab

Delete neural_engine/src/bin/test_tactics.rs with huggingface_hub

Browse files
Files changed (1) hide show
  1. neural_engine/src/bin/test_tactics.rs +0 -130
neural_engine/src/bin/test_tactics.rs DELETED
@@ -1,130 +0,0 @@
1
- use shakmaty::{Chess, Position};
2
- use std::collections::HashMap;
3
-
4
- // Paste tactical_search and related functions from main.rs here
5
- // to test what tactical_search returns for the position after 17. Qxf4.
6
-
7
- fn material_difference(board: &Chess, pov: shakmaty::Color) -> i32 {
8
- let w = board.board().white();
9
- let b = board.board().black();
10
- let score =
11
- 9 * (w.queens().count() as i32 - b.queens().count() as i32) +
12
- 5 * (w.rooks().count() as i32 - b.rooks().count() as i32) +
13
- 3 * (w.bishops().count() as i32 - b.bishops().count() as i32) +
14
- 3 * (w.knights().count() as i32 - b.knights().count() as i32) +
15
- 1 * (w.pawns().count() as i32 - b.pawns().count() as i32);
16
- if pov == shakmaty::Color::White { score } else { -score }
17
- }
18
-
19
- fn score_move(m: &shakmaty::Move) -> i32 {
20
- if m.is_capture() { 10 } else { 0 }
21
- }
22
-
23
- fn quiescence_search(board: &Chess, mut alpha: i32, beta: i32, depth: u8) -> i32 {
24
- let in_check = board.is_check();
25
- let stand_pat = material_difference(board, board.turn());
26
-
27
- if depth >= 4 || board.is_game_over() { return stand_pat; }
28
-
29
- if !in_check {
30
- if stand_pat >= beta {
31
- return beta;
32
- }
33
- if alpha < stand_pat {
34
- alpha = stand_pat;
35
- }
36
- }
37
-
38
- let mut legals: Vec<_> = board.legal_moves().into_iter().collect();
39
- legals.sort_by_cached_key(|m| -score_move(m));
40
-
41
- for m in &legals {
42
- if m.is_capture() || in_check {
43
- let mut next_board = board.clone();
44
- next_board.play_unchecked(m);
45
- let score = -quiescence_search(&next_board, -beta, -alpha, depth + 1);
46
- if score >= beta {
47
- return beta;
48
- }
49
- if score > alpha {
50
- alpha = score;
51
- }
52
- }
53
- }
54
- alpha
55
- }
56
-
57
- fn tactical_search(board: &Chess, mut alpha: i32, beta: i32, depth: u8, qs_depth: u8) -> i32 {
58
- if depth == 0 {
59
- return quiescence_search(board, alpha, beta, qs_depth);
60
- }
61
-
62
- if board.is_game_over() {
63
- if board.is_checkmate() { return -9999; }
64
- return 0;
65
- }
66
-
67
- let mut legals: Vec<_> = board.legal_moves().into_iter().collect();
68
- legals.sort_by_cached_key(|m| -score_move(m));
69
-
70
- let mut best_score = -99999;
71
- let mut first = true;
72
-
73
- for m in &legals {
74
- let mut next_board = board.clone();
75
- next_board.play_unchecked(m);
76
-
77
- let score = if first {
78
- -tactical_search(&next_board, -beta, -alpha, depth - 1, qs_depth)
79
- } else {
80
- let mut val = -tactical_search(&next_board, -alpha - 1, -alpha, depth - 1, qs_depth);
81
- if val > alpha && val < beta {
82
- val = -tactical_search(&next_board, -beta, -alpha, depth - 1, qs_depth);
83
- }
84
- val
85
- };
86
-
87
- first = false;
88
- if score > best_score {
89
- best_score = score;
90
- }
91
- if best_score > alpha {
92
- alpha = best_score;
93
- }
94
- if alpha >= beta {
95
- break;
96
- }
97
- }
98
- best_score
99
- }
100
-
101
- fn main() {
102
- use shakmaty::fen::Fen;
103
- let fen = "r2qk2r/4bppp/pn1p4/8/1Q3pP1/1N6/PPP4P/2KR1B1R w kq - 0 17";
104
- let setup: Fen = fen.parse().unwrap();
105
- let board: Chess = setup.into_position(shakmaty::CastlingMode::Standard).unwrap();
106
-
107
- let current_mat = material_difference(&board, board.turn());
108
- println!("Current Material Difference (White): {}", current_mat);
109
-
110
- // Evaluate 17. Qxf4
111
- let m = shakmaty::uci::Uci::from_ascii(b"b4f4").unwrap().to_move(&board).unwrap();
112
- let mut next_board = board.clone();
113
- next_board.play_unchecked(&m);
114
-
115
- let cand_tact = -tactical_search(&next_board, -9999, 9999, 3, 0);
116
- println!("Tactical Search Score for 17. Qxf4: {}", cand_tact);
117
-
118
- if cand_tact <= current_mat - 2 {
119
- println!("SAFETY NET WOULD TRIGGER");
120
- } else {
121
- println!("SAFETY NET FAILED TO TRIGGER");
122
- }
123
-
124
- // Check what happens if we play 17... Bg5 in tactical search
125
- let m2 = shakmaty::uci::Uci::from_ascii(b"e7g5").unwrap().to_move(&next_board).unwrap();
126
- let mut bb = next_board.clone();
127
- bb.play_unchecked(&m2);
128
- let s2 = -tactical_search(&bb, -9999, 9999, 2, 0);
129
- println!("Tactical Search Score for 17... Bg5: {}", s2);
130
- }