fixed-checkmate.cc
Go to the documentation of this file.
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 <cstdio>
00013 #include <unistd.h>
00014 
00015 using namespace osl;
00016 using namespace osl::checkmate;
00017 using namespace osl::misc;
00018 void usage(const char *prog)
00019 {
00020   using namespace std;
00021   cerr << "Usage: " << prog << " [-d depth] csa-filenames "
00022        << endl
00023        << endl;
00024   exit(1);
00025 }
00026 
00027 bool verbose=false;
00028 int num_checkmate=0, num_escape=0, num_unkown=0;
00029 
00030 void search(int depth, const char *filename);
00031 
00032 int main(int argc, char **argv)
00033 {
00034   const char *program_name = argv[0];
00035   int depth=2;
00036   bool error_flag = false;
00037   extern char *optarg;
00038   extern int optind;
00039   
00040   char c;
00041   while ((c = getopt(argc, argv, "d:vh")) != EOF)
00042   {
00043     switch(c)
00044     {
00045     case 'd':   depth = atoi(optarg);
00046       break;
00047     case 'v':   verbose = true;
00048       break;
00049     default:    error_flag = true;
00050     }
00051   }
00052   argc -= optind;
00053   argv += optind;
00054 
00055   if (error_flag || (argc < 1))
00056     usage(program_name);
00057 
00058   std::cerr << "depth " << depth << "\n";
00059   try
00060   {
00061     for (int i=0; i<argc; ++i)
00062     {
00063       search(depth, argv[i]);
00064     }
00065     std::cerr << "check " << num_checkmate << " escape " << num_escape
00066               << " unknown " << num_unkown << "\n";
00067   }
00068   catch (std::exception& e)
00069   {
00070     std::cerr << e.what() << "\n";
00071     return 1;
00072   }
00073 }
00074 
00075 void search(int depth, const char *filename)
00076 {
00077   const Record rec=CsaFile(filename).getRecord();
00078   NumEffectState state(rec.getInitialState());
00079 
00080   FixedDepthSearcher searcher(state);
00081 
00082   Move best_move;
00083   PerfMon clock;
00084   const ProofDisproof pdp = searcher.hasCheckmateMoveOfTurn(depth, best_move);
00085   const unsigned long long total_cycles = clock.stop();
00086   const int count = searcher.getCount();
00087 
00088   if (pdp.isCheckmateSuccess())
00089   {
00090     ++num_checkmate;
00091     std::cerr << "win by " << best_move << "\n";
00092   }
00093   else if (pdp.isCheckmateFail())
00094   {
00095     ++num_escape;
00096     std::cerr << "no checkmate\n";
00097   }
00098   else
00099   {
00100     ++num_unkown;
00101     std::cerr << "unknown " << pdp << "\n";
00102   }
00103 
00104   PerfMon::message(total_cycles, "total ", count);
00105 }
00106 
00107 /* ------------------------------------------------------------------------- */
00108 // ;;; Local Variables:
00109 // ;;; mode:c++
00110 // ;;; c-basic-offset:2
00111 // ;;; End:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines