quiescence2stat.cc Source File

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
quiescence2stat.cc
Go to the documentation of this file.
1 /* quiescencestat.cc
2 */
3 #include "osl/search/quiescenceSearch2.h"
4 #include "osl/search/simpleHashTable.h"
5 #include "osl/search/searchState2.h"
6 #include "osl/effect_util/effectUtil.h"
7 #include "osl/record/csaString.h"
8 #include "osl/record/csaRecord.h"
9 #include "osl/eval/ml/openMidEndingEval.h"
10 #include "osl/misc/perfmon.h"
11
12 #include <iostream>
13 #include <fstream>
14 #include <cstdio>
15
16 using namespace osl;
17 using namespace osl::search;
18 using namespace osl::misc;
19
20 void qsearch(const char *filename);
21
22 void usage(const char *program_name)
23 {
24 std::cerr << program_name << " [-d depth] [-s skip] [-v] [-p] csafiles\n";
25 exit(1);
26 }
27
28 int depth = -2;
29 bool verbose = false, problem_solving = false;
30 size_t skip_first = 0;
31
32 void qsearch(const char *filename);
33
34 int main(int argc, char **argv)
35 {
36 const char *program_name = argv[0];
37 bool error_flag = false;
38
39 extern char *optarg;
40 extern int optind;
41 char c;
42 while ((c = getopt(argc, argv, "d:s:pvh")) != EOF)
43 {
44 switch(c)
45 {
46 case 'd': depth = atoi(optarg);
47 break;
48 case 's': skip_first = atoi(optarg);
49 break;
50 case 'p': problem_solving = true;
51 break;
52 case 'v': verbose = true;
53 break;
54 default: error_flag = true;
55 }
56 }
57 argc -= optind;
58 argv += optind;
59
60 if (error_flag || (argc < 1))
61 usage(program_name);
62
63 std::cerr << "using table record depth " << depth << "\n";
64 eval::ml::OpenMidEndingEval::setUp();
65 progress::ml::NewProgress::setUp();
66 try
67 {
68 for (int i=0; i<argc; ++i)
69 {
70 qsearch(argv[i]);
71 }
72 }
73 catch (std::exception& e)
74 {
75 std::cerr << e.what() << "\n";
76 return 1;
77 }
78 catch (...)
79 {
80 throw;
81 }
82 }
83
84 void qsearch(const char *filename)
85 {
86 if (verbose)
87 std::cerr << filename;
88 unsigned long long total_cycles=0;
89 unsigned long long positions = 0;
90 Record rec=CsaFile(filename).getRecord();
91 NumEffectState state(rec.getInitialState());
92 const vector<osl::Move> moves=rec.getMoves();
93
94 typedef QuiescenceSearch2<eval::ml::OpenMidEndingEval> qsearch_t;
95
96 SimpleHashTable table(1000000,depth,verbose);
97 SearchState2Core::checkmate_t checkmate_searcher;
98 eval::ml::OpenMidEndingEval ev(state);
99 size_t i=0;
100 Player initial_turn = state.turn();
101 while (true)
102 {
103 if (i >= skip_first)
104 {
105 SearchState2Core core(state, checkmate_searcher);
106 qsearch_t qs(core, table);
107 const Move last_move = (i > 0) ? moves[i-1] : Move::PASS(alt(initial_turn));
108 if (verbose)
109 std::cerr << i << " " << last_move << "\n";
110 if (problem_solving)
111 {
112 std::cout << state;
113 table.allocate(HashKey(state), 1000);
114 }
115 PerfMon clock;
116 const int val = qs.search(state.turn(), ev, last_move, 4);
117 total_cycles += clock.stop();
118 positions += qs.nodeCount();
119
120 if (verbose || problem_solving)
121 {
122 const SimpleHashRecord *record = table.find(HashKey(state));
123 std::cout << "result ";
124 if (record)
125 std::cout << record::csa::show(record->qrecord.bestMove()) << " ";
126 std::cout << val << "\n";
127 if (i < moves.size())
128 std::cout << "recorded " << record::csa::show(moves[i]) << "\n";
129 }
130 }
131 if (i >= moves.size() || problem_solving)
132 break;
133 const Move move = moves[i++];
134 state.makeMove(move);
135 ev.update(state, move);
136 }
137 const size_t checkmate_count = checkmate_searcher.totalNodeCount();
138 std::cerr << total_cycles << " / ( " << positions
139 << " + " << checkmate_count << " ) = "
140 << total_cycles/(double)(positions + checkmate_count) << "\n";
141 }
142
143 /* ------------------------------------------------------------------------- */
144 // ;;; Local Variables:
145 // ;;; mode:c++
146 // ;;; c-basic-offset:2
147 // ;;; End: