@@ -77,10 +77,7 @@ fn parse_epd_line(line: &str) -> Result<TuningPosition> {
7777 }
7878 }
7979
80- let is_white_relative = match game_result {
81- 0.0 | 0.5 | 1.0 => true ,
82- _ => false ,
83- } ;
80+ let is_white_relative = matches ! ( game_result, 0.0 | 0.5 | 1.0 ) ;
8481
8582 let result = if is_white_relative {
8683 game_result
@@ -207,9 +204,8 @@ mod tests {
207204 ] ;
208205
209206 let mut expected_game_phases: [ f64 ; 10 ] = [ 7. , 18. , 12. , 10. , 10. , 8. , 17. , 20. , 5. , 24. ] ;
210- for i in 0 ..expected_game_phases. len ( ) {
211- // scale to [0, 1]
212- expected_game_phases[ i] /= GAME_PHASE_MAX as f64 ;
207+ for phase in & mut expected_game_phases {
208+ * phase /= GAME_PHASE_MAX as f64 ;
213209 }
214210
215211 const EXPECTED_GAME_RESULTS : [ f64 ; 10 ] = [ 0.0 , 0.0 , 0.0 , 1.0 , 1.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 ] ;
@@ -225,6 +221,7 @@ mod tests {
225221 // also verify that the evaluation matches
226222 let expected_value = eval. eval ( board) ;
227223
224+ // tuning position evaluation is always from white's perspective
228225 let val = match board. side_to_move ( ) {
229226 Side :: White => position. evaluate ( & params) ,
230227 Side :: Black => -position. evaluate ( & params) ,
@@ -274,7 +271,13 @@ mod tests {
274271 assert_eq ! ( position. game_result, expected_game_result) ;
275272 assert_eq ! ( * result, EXPECTED_PARSED_GAME_RESULTS [ i] ) ;
276273 let expected_value = eval. eval ( board) ;
277- let val = position. evaluate ( & params) ;
274+
275+ // tuning position evaluation is always from white's perspective
276+ let val = match board. side_to_move ( ) {
277+ Side :: White => position. evaluate ( & params) ,
278+ Side :: Black => -position. evaluate ( & params) ,
279+ Side :: Both => panic ! ( "Side to move cannot be both." ) ,
280+ } ;
278281 println ! ( "{} // {}" , expected_value, val) ;
279282 assert ! ( ( expected_value. 0 as f64 - val) . abs( ) . round( ) <= 1.0 )
280283 }
@@ -308,7 +311,12 @@ mod tests {
308311 assert_eq ! ( position. game_result, EXPECTED_PARSED_GAME_RESULTS [ i] ) ;
309312 assert_eq ! ( * result, EXPECTED_PARSED_GAME_RESULTS [ i] ) ;
310313 let expected_value = eval. eval ( board) ;
311- let val = position. evaluate ( & params) ;
314+ // tuning position evaluation is always from white's perspective
315+ let val = match board. side_to_move ( ) {
316+ Side :: White => position. evaluate ( & params) ,
317+ Side :: Black => -position. evaluate ( & params) ,
318+ Side :: Both => panic ! ( "Side to move cannot be both." ) ,
319+ } ;
312320 println ! ( "{} // {}" , expected_value, val) ;
313321 assert ! ( ( expected_value. 0 as f64 - val) . abs( ) . round( ) <= 1.0 )
314322 }
0 commit comments