00001 #include "osl/apply_move/applyMove.h"
00002 #include "osl/state/numEffectState.h"
00003 #include "osl/record/kisen.h"
00004 #include "osl/record/csaIOError.h"
00005
00006 #include <boost/scoped_ptr.hpp>
00007 #include <iostream>
00008
00009 void usage (const char *program_name)
00010 {
00011 std::cerr << "Usage: " << program_name << " KISEN-FILE [out]"
00012 << std::endl;
00013 exit(1);
00014 }
00015
00016 void check_all(const char*filename, const char *output)
00017 {
00018 osl::record::KisenFile kisen(filename);
00019 boost::scoped_ptr<std::ofstream> os;
00020 boost::scoped_ptr<osl::record::OKisenStream> out;
00021 if (output) {
00022 os.reset(new std::ofstream(output));
00023 out.reset(new osl::record::OKisenStream(*os));
00024 }
00025
00026 for (size_t i = 0; i < kisen.size(); i++)
00027 {
00028 std::cout << i;
00029 if ((i % 16) == 15 || i + 1 == kisen.size())
00030 std::cout << std::endl;
00031 else
00032 std::cout << ' ';
00033 osl::state::NumEffectState state(kisen.getInitialState());
00034 osl::vector<osl::Move> moves;
00035 size_t j = 0;
00036 try {
00037 moves = kisen.getMoves(i);
00038 for (; j < moves.size(); j++)
00039 {
00040 const osl::Position opKingPosition
00041 = state.getKingPosition(alt(state.getTurn()));
00042 if (state.hasEffectBy(state.getTurn(), opKingPosition))
00043 {
00044 if (j)
00045 --j;
00046 break;
00047 }
00048 osl::apply_move::ApplyMoveOfTurn::doMove(state, moves[j]);
00049 }
00050 moves.resize(j);
00051 }
00052 catch (osl::record::csa::CsaIOError& e) {
00053 std::cerr << e.what();
00054 }
00055
00056 if (out)
00057 out->save(kisen.getInitialState(), moves);
00058 }
00059 }
00060
00061 int main(int argc, char **argv)
00062 {
00063 if (! (argc == 2 || argc == 3))
00064 usage(argv[0]);
00065
00066 check_all(argv[1], (argc == 3) ? argv[2] : "");
00067
00068 return 0;
00069 }
00070
00071
00072
00073