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