All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
pairstat.cc
Go to the documentation of this file.
1 /* pairstat.cc
2  */
3 
5 #include "osl/record/csaString.h"
7 #include <iostream>
8 #include <iomanip>
9 #include <cstdlib>
10 #include <cstdio>
11 #include <unistd.h>
12 
13 using namespace osl;
14 using namespace osl::eval;
15 
16 void usage(const char *prog)
17 {
18  using namespace std;
19  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)]"
20  << endl
21  << "if any of -Ppt options are specified, relation of [<specified-pieace*specified-pos>,<other-pieace*other-pos>] will be shown \n"
22  << "otherwise, relation of [<same-pieace*same-pos>,<same-pieace*same-pos>] will be shown \n"
23  << endl;
24  exit(1);
25 }
26 
29 
30 int main(int argc, char **argv)
31 {
32  const char *program_name = argv[0];
33  bool error_flag = false;
34  const char *pairFileName = 0;
35  int ptype = PROOK;
36  Square pos(1,1);
37  Player player = BLACK;
38  int singleStateMode = true;
39 
40  extern char *optarg;
41  extern int optind;
42  char c;
43  while ((c = getopt(argc, argv, "f:p:P:t:vh")) != EOF)
44  {
45  switch(c)
46  {
47  case 'f': pairFileName = optarg;
48  break;
49  case 'p': pos = Square(atoi(optarg)/10, atoi(optarg)%10);
50  singleStateMode = false;
51  break;
52  case 'P': player = (atoi(optarg) ? WHITE : BLACK);
53  singleStateMode = false;
54  break;
55  case 't': ptype = atoi(optarg);
56  singleStateMode = false;
57  break;
58  default: error_flag = true;
59  }
60  }
61  argc -= optind;
62  argv += optind;
63 
64  if (error_flag || (! pairFileName))
65  usage(program_name);
66 
67  PiecePairRawEval::setUp(pairFileName);
68 
69  if (singleStateMode)
70  {
71  for (int i=PPAWN; i<=PTYPE_MAX; ++i)
72  {
73  showPieceStat(BLACK,static_cast<Ptype>(i));
74  showPieceStat(WHITE,static_cast<Ptype>(i));
75  }
76  }
77  else
78  showPairStat(player,pos,static_cast<Ptype>(ptype));
79 }
80 
81 void showPieceStat(Player player, Ptype ptype)
82 {
83  const PtypeO ptypeo = newPtypeO(player, ptype);
84  // single [piece,position]
85  std::cout << player << ", " << ptype << "\n";
86  for (int y=1; y<=9; ++y)
87  {
88  for (int x=9; x>=1; --x)
89  {
90  const Square pos1(x,y);
91  const unsigned int index1 = PiecePairIndex::indexOf(pos1,ptypeo);
92  std::cout << std::setw(4) << PiecePairRawTable::Table.valueOf(index1,index1);
93  }
94  std::cout << "\n";
95  }
96  const Square pos1 = Square::STAND();
97  const unsigned int index1 = PiecePairIndex::indexOf(pos1,ptypeo);
98  std::cout << pos1 << " " << std::setw(4) << PiecePairRawTable::Table.valueOf(index1,index1);
99  std::cout << "\n";
100 }
101 
102 void showPairStatAgainst(Player player2, Ptype ptype2, unsigned int index1)
103 {
104  const PtypeO ptypeo2 = newPtypeO(player2, ptype2);
105  for (int y=1; y<=9; ++y)
106  {
107  for (int x=9; x>=1; --x)
108  {
109  const Square pos2(x,y);
110  const unsigned int index2 = PiecePairIndex::indexOf(pos2,ptypeo2);
111  std::cout << std::setw(4) << PiecePairRawTable::Table.valueOf(index1,index2);
112  }
113  std::cout << "\n";
114  }
115  const Square pos2 = Square::STAND();
116  const unsigned int index2 = PiecePairIndex::indexOf(pos2,ptypeo2);
117  std::cout << pos2 << " " << std::setw(4) << PiecePairRawTable::Table.valueOf(index1,index2);
118  std::cout << "\n";
119 }
120 
121 void showPairStat(Player player, Square pos1, Ptype ptype1)
122 {
123  const PtypeO ptypeo1 = newPtypeO(player, ptype1);
124  std::cout << player << ", " << pos1 << ", " << ptype1 << "\n";
125  const unsigned int index1 = PiecePairIndex::indexOf(pos1,ptypeo1);
126  for (int p2=PPAWN; p2<=PTYPE_MAX; ++p2)
127  {
128  Ptype ptype2 = static_cast<Ptype>(p2);
129  std::cout << player << ptype2 << " (<=> " << player << ptype1 << ", " << pos1 << ")\n";
130  showPairStatAgainst(player, ptype2, index1);
131  std::cout << alt(player) << ptype2 << " (<=> " << player << ptype1 << ", " << pos1 << ")\n";
132  showPairStatAgainst(alt(player), ptype2, index1);
133  }
134 }
135 
136 
137 /* ------------------------------------------------------------------------- */
138 // ;;; Local Variables:
139 // ;;; mode:c++
140 // ;;; c-basic-offset:2
141 // ;;; End: