00001
00002
00003
00004
00005 #include "osl/record/csaRecord.h"
00006 #include "osl/record/kisen.h"
00007 #include "osl/state/numEffectState.h"
00008 #include "osl/effect_util/effectUtil.h"
00009 #include "osl/apply_move/applyMove.h"
00010
00011 #include <iostream>
00012 #include <cstdlib>
00013 #include <unistd.h>
00014
00015 using namespace osl;
00016
00017 void usage(const char *prog)
00018 {
00019 using namespace std;
00020 cerr << "Usage: " << prog << " [-N atmost-N-games] [-k kisenFileName] csa-filenames "
00021 << endl;
00022
00023 exit(1);
00024 }
00025
00026 void processKifu (osl::vector<Move> const& moves)
00027 {
00028 NumEffectState state((SimpleState(HIRATE)));
00029 std::cout << state << std::endl;
00030 for (size_t i=0; i<moves.size (); ++i)
00031 {
00032 if (EffectUtil::isKingInCheck(alt(state.getTurn()), state))
00033 {
00034
00035 std::cerr << "e";
00036 break;
00037 }
00038 ApplyMoveOfTurn::doMove(state, moves[i]);
00039 std::cout << state << std::endl;
00040 }
00041 std::cout << state << std::endl;
00042 }
00043
00044 int main(int argc, char **argv)
00045 {
00046 const char *program_name = argv[0];
00047 bool error_flag = false;
00048 bool verbose = false;
00049 const char *kisenFilename = 0;
00050
00051 extern char *optarg;
00052 extern int optind;
00053 char c;
00054 size_t num_records = 1;
00055 while ((c = getopt(argc, argv, "N:k:vh")) != EOF)
00056 {
00057 switch(c)
00058 {
00059 case 'k': kisenFilename = optarg;
00060 break;
00061 case 'N': num_records = atoi(optarg);
00062 break;
00063 case 'v': verbose = true;
00064 break;
00065 default: error_flag = true;
00066 }
00067 }
00068 argc -= optind;
00069 argv += optind;
00070
00071 if (error_flag)
00072 usage(program_name);
00073
00074 try
00075 {
00076 nice(20);
00077 size_t record_processed = 0;
00078
00079
00080 if (kisenFilename)
00081 {
00082 KisenFile kisenFile(kisenFilename);
00083
00084 for (size_t i=0; i<kisenFile.size(); i++)
00085 {
00086 if (++record_processed > num_records)
00087 break;
00088 const vector<Move> moves=kisenFile.getMoves(i);
00089 processKifu (moves);
00090 }
00091 }
00092
00093
00094 for (int i=0; i<argc; ++i)
00095 {
00096 if (++record_processed > num_records)
00097 break;
00098 CsaFile file(argv [i]);
00099 const vector<Move> moves=file.getRecord().getMoves();
00100
00101 processKifu (moves);
00102 }
00103 }
00104
00105 catch (std::exception& e)
00106 {
00107 std::cerr << e.what() << "\n";
00108 return 1;
00109 }
00110 }
00111
00112
00113
00114
00115