show-state.cc Source File

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
eval/show-state.cc
Go to the documentation of this file.
1 /* show-state.cc
2 */
3 #include "osl/eval/ppair/piecePairPieceEval.h"
4 #include "osl/eval/ppair/piecePairRawEval.h"
5 #include "osl/eval/endgame/attackDefense.h"
6 #include "osl/eval/endgame/attackKing.h"
7 #include "osl/eval/endgame/defenseKing.h"
8 #include "osl/eval/endgame/kingPieceValues.h"
9 #include "osl/eval/progressEval.h"
10 #include "osl/container/pieceValues.h"
11 #include "osl/record/csaRecord.h"
12 #include "osl/state/numEffectState.h"
13 #include "osl/oslConfig.h"
14 #include <stdexcept>
15 #include <iostream>
16 #include <iomanip>
17 #include <cstdlib>
18 #include <cstdio>
19 #include <unistd.h>
20
21 using namespace osl;
22 using namespace osl::eval;
23 using namespace osl::eval::endgame;
24
25 void usage(const char *prog)
26 {
27 using namespace std;
28 cerr << "Usage: " << prog << " [-a] [-t raw|piece|attack|defense|endgame|progress] [-f pair-file-name] csa-filename"
29 << endl;
30 exit(1);
31 }
32
33 void show(const char *filename, const std::string&);
34
35 bool show_all_states = false;
36 int main(int argc, char **argv)
37 {
38 const char *program_name = argv[0];
39 bool error_flag = false;
40
41 std::string table_filename
42 = OslConfig::home() + "/data/sibling-attack.pair";
43 std::string eval_type = "piece";
44
45 extern char *optarg;
46 extern int optind;
47 char c;
48 while ((c = getopt(argc, argv, "at:f:vh")) != EOF)
49 {
50 switch(c)
51 {
52 case 'a': show_all_states = true;
53 break;
54 case 'f': table_filename = optarg;
55 break;
56 case 't': eval_type = optarg;
57 break;
58 default: error_flag = true;
59 }
60 }
61 argc -= optind;
62 argv += optind;
63
64 if (error_flag)
65 usage(program_name);
66
67 PiecePairPieceTable::Table.setUp(table_filename.c_str());
68
69 for (int i=0; i<argc; ++i)
70 {
71 show(argv[i], eval_type);
72 }
73 }
74
75 void show(const SimpleState& state, const std::string& eval_type)
76 {
77 std::cout << state;
78 const progress::Effect5x3 progress((NumEffectState(state)));
79 std::cout << "black " << progress.progress16(BLACK).value()
80 << " white " << progress.progress16(WHITE).value()
81 << " average " << progress.progress16().value()
82 << "\n";
83 PieceValues values;
84 if (eval_type == "progress")
85 ProgressEval::setValues(state, values);
86 else if (eval_type == "endgame")
87 AttackDefense::setValues(state, values);
88 else if (eval_type == "attack")
89 KingPieceValues<AttackKing>::setValues(state, values);
90 else if (eval_type == "defense")
91 KingPieceValues<DefenseKing>::setValues(state, values);
92 else if (eval_type == "piece")
93 PiecePairPieceEval::setValues(state, values);
94 else if (eval_type == "raw")
95 PiecePairRawEval::setValues(state, values);
96 else
97 throw std::runtime_error("unknown function type "+eval_type);
98 values.showValues(std::cout, state);
99 }
100
101 void show(const char *filename, const std::string& eval_type)
102 {
103 CsaFile file(filename);
104 const vector<osl::Move> moves = file.getRecord().getMoves();
105 NumEffectState state(file.getInitialState());
106 for (unsigned int i=0; i<moves.size(); i++)
107 {
108 if (show_all_states)
109 show(state, eval_type);
110 const Move m = moves[i];
111 state.makeMove(m);
112 }
113 show(state, eval_type);
114 }
115
116 /* ------------------------------------------------------------------------- */
117 // ;;; Local Variables:
118 // ;;; mode:c++
119 // ;;; c-basic-offset:2
120 // ;;; End: