@@ -18,7 +18,6 @@ use std::io::{Read, Write};
18
18
use engine:: src:: game:: to_lower;
19
19
use std:: cmp:: Ordering ;
20
20
use std:: fs:: File ;
21
- use std:: ptr:: null_mut;
22
21
23
22
/* Local variables */
24
23
static mut thor_game_count: i32 = 0 ;
@@ -585,7 +584,7 @@ pub unsafe fn sort_thor_games(count: i32) {
585
584
}
586
585
let sord_order = & thor_sort_order[ 0 ..thor_sort_criteria_count as usize ] ;
587
586
thor_search. match_list . sort_by ( |g1, g2| {
588
- match unsafe { thor_compare ( & * * g1 , & * * g2 , sord_order, & players, & tournaments) } {
587
+ match unsafe { thor_compare ( g1 . unwrap ( ) , g2 . unwrap ( ) , sord_order, & players, & tournaments) } {
589
588
i32:: MIN ..=-1_i32 => Ordering :: Less ,
590
589
0 => Ordering :: Equal ,
591
590
1_i32 ..=i32:: MAX => Ordering :: Greater ,
@@ -605,7 +604,7 @@ pub unsafe fn print_thor_matches(mut stream: &mut impl Write, max_games: i32) {
605
604
if i == 0 {
606
605
stream. write ( b"\n " ) ;
607
606
}
608
- print_game ( & mut stream, & * * thor_search. match_list . offset ( i as isize ) , 0 , & tournaments, & players) ;
607
+ print_game ( & mut stream, thor_search. match_list . offset ( i as isize ) . unwrap ( ) , 0 , & tournaments, & players) ;
609
608
i += 1
610
609
} ;
611
610
}
@@ -1353,7 +1352,7 @@ unsafe fn get_thor_game(index: i32) -> GameInfoType {
1353
1352
info. black_corrected_score = 32
1354
1353
} else {
1355
1354
/* Copy name fields etc */
1356
- let game = * thor_search. match_list . offset ( index as isize ) ;
1355
+ let game = thor_search. match_list . offset ( index as isize ) . unwrap ( ) ;
1357
1356
info. black_name = players. get_player_name ( ( * game) . black_no as i32 ) ;
1358
1357
info. white_name = players. get_player_name ( ( * game) . white_no as i32 ) ;
1359
1358
info. tournament = tournaments. tournament_name ( ( * game) . tournament_no as i32 ) ;
@@ -1530,7 +1529,7 @@ impl ThorBoard {
1530
1529
Play the MAX_MOVES first moves of GAME and update THOR_BOARD
1531
1530
and THOR_SIDE_TO_MOVE to represent the position after those moves.
1532
1531
*/
1533
- fn play_through_game ( & mut self , game : & mut GameType , max_moves : i32 ) -> i32 {
1532
+ fn play_through_game ( & mut self , game : & GameType , max_moves : i32 ) -> i32 {
1534
1533
let mut move_0: i32 = 0 ;
1535
1534
let mut flipped: i32 = 0 ;
1536
1535
clear_thor_board ( & mut self . board ) ;
@@ -1653,10 +1652,10 @@ fn prepare_game(mut game: &mut GameType, thor_board: &mut ThorBoard, tree: &mut
1653
1652
}
1654
1653
( * game) . opening = opening;
1655
1654
/* Initialize the shape state */
1656
- ( * game) . shape_lo = 3 << 27 ;
1657
- ( * game) . shape_hi = 3 << 3 ;
1658
- ( * game) . shape_state_hi = 0 ;
1659
- ( * game) . shape_state_lo = 0 ;
1655
+ ( * game) . shape_lo . set ( 3 << 27 ) ;
1656
+ ( * game) . shape_hi . set ( 3 << 3 ) ;
1657
+ ( * game) . shape_state_hi . set ( 0 ) ;
1658
+ ( * game) . shape_state_lo . set ( 0 ) ;
1660
1659
/* Store the corner descriptor */
1661
1660
( * game) . corner_descriptor = corner_descriptor;
1662
1661
}
@@ -1919,19 +1918,18 @@ pub unsafe fn init_thor_database(random: &mut MyRandom) {
1919
1918
*/
1920
1919
1921
1920
unsafe fn get_thor_game_moves ( index : i32 , move_count : & mut i32 , moves : & mut [ i32 ] ) {
1922
- let mut game = 0 as * mut GameType ;
1923
1921
if index < 0 || index >= thor_search. match_count {
1924
1922
/* Bad index, so fill with empty values */
1925
1923
* move_count = 0
1926
1924
} else {
1927
- game = * thor_search. match_list . offset ( index as isize ) ;
1925
+ let game = thor_search. match_list . offset ( index as isize ) . unwrap ( ) ;
1928
1926
* move_count = ( * game) . move_count as i32 ;
1929
- match ( * game) . matching_symmetry as i32 {
1927
+ match ( * game) . matching_symmetry . get ( ) as i32 {
1930
1928
0 | 2 | 5 | 7 => {
1931
1929
/* Symmetries that preserve the initial position. */
1932
1930
let mut i = 0 ;
1933
1931
while i < ( * game) . move_count as i32 {
1934
- * moves. offset ( i as isize ) = * symmetry_map[ ( * game) . matching_symmetry as usize ] . offset ( abs ( ( * game) . moves [ i as usize ] as i32 ) as isize ) ;
1932
+ * moves. offset ( i as isize ) = * symmetry_map[ ( * game) . matching_symmetry . get ( ) as usize ] . offset ( abs ( ( * game) . moves [ i as usize ] as i32 ) as isize ) ;
1935
1933
i += 1
1936
1934
}
1937
1935
}
@@ -1956,12 +1954,12 @@ pub unsafe fn get_thor_game_move(index: i32, move_number: i32) -> i32 {
1956
1954
if index < 0 || index >= thor_search. match_count {
1957
1955
-1
1958
1956
} else {
1959
- let game = * thor_search. match_list . offset ( index as isize ) ;
1957
+ let game = thor_search. match_list . offset ( index as isize ) . unwrap ( ) ;
1960
1958
if move_number < 0 ||
1961
1959
move_number >= ( * game) . move_count as i32 {
1962
1960
-1
1963
1961
} else {
1964
- * symmetry_map[ ( * game) . matching_symmetry as usize ] . offset ( abs ( ( * game) . moves [ move_number as usize ] as i32 ) as isize )
1962
+ * symmetry_map[ ( * game) . matching_symmetry . get ( ) as usize ] . offset ( abs ( ( * game) . moves [ move_number as usize ] as i32 ) as isize )
1965
1963
}
1966
1964
}
1967
1965
}
@@ -1972,7 +1970,7 @@ pub unsafe fn get_thor_game_move(index: i32, move_number: i32) -> i32 {
1972
1970
SIDE_TO_MOVE being the player to move, matches the hash codes
1973
1971
IN_HASH1 and IN_HASH2, otherwise FALSE.
1974
1972
*/
1975
- fn position_match ( mut game : & mut GameType ,
1973
+ fn position_match ( mut game : & GameType ,
1976
1974
thor_board : & mut ThorBoard ,
1977
1975
thor_hash_ : & mut ThorHash ,
1978
1976
tree : & mut ThorOpeningTree ,
@@ -2010,58 +2008,58 @@ fn position_match(mut game: &mut GameType,
2010
2008
/* Check if the opening information suffices to
2011
2009
determine if the position matches or not. */
2012
2010
if ( tree[ game. opening ] ) . current_match == 1 {
2013
- ( * game) . matching_symmetry = ( tree[ game. opening ] ) . matching_symmetry as i16 ;
2011
+ ( * game) . matching_symmetry . set ( ( tree[ game. opening ] ) . matching_symmetry as i16 ) ;
2014
2012
return 1
2015
2013
} else {
2016
2014
if ( tree[ game. opening ] ) . current_match == 2 {
2017
2015
return 0
2018
2016
}
2019
2017
}
2020
2018
/* Check if the lower 32 bits of the shape state coincide */
2021
- if ( ( * game) . shape_state_lo as i32 ) < move_count {
2022
- i = ( * game) . shape_state_lo as i32 ;
2019
+ if ( ( * game) . shape_state_lo . get ( ) as i32 ) < move_count {
2020
+ i = ( * game) . shape_state_lo . get ( ) as i32 ;
2023
2021
while i < move_count {
2024
- ( * game) . shape_lo |= move_mask_lo[ abs ( ( * game) . moves [ i as usize ] as i32 ) as usize ] ;
2022
+ ( * game) . shape_lo . set ( ( * game ) . shape_lo . get ( ) | move_mask_lo[ abs ( ( * game) . moves [ i as usize ] as i32 ) as usize ] ) ;
2025
2023
i += 1
2026
2024
}
2027
- ( * game) . shape_state_lo = move_count as i16
2028
- } else if ( * game) . shape_state_lo as i32 > move_count {
2029
- i = ( * game) . shape_state_lo as i32 - 1 ;
2025
+ ( * game) . shape_state_lo . set ( move_count as i16 )
2026
+ } else if ( * game) . shape_state_lo . get ( ) as i32 > move_count {
2027
+ i = ( * game) . shape_state_lo . get ( ) as i32 - 1 ;
2030
2028
while i >= move_count {
2031
- ( * game) . shape_lo &= !move_mask_lo[ abs ( ( * game) . moves [ i as usize ] as i32 ) as usize ] ;
2029
+ ( * game) . shape_lo . set ( ( * game ) . shape_lo . get ( ) & !move_mask_lo[ abs ( ( * game) . moves [ i as usize ] as i32 ) as usize ] ) ;
2032
2030
i -= 1
2033
2031
}
2034
- ( * game) . shape_state_lo = move_count as i16
2032
+ ( * game) . shape_state_lo . set ( move_count as i16 ) ;
2035
2033
}
2036
2034
shape_match = 0 ;
2037
2035
i = 0 ;
2038
2036
while i < 8 {
2039
- shape_match |= ( ( * game) . shape_lo == * shape_lo. offset ( i as isize ) ) as i32 ;
2037
+ shape_match |= ( ( * game) . shape_lo . get ( ) == * shape_lo. offset ( i as isize ) ) as i32 ;
2040
2038
i += 1
2041
2039
}
2042
2040
if shape_match == 0 {
2043
2041
return 0
2044
2042
}
2045
2043
/* Check if the upper 32 bits of the shape state coincide */
2046
- if ( ( * game) . shape_state_hi as i32 ) < move_count {
2047
- i = ( * game) . shape_state_hi as i32 ;
2044
+ if ( ( * game) . shape_state_hi . get ( ) as i32 ) < move_count {
2045
+ i = ( * game) . shape_state_hi . get ( ) as i32 ;
2048
2046
while i < move_count {
2049
- ( * game) . shape_hi |= move_mask_hi[ abs ( ( * game) . moves [ i as usize ] as i32 ) as usize ] ;
2047
+ ( * game) . shape_hi . set ( ( * game ) . shape_hi . get ( ) | move_mask_hi[ abs ( ( * game) . moves [ i as usize ] as i32 ) as usize ] ) ;
2050
2048
i += 1
2051
2049
}
2052
- ( * game) . shape_state_hi = move_count as i16
2053
- } else if ( * game) . shape_state_hi as i32 > move_count {
2054
- i = ( * game) . shape_state_hi as i32 - 1 ;
2050
+ ( * game) . shape_state_hi . set ( move_count as i16 )
2051
+ } else if ( * game) . shape_state_hi . get ( ) as i32 > move_count {
2052
+ i = ( * game) . shape_state_hi . get ( ) as i32 - 1 ;
2055
2053
while i >= move_count {
2056
- ( * game) . shape_hi &= !move_mask_hi[ abs ( ( * game) . moves [ i as usize ] as i32 ) as usize ] ;
2054
+ ( * game) . shape_hi . set ( ( * game ) . shape_hi . get ( ) & !move_mask_hi[ abs ( ( * game) . moves [ i as usize ] as i32 ) as usize ] ) ;
2057
2055
i -= 1
2058
2056
}
2059
- ( * game) . shape_state_hi = move_count as i16
2057
+ ( * game) . shape_state_hi . set ( move_count as i16 )
2060
2058
}
2061
2059
shape_match = 0 ;
2062
2060
i = 0 ;
2063
2061
while i < 8 {
2064
- shape_match |= ( ( * game) . shape_hi == * shape_hi. offset ( i as isize ) ) as i32 ;
2062
+ shape_match |= ( ( * game) . shape_hi . get ( ) == * shape_hi. offset ( i as isize ) ) as i32 ;
2065
2063
i += 1
2066
2064
}
2067
2065
if shape_match == 0 {
@@ -2084,7 +2082,7 @@ fn position_match(mut game: &mut GameType,
2084
2082
i = 0 ;
2085
2083
while i < 8 {
2086
2084
if primary_hit_mask & secondary_hit_mask & ( 1 ) << i != 0 {
2087
- ( * game) . matching_symmetry = i as i16 ;
2085
+ ( * game) . matching_symmetry . set ( i as i16 ) ;
2088
2086
return 1
2089
2087
}
2090
2088
i += 1
@@ -2274,7 +2272,6 @@ pub unsafe fn database_search(in_board: &[i32], side_to_move: i32) {
2274
2272
let mut corner_mask: u32 = 0 ;
2275
2273
let mut shape_lo: [ u32 ; 8 ] = [ 0 ; 8 ] ;
2276
2274
let mut shape_hi: [ u32 ; 8 ] = [ 0 ; 8 ] ;
2277
- let mut game;
2278
2275
/* We need a player and a tournament database. */
2279
2276
if players. count ( ) == 0 ||
2280
2277
tournaments. count ( ) == 0 {
@@ -2284,10 +2281,10 @@ pub unsafe fn database_search(in_board: &[i32], side_to_move: i32) {
2284
2281
/* Make sure there's memory allocated if all positions
2285
2282
in all databases match the position */
2286
2283
if thor_search. allocation == 0 {
2287
- thor_search. match_list = vec ! [ null_mut ( ) ; thor_game_count as usize ] ;
2284
+ thor_search. match_list = vec ! [ Default :: default ( ) ; thor_game_count as usize ] ;
2288
2285
thor_search. allocation = thor_game_count
2289
2286
} else if thor_search. allocation < thor_game_count {
2290
- thor_search. match_list = vec ! [ null_mut ( ) ; thor_game_count as usize ] ;
2287
+ thor_search. match_list = vec ! [ Default :: default ( ) ; thor_game_count as usize ] ;
2291
2288
thor_search. allocation = thor_game_count
2292
2289
}
2293
2290
/* If necessary, filter all games in the database */
@@ -2297,22 +2294,22 @@ pub unsafe fn database_search(in_board: &[i32], side_to_move: i32) {
2297
2294
}
2298
2295
/* If necessary, sort all games in the database */
2299
2296
if thor_games_sorted == 0 {
2300
- let mut current_db_ = & mut database_head;
2297
+ let mut current_db_ = & database_head;
2301
2298
i = 0 ;
2302
2299
while let Some ( current_db) = current_db_ {
2303
2300
j = 0 ;
2304
2301
while j < ( * current_db) . count {
2305
2302
let ref mut fresh5 = * thor_search. match_list . offset ( i as isize ) ;
2306
- * fresh5 = & mut * ( * current_db) . games . offset ( j as isize ) as * mut GameType ;
2303
+ * fresh5 = Some ( ( * current_db) . games . as_slice ( ) . offset ( j as isize ) ) ;
2307
2304
i += 1 ;
2308
2305
j += 1
2309
2306
}
2310
- current_db_ = & mut ( * current_db) . next
2307
+ current_db_ = & ( * current_db) . next
2311
2308
}
2312
2309
sort_thor_games ( thor_game_count) ;
2313
2310
j = 0 ;
2314
2311
while j < thor_game_count {
2315
- ( * * thor_search. match_list . offset ( j as isize ) ) . sort_order = j ;
2312
+ ( thor_search. match_list . offset ( j as isize ) ) . unwrap ( ) . sort_order . set ( j ) ;
2316
2313
j += 1
2317
2314
}
2318
2315
thor_games_sorted = 1
@@ -2421,7 +2418,7 @@ pub unsafe fn database_search(in_board: &[i32], side_to_move: i32) {
2421
2418
i = 0 ;
2422
2419
while i < thor_game_count {
2423
2420
let ref mut fresh6 = * thor_search. match_list . offset ( i as isize ) ;
2424
- * fresh6 = 0 as * mut GameType ;
2421
+ * fresh6 = None ; // 0 as *mut GameType;
2425
2422
i += 1
2426
2423
}
2427
2424
i = 0 ;
@@ -2435,17 +2432,17 @@ pub unsafe fn database_search(in_board: &[i32], side_to_move: i32) {
2435
2432
thor_search. next_move_score [ i as usize ] = 0.0f64 ;
2436
2433
i += 1
2437
2434
}
2438
- let mut current_db_ = & mut database_head;
2435
+ let mut current_db_ = & database_head;
2439
2436
while let Some ( current_db) = current_db_ {
2440
2437
i = 0 ;
2441
2438
while i < ( * current_db) . count {
2442
- game = & mut * ( * current_db) . games . offset ( i as isize ) ;
2439
+ let game = ( * current_db) . games . as_slice ( ) . offset ( i as isize ) ;
2443
2440
if ( * game) . passes_filter != 0 {
2444
2441
if disc_count[ 0 ] == ( * game) . black_disc_count [ move_count as usize ] as i32 {
2445
2442
if position_match ( game, & mut board, & mut thor_hash, & mut thor_opening_tree, move_count, side_to_move, & mut shape_lo, & mut shape_hi, corner_mask, target_hash1, target_hash2) != 0 {
2446
- let ref mut fresh7 = * thor_search. match_list . offset ( ( * game) . sort_order as isize ) ;
2447
- * fresh7 = game;
2448
- symmetry = ( * game) . matching_symmetry as i32 ;
2443
+ let ref mut fresh7 = * thor_search. match_list . offset ( game. sort_order . get ( ) as _ ) ;
2444
+ * fresh7 = Some ( game) ;
2445
+ symmetry = ( game) . matching_symmetry . get ( ) as i32 ;
2449
2446
if move_count < ( * game) . move_count as i32 {
2450
2447
next_move = * symmetry_map[ symmetry as usize ] . offset (
2451
2448
abs ( ( * game) . moves [ move_count as usize ] as i32 ) as isize
@@ -2468,7 +2465,7 @@ pub unsafe fn database_search(in_board: &[i32], side_to_move: i32) {
2468
2465
}
2469
2466
i += 1
2470
2467
}
2471
- current_db_ = & mut ( * current_db) . next
2468
+ current_db_ = & ( * current_db) . next
2472
2469
}
2473
2470
/* Remove the NULLs from the list of matching games if there are any.
2474
2471
This gives a sorted list. */
@@ -2477,7 +2474,7 @@ pub unsafe fn database_search(in_board: &[i32], side_to_move: i32) {
2477
2474
i = 0 ;
2478
2475
j = 0 ;
2479
2476
while i < thor_search. match_count {
2480
- if !( * thor_search. match_list . offset ( j as isize ) ) . is_null ( ) {
2477
+ if !( * thor_search. match_list . offset ( j as isize ) ) . is_none ( ) {
2481
2478
let ref mut fresh8 = * thor_search. match_list . offset ( i as isize ) ;
2482
2479
* fresh8 = * thor_search. match_list . offset ( j as isize ) ;
2483
2480
i += 1
0 commit comments