00001 #include "osl/checkmate/fixedDepthSearcher.h"
00002
00003 #include "osl/record/csaString.h"
00004 #include "osl/record/csaRecord.h"
00005 #include "osl/state/numEffectState.h"
00006 #include "osl/misc/perfmon.h"
00007
00008 #include <boost/scoped_ptr.hpp>
00009 #include <string>
00010 #include <iostream>
00011 #include <cstdlib>
00012 #include <unistd.h>
00013
00014 using namespace osl;
00015 using namespace osl::checkmate;
00016 using namespace osl::misc;
00017 void usage(const char *prog)
00018 {
00019 using namespace std;
00020 cerr << "Usage: " << prog << " [-d depth] csa-filenames "
00021 << endl
00022 << endl;
00023 exit(1);
00024 }
00025
00026 bool verbose=false;
00027 int num_checkmate=0, num_escape=0, num_unkown=0;
00028
00029 void search(int depth, const char *filename);
00030
00031 int main(int argc, char **argv)
00032 {
00033 const char *program_name = argv[0];
00034 int depth=2;
00035 bool error_flag = false;
00036 extern char *optarg;
00037 extern int optind;
00038
00039 char c;
00040 while ((c = getopt(argc, argv, "d:vh")) != EOF)
00041 {
00042 switch(c)
00043 {
00044 case 'd': depth = atoi(optarg);
00045 break;
00046 case 'v': verbose = true;
00047 break;
00048 default: error_flag = true;
00049 }
00050 }
00051 argc -= optind;
00052 argv += optind;
00053
00054 if (error_flag || (argc < 1))
00055 usage(program_name);
00056
00057 std::cerr << "depth " << depth << "\n";
00058 try
00059 {
00060 for (int i=0; i<argc; ++i)
00061 {
00062 search(depth, argv[i]);
00063 }
00064 std::cerr << "check " << num_checkmate << " escape " << num_escape
00065 << " unknown " << num_unkown << "\n";
00066 }
00067 catch (std::exception& e)
00068 {
00069 std::cerr << e.what() << "\n";
00070 return 1;
00071 }
00072 }
00073
00074 void search(int depth, const char *filename)
00075 {
00076 const Record rec=CsaFile(filename).getRecord();
00077 NumEffectState state(rec.getInitialState());
00078
00079 FixedDepthSearcher searcher(state);
00080
00081 Move best_move;
00082 PerfMon clock;
00083 const ProofDisproof pdp = searcher.hasCheckmateMoveOfTurn(depth, best_move);
00084 const unsigned long long total_cycles = clock.stop();
00085 const int count = searcher.getCount();
00086
00087 if (pdp.isCheckmateSuccess())
00088 {
00089 ++num_checkmate;
00090 std::cerr << "win by " << best_move << "\n";
00091 }
00092 else if (pdp.isCheckmateFail())
00093 {
00094 ++num_escape;
00095 std::cerr << "no checkmate\n";
00096 }
00097 else
00098 {
00099 ++num_unkown;
00100 std::cerr << "unknown " << pdp << "\n";
00101 }
00102
00103 PerfMon::message(total_cycles, "total ", count);
00104 }
00105
00106
00107
00108
00109
00110