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