fixed-checkmate.cc Source File

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
fixed-checkmate.cc
Go to the documentation of this file.
1 #include "osl/checkmate/fixedDepthSearcher.h"
2
3 #include "osl/record/csaString.h"
4 #include "osl/record/csaRecord.h"
5 #include "osl/state/numEffectState.h"
6 #include "osl/misc/perfmon.h"
7
8 #include <boost/scoped_ptr.hpp>
9 #include <string>
10 #include <iostream>
11 #include <cstdlib>
12 #include <cstdio>
13 #include <unistd.h>
14
15 using namespace osl;
16 using namespace osl::checkmate;
17 using namespace osl::misc;
18 void usage(const char *prog)
19 {
20 using namespace std;
21 cerr << "Usage: " << prog << " [-d depth] csa-filenames "
22 << endl
23 << endl;
24 exit(1);
25 }
26
27 bool verbose=false;
28 int num_checkmate=0, num_escape=0, num_unkown=0;
29
30 void search(int depth, const char *filename);
31
32 int main(int argc, char **argv)
33 {
34 const char *program_name = argv[0];
35 int depth=2;
36 bool error_flag = false;
37 extern char *optarg;
38 extern int optind;
39
40 char c;
41 while ((c = getopt(argc, argv, "d:vh")) != EOF)
42 {
43 switch(c)
44 {
45 case 'd': depth = atoi(optarg);
46 break;
47 case 'v': verbose = true;
48 break;
49 default: error_flag = true;
50 }
51 }
52 argc -= optind;
53 argv += optind;
54
55 if (error_flag || (argc < 1))
56 usage(program_name);
57
58 std::cerr << "depth " << depth << "\n";
59 try
60 {
61 for (int i=0; i<argc; ++i)
62 {
63 search(depth, argv[i]);
64 }
65 std::cerr << "check " << num_checkmate << " escape " << num_escape
66 << " unknown " << num_unkown << "\n";
67 }
68 catch (std::exception& e)
69 {
70 std::cerr << e.what() << "\n";
71 return 1;
72 }
73 }
74
75 void search(int depth, const char *filename)
76 {
77 const Record rec=CsaFile(filename).getRecord();
78 NumEffectState state(rec.getInitialState());
79
80 FixedDepthSearcher searcher(state);
81
82 Move best_move;
83 PerfMon clock;
84 const ProofDisproof pdp = searcher.hasCheckmateMoveOfTurn(depth, best_move);
85 const unsigned long long total_cycles = clock.stop();
86 const int count = searcher.getCount();
87
88 if (pdp.isCheckmateSuccess())
89 {
90 ++num_checkmate;
91 std::cerr << "win by " << best_move << "\n";
92 }
93 else if (pdp.isCheckmateFail())
94 {
95 ++num_escape;
96 std::cerr << "no checkmate\n";
97 }
98 else
99 {
100 ++num_unkown;
101 std::cerr << "unknown " << pdp << "\n";
102 }
103
104 PerfMon::message(total_cycles, "total ", count);
105 }
106
107 /* ------------------------------------------------------------------------- */
108 // ;;; Local Variables:
109 // ;;; mode:c++
110 // ;;; c-basic-offset:2
111 // ;;; End: