00001
00005 #include "osl/apply_move/applyMove.h"
00006 #include "osl/record/ki2.h"
00007 #include "osl/record/checkDuplicate.h"
00008 #include "osl/record/ki2IOError.h"
00009
00010 #include <boost/algorithm/string/trim.hpp>
00011 #include <boost/foreach.hpp>
00012 #include <boost/program_options.hpp>
00013 #include <boost/lambda/lambda.hpp>
00014 #include <boost/lambda/bind.hpp>
00015 #include <iostream>
00016 #include <fstream>
00017 #include <string>
00018 #include <vector>
00019 #include <algorithm>
00020
00021
00022
00023
00024 boost::program_options::variables_map vm;
00025 osl::record::CheckDuplicate check_duplicate;
00026
00027 using namespace boost::lambda;
00028
00029 void process( const std::string& file_name)
00030 {
00031 try {
00032 bool verbose = false;
00033 if (vm.count("verbose"))
00034 verbose = true;
00035 const osl::Ki2File ki2(file_name, verbose);
00036 const osl::Record& record = ki2.getRecord();
00037 const osl::stl::vector<osl::Move>& moves = record.getMoves();
00038
00039 if (check_duplicate.regist(moves)) {
00040 std::cerr << "Found a duplicated play: " << file_name << "\n";
00041 return;
00042 }
00043
00044 osl::SimpleState state((osl::HIRATE));
00045 BOOST_FOREACH(const osl::Move& move, moves)
00046 {
00047 if (!state.isValidMove(move, false))
00048 {
00049 std::cout << file_name << "\n";
00050 continue;
00051 }
00052 osl::ApplyMoveOfTurn::doMove(state, move);
00053 }
00054 } catch (osl::Ki2IOError& err) {
00055 std::cerr << err.what() << "\n";
00056 std::cerr << "Found an error: " << file_name << "\n";
00057 return;
00058 }
00059 }
00060
00061 int main(int argc, char **argv)
00062 {
00063 boost::program_options::options_description command_line_options;
00064 command_line_options.add_options()
00065 ("input-file", boost::program_options::value< std::vector<std::string> >(),
00066 "input files in ki2 format (.ki2)")
00067 ("verbose,v", "Verbose mode")
00068 ("help,h", "Show this help message");
00069 boost::program_options::positional_options_description p;
00070 p.add("input-file", -1);
00071
00072 try
00073 {
00074 boost::program_options::store(
00075 boost::program_options::command_line_parser(
00076 argc, argv).options(command_line_options).positional(p).run(), vm);
00077 boost::program_options::notify(vm);
00078 if (vm.count("help"))
00079 {
00080 std::cout << "Usage: " << argv[0] << " [options] ki2-file [ki2-file...]\n";
00081 std::cout << " " << argv[0] << " [options]\n";
00082 std::cout << command_line_options << std::endl;
00083 return 0;
00084 }
00085 }
00086 catch (std::exception &e)
00087 {
00088 std::cerr << "error in parsing options" << std::endl
00089 << e.what() << std::endl;
00090 std::cerr << "Usage: " << argv[0] << " [options] ki2-file [ki2-file...]\n";
00091 std::cerr << " " << argv[0] << " [options]\n";
00092 std::cerr << command_line_options << std::endl;
00093 return 1;
00094 }
00095
00096 std::vector<std::string> files;
00097 if (vm.count("input-file"))
00098 {
00099 const std::vector<std::string> temp = vm["input-file"].as<std::vector<std::string> >();
00100 files.insert(files.end(), temp.begin(), temp.end());
00101 }
00102 else
00103 {
00104 std::string line;
00105 while(std::getline(std::cin , line))
00106 {
00107 boost::algorithm::trim(line);
00108 files.push_back(line);
00109 }
00110 }
00111
00112
00113 std::for_each(files.begin(), files.end(), bind(&process, _1));
00114
00115 check_duplicate.print(std::cout);
00116
00117 return 0;
00118 }
00119
00120
00121
00122