00001
00002
00003
00004 #include "osl/progress/effect5x3.h"
00005 #include "osl/record/csaRecord.h"
00006 #include "osl/state/numEffectState.h"
00007 #include "osl/apply_move/applyMove.h"
00008 #include <stdexcept>
00009 #include <iostream>
00010 #include <iomanip>
00011 #include <cstdlib>
00012 #include <unistd.h>
00013
00014 using namespace osl;
00015 using namespace osl::progress;
00016
00017 void usage(const char *prog)
00018 {
00019 using namespace std;
00020 cerr << "Usage: " << prog << " [-a] csa-filename"
00021 << endl;
00022 exit(1);
00023 }
00024
00025 void show(const char *filename);
00026
00027 bool show_all_states = false;
00028 int main(int argc, char **argv)
00029 {
00030 const char *program_name = argv[0];
00031 bool error_flag = false;
00032
00033
00034 extern int optind;
00035 char c;
00036 while ((c = getopt(argc, argv, "at:f:vh")) != EOF)
00037 {
00038 switch(c)
00039 {
00040 case 'a': show_all_states = true;
00041 break;
00042 default: error_flag = true;
00043 }
00044 }
00045 argc -= optind;
00046 argv += optind;
00047
00048 if (error_flag)
00049 usage(program_name);
00050
00051 for (int i=0; i<argc; ++i)
00052 {
00053 show(argv[i]);
00054 }
00055 }
00056
00057 void show(const NumEffectState& state)
00058 {
00059 std::cout << state;
00060 const int progress_black = Effect5x3::makeProgress(BLACK,state);
00061 const int progress_white = Effect5x3::makeProgress(WHITE,state);
00062 std::cout << "black " << progress_black << "\n";
00063 std::cout << "white " << progress_white << "\n";
00064 std::cout << "total " << progress_black + progress_white << "\n";
00065 }
00066
00067 void show(const char *filename)
00068 {
00069 CsaFile file(filename);
00070 const vector<osl::Move> moves = file.getRecord().getMoves();
00071 NumEffectState state(file.getInitialState());
00072 for (unsigned int i=0; i<moves.size(); i++)
00073 {
00074 if (show_all_states)
00075 show(state);
00076 const Move m = moves[i];
00077 ApplyMoveOfTurn::doMove(state, m);
00078 }
00079 show(state);
00080 }
00081
00082
00083
00084
00085
00086