pairstat.cc
Go to the documentation of this file.
00001 /* pairstat.cc
00002  */
00003 
00004 #include "osl/eval/ppair/piecePairRawEval.h"
00005 #include "osl/record/csaString.h"
00006 #include "osl/state/simpleState.h"
00007 #include <iostream>
00008 #include <iomanip>
00009 #include <cstdlib>
00010 #include <cstdio>
00011 #include <unistd.h>
00012 
00013 using namespace osl;
00014 using namespace osl::eval;
00015 
00016 void usage(const char *prog)
00017 {
00018   using namespace std;
00019   cerr << "Usage: " << prog << " [-f pair-file-name] [-P player(0 for black, 1 for white)] [-p position(e.g. 11)] [-t ptype(e.g. 7 for PROOK)]"
00020        << endl
00021        << "if any of -Ppt options are specified, relation of [<specified-pieace*specified-pos>,<other-pieace*other-pos>] will be shown \n"
00022        << "otherwise, relation of [<same-pieace*same-pos>,<same-pieace*same-pos>] will be shown \n"
00023        << endl;
00024   exit(1);
00025 }
00026 
00027 void showPieceStat(Player, Ptype);
00028 void showPairStat(Player, Square, Ptype);
00029 
00030 int main(int argc, char **argv)
00031 {
00032   const char *program_name = argv[0];
00033   bool error_flag = false;
00034   const char *pairFileName = 0;
00035   int ptype = PROOK;
00036   Square pos(1,1);
00037   Player player = BLACK;
00038   int singleStateMode = true;
00039   
00040   extern char *optarg;
00041   extern int optind;
00042   char c;
00043   while ((c = getopt(argc, argv, "f:p:P:t:vh")) != EOF)
00044   {
00045     switch(c)
00046     {
00047     case 'f':   pairFileName = optarg;
00048       break;
00049     case 'p':   pos = Square(atoi(optarg)/10, atoi(optarg)%10);
00050       singleStateMode = false;
00051       break;
00052     case 'P':   player = (atoi(optarg) ? WHITE : BLACK);
00053       singleStateMode = false;
00054       break;
00055     case 't':   ptype = atoi(optarg);
00056       singleStateMode = false;
00057       break;
00058     default:    error_flag = true;
00059     }
00060   }
00061   argc -= optind;
00062   argv += optind;
00063 
00064   if (error_flag || (! pairFileName))
00065     usage(program_name);
00066 
00067   PiecePairRawEval::setUp(pairFileName);
00068 
00069   if (singleStateMode)
00070   {
00071     for (int i=PPAWN; i<=PTYPE_MAX; ++i)
00072     {
00073       showPieceStat(BLACK,static_cast<Ptype>(i));
00074       showPieceStat(WHITE,static_cast<Ptype>(i));
00075     }
00076   }
00077   else
00078     showPairStat(player,pos,static_cast<Ptype>(ptype));
00079 }
00080 
00081 void showPieceStat(Player player, Ptype ptype)
00082 {
00083   const PtypeO ptypeo = newPtypeO(player, ptype);
00084   // single [piece,position]
00085   std::cout << player << ", " << ptype << "\n";
00086   for (int y=1; y<=9; ++y)
00087   {
00088     for (int x=9; x>=1; --x)
00089     {
00090       const Square pos1(x,y);
00091       const unsigned int index1 = PiecePairIndex::indexOf(pos1,ptypeo);
00092       std::cout << std::setw(4) << PiecePairRawTable::Table.valueOf(index1,index1);
00093     }
00094     std::cout << "\n";
00095   }
00096   const Square pos1 = Square::STAND();
00097   const unsigned int index1 = PiecePairIndex::indexOf(pos1,ptypeo);
00098   std::cout << pos1 << " " << std::setw(4) << PiecePairRawTable::Table.valueOf(index1,index1);
00099   std::cout << "\n";
00100 }
00101 
00102 void showPairStatAgainst(Player player2, Ptype ptype2, unsigned int index1)
00103 {
00104   const PtypeO ptypeo2 = newPtypeO(player2, ptype2);
00105   for (int y=1; y<=9; ++y)
00106   {
00107     for (int x=9; x>=1; --x)
00108     {
00109       const Square pos2(x,y);
00110       const unsigned int index2 = PiecePairIndex::indexOf(pos2,ptypeo2);
00111       std::cout << std::setw(4) << PiecePairRawTable::Table.valueOf(index1,index2);
00112     }
00113     std::cout << "\n";
00114   }
00115   const Square pos2 = Square::STAND();
00116   const unsigned int index2 = PiecePairIndex::indexOf(pos2,ptypeo2);
00117   std::cout << pos2 << " " << std::setw(4) << PiecePairRawTable::Table.valueOf(index1,index2);
00118   std::cout << "\n";
00119 }
00120 
00121 void showPairStat(Player player, Square pos1, Ptype ptype1)
00122 {
00123   const PtypeO ptypeo1 = newPtypeO(player, ptype1);
00124   std::cout << player << ", " << pos1 << ", " << ptype1 << "\n";
00125   const unsigned int index1 = PiecePairIndex::indexOf(pos1,ptypeo1);
00126   for (int p2=PPAWN; p2<=PTYPE_MAX; ++p2)
00127   {
00128     Ptype ptype2 = static_cast<Ptype>(p2);
00129     std::cout << player << ptype2 << " (<=> " << player << ptype1 << ", " << pos1 << ")\n";
00130     showPairStatAgainst(player, ptype2, index1);
00131     std::cout << alt(player) << ptype2 << " (<=> " << player << ptype1 << ", " << pos1 << ")\n";
00132     showPairStatAgainst(alt(player), ptype2, index1);
00133   }
00134 }
00135 
00136 
00137 /* ------------------------------------------------------------------------- */
00138 // ;;; Local Variables:
00139 // ;;; mode:c++
00140 // ;;; c-basic-offset:2
00141 // ;;; End:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines