1
+ use std:: fs:: remove_file;
2
+ use std:: mem;
1
3
use std:: time:: Duration ;
2
4
3
-
4
5
use crate :: algorithms:: the_algorithm:: Algorithm ;
5
6
#[ allow( unused_imports) ]
6
- use crate :: common:: constants:: { modules:: {
7
- ALPHA_BETA , ANALYZE , NAIVE_PSQT , PAWN_STRUCTURE , SEARCH_EXTENSIONS , SKIP_BAD_MOVES ,
8
- SQUARE_CONTROL_METRIC , TAPERED_EVERY_PESTO_PSQT , TAPERED_INCREMENTAL_PESTO_PSQT ,
9
- TRANSPOSITION_TABLE ,
10
- } , NUMBER_OF_MODULES } ;
11
- use crate :: io:: { write_result, modules_to_string} ;
7
+ use crate :: common:: constants:: {
8
+ modules:: {
9
+ ALPHA_BETA , ANALYZE , NAIVE_PSQT , PAWN_STRUCTURE , SEARCH_EXTENSIONS , SKIP_BAD_MOVES ,
10
+ SQUARE_CONTROL_METRIC , TAPERED_EVERY_PESTO_PSQT , TAPERED_INCREMENTAL_PESTO_PSQT ,
11
+ TRANSPOSITION_TABLE ,
12
+ } ,
13
+ NUMBER_OF_MODULES ,
14
+ } ;
15
+ use crate :: io:: write_result;
12
16
13
17
use self :: pitter:: logic:: { Competition , CompetitionResults } ;
14
18
15
19
mod algorithms;
16
20
mod common;
21
+ mod io;
17
22
mod modules;
18
23
mod pitter;
19
- mod io;
20
24
21
25
//If we should print the moves played and results of each game.
22
26
pub ( crate ) const PRINT_GAME : bool = true ;
23
27
//If we should test all possible pairs of combinations.
24
28
const TEST_ALL_PAIRS : bool = true ;
25
29
26
-
27
30
#[ tokio:: main]
28
31
async fn main ( ) {
32
+ remove_file ( "./output.txt" ) . unwrap_or_default ( ) ;
29
33
if !TEST_ALL_PAIRS {
30
34
//ALPHA_BETA | ANALYZE | SEARCH_EXTENSIONS | SKIP_BAD_MOVES | SQUARE_CONTROL_METRIC | TRANSPOSITION_TABLE | NAIVE_PSQT | PAWN_STRUCTURE | TAPERED_EVERY_PESTO_PSQT | TAPERED_INCREMENTAL_PESTO_PSQT
31
35
//Put 0 for no modules.
32
36
//Setup modules
33
- let modules1 = ALPHA_BETA | TAPERED_INCREMENTAL_PESTO_PSQT ;
34
- let modules2 = ALPHA_BETA | TAPERED_EVERY_PESTO_PSQT ;
37
+ let modules1 = TRANSPOSITION_TABLE ;
38
+ let modules2 = 0 ;
35
39
let time_per_move1 = Duration :: from_micros ( 2000 ) ;
36
40
let time_per_move2 = Duration :: from_micros ( 2000 ) ;
37
- let game_pairs = 500 ;
41
+ let game_pairs = 50 ;
38
42
39
43
//Run competition
40
- let result = do_competition ( modules1, modules2, time_per_move1, time_per_move2, game_pairs) . await ;
41
-
42
- //Save results to file
43
- let mut output: String = "\n Algo 1 modules: " . to_owned ( ) + & modules_to_string ( modules1) + "\n Algo 2 modules: " + & modules_to_string ( modules2)
44
- + & "\n Game pairs: " + & game_pairs. to_string ( ) + & "\n Time per move, algo1: " + & format ! ( "{:?}" , time_per_move1) + "\n Time per move, algo2: " + & format ! ( "{:?}" , time_per_move2) ;
45
- let result = format ! ( "\n Competition results: {:#?}" , & result) ;
46
- output = output + & result + & "\n \n \n " ;
47
- let buf = output. as_bytes ( ) ;
48
- let _ = write_result ( buf, "./output.txt" ) ;
49
-
44
+ let result = do_competition (
45
+ modules1,
46
+ modules2,
47
+ time_per_move1,
48
+ time_per_move2,
49
+ game_pairs,
50
+ )
51
+ . await ;
52
+ dbg ! ( result) ;
50
53
} else {
51
- println ! ( "Running {} possibilites" , ( NUMBER_OF_MODULES +1 ) * NUMBER_OF_MODULES /2 ) ;
54
+ println ! (
55
+ "Running {} possibilites" ,
56
+ ( NUMBER_OF_MODULES + 1 ) * NUMBER_OF_MODULES / 2
57
+ ) ;
52
58
let time_per_move1 = Duration :: from_micros ( 2000 ) ;
53
59
let time_per_move2 = Duration :: from_micros ( 2000 ) ;
54
- let game_pairs = 1000 ;
55
-
60
+ let game_pairs = 200 ;
61
+
56
62
let mut competitions_run: u32 = 0 ;
57
- for i in 0 ..NUMBER_OF_MODULES +1 {
58
- for j in i+1 ..NUMBER_OF_MODULES +1 {
63
+ let mut dp: Vec < Vec < Option < CompetitionResults > > > =
64
+ vec ! [ vec![ None ; NUMBER_OF_MODULES ] ; NUMBER_OF_MODULES ] ;
65
+ for i in 0 ..NUMBER_OF_MODULES {
66
+ for j in 0 ..NUMBER_OF_MODULES {
67
+ if dp[ j] [ i] . is_some ( ) {
68
+ let mut temp = dp[ j] [ i] . unwrap ( ) ;
69
+ let output: String =
70
+ format ! ( "{}\t " , temp. algo2_wins as i64 - temp. algo1_wins as i64 ) ;
71
+ let buf = output. as_bytes ( ) ;
72
+ let _ = write_result ( buf, "./output.txt" ) ;
73
+ mem:: swap ( & mut temp. algo1_wins , & mut temp. algo2_wins ) ;
74
+ dp[ i] [ j] = Some ( temp) ;
75
+ continue ;
76
+ }
59
77
competitions_run += 1 ;
60
- println ! ( "\r Testing pair {} out of {}" , competitions_run, ( NUMBER_OF_MODULES +1 ) * NUMBER_OF_MODULES /2 ) ;
61
- let modules1 = 1 << i;
62
- let modules2 = 1 << j;
78
+ println ! (
79
+ "\r Testing pair {} out of {}" ,
80
+ competitions_run,
81
+ ( NUMBER_OF_MODULES + 1 ) * NUMBER_OF_MODULES / 2
82
+ ) ;
83
+
84
+ // Analyze is useless in this scenario
85
+ let modules1 = 1 << j;
86
+ let modules1 = if modules1 == ANALYZE { 0 } else { modules1 } ;
87
+ let modules2 = 1 << i;
88
+ let modules2 = if modules2 == ANALYZE { 0 } else { modules2 } ;
63
89
64
- let result = do_competition ( modules1, modules2, time_per_move1, time_per_move2, game_pairs) . await ;
90
+ let result = do_competition (
91
+ modules1,
92
+ modules2,
93
+ time_per_move1,
94
+ time_per_move2,
95
+ game_pairs,
96
+ )
97
+ . await ;
65
98
66
- let mut output: String = "\n Algo 1 modules: " . to_owned ( ) + & modules_to_string ( modules1) + "\n Algo 2 modules: " + & modules_to_string ( modules2)
67
- + & "\n Game pairs: " + & game_pairs. to_string ( ) + & "\n Time per move, algo1: " + & format ! ( "{:?}" , time_per_move1) + "\n Time per move, algo2: " + & format ! ( "{:?}" , time_per_move2) ;
68
- let result = format ! ( "\n Competition results: {:#?}" , & result) ;
69
- output = output + & result + & "\n \n \n " ;
99
+ dp[ i] [ j] = Some ( result) ;
100
+ let output: String =
101
+ format ! ( "{}\t " , result. algo1_wins as i64 - result. algo2_wins as i64 ) ;
70
102
let buf = output. as_bytes ( ) ;
71
- let _ = write_result ( buf, "./output.txt" ) ;
103
+ let _ = write_result ( buf, "./output.txt" ) ;
72
104
}
105
+ let _ = write_result ( "\n " . as_bytes ( ) , "./output.txt" ) ;
73
106
}
74
107
}
75
-
76
108
}
77
109
78
- async fn do_competition ( modules1 : u32 , modules2 : u32 , time_per_move1 : Duration , time_per_move2 : Duration , game_pairs : u32 ) -> CompetitionResults {
110
+ async fn do_competition (
111
+ modules1 : u32 ,
112
+ modules2 : u32 ,
113
+ time_per_move1 : Duration ,
114
+ time_per_move2 : Duration ,
115
+ game_pairs : u32 ,
116
+ ) -> CompetitionResults {
79
117
let competition = Competition :: new (
80
118
Algorithm :: new ( modules1, time_per_move1) ,
81
119
Algorithm :: new ( modules2, time_per_move2) ,
@@ -84,6 +122,5 @@ async fn do_competition(modules1: u32, modules2: u32, time_per_move1: Duration,
84
122
// competition.analyze_algorithm_choices(|(game_info, _), _| {
85
123
// game_info.outcome == GameOutcome::InconclusiveTooLong
86
124
// });
87
- let results = competition. start_competition ( game_pairs) . await ;
88
- results
125
+ competition. start_competition ( game_pairs) . await
89
126
}
0 commit comments