My Project
kanjiPrint.h
Go to the documentation of this file.
1/* kanjiPrint.h
2 */
3#ifndef RECORD_KANJIPRINT_H
4#define RECORD_KANJIPRINT_H
5
6#include "osl/simpleState.h"
7#include <memory>
8#include <iosfwd>
9#include <string>
10
11namespace osl
12{
13 class Move;
14
15 namespace record
16 {
17 class Color;
18 std::ostream& operator<<(std::ostream& os, const Color& c);
22 class Color
23 {
24 public:
25 Color() : name(""), valid(false) {}
26 Color(const std::string& value, const std::string& name, const bool valid=true);
27 ~Color();
28 private:
29 std::string value;
30 std::string name;
31 bool valid;
32 public:
33 bool isValid() const {return valid;}
34 const std::string& getName() const {return name;}
35 bool operator==(const Color& rhs) const
36 {
37 return (this->valid == rhs.valid) &&
38 (this->value == rhs.value);
39 }
40 bool operator!=(const Color& rhs) const
41 {
42 return !(*this == rhs);
43
44 }
45
49 static const Color colorFor(const std::string& str);
50
52 static const Color NONE;
53 static const Color Black;
54 static const Color Red;
55 static const Color Green;
56 static const Color Brown;
57 static const Color Blue;
58 static const Color Purple;
59 static const Color Cyan;
60 static const Color LightGray;
61 static const Color DarkGray;
62 static const Color LightRed;
63 static const Color LightGreen;
64 static const Color Yellow;
65 static const Color LightBlue;
66 static const Color LightPurple;
67 static const Color LightCyan;
68 static const Color White;
69
70 friend std::ostream& operator<<(std::ostream& os, const Color& c);
71 };
72
73
78 {
79 private:
80 std::ostream& os;
81 const Color color;
82
83 void escColSet() const;
84 void escColReSet() const;
85 public:
86 ChangeShellColor(std::ostream& os, const Color& color)
87 : os(os), color(color) {escColSet();}
89 };
90
92 std::string kanjiNumber(const int n);
93
98 {
99 public:
101
102 virtual ~Characters();
103
105 virtual const std::string& getDan(const size_t index) const = 0;
107 virtual const std::string& getSuji(const size_t index) const = 0;
109 virtual const std::string& getPiece(const size_t index) const = 0;
110
112 const std::string& getStand(const size_t index) const
114 return stand[index];
116
117 const std::string& stand_kanji(const PtypeO& ptypeo) const
118 {
119 return getStand(piece_index(ptypeo));
120 }
121
122 const std::string& kanji(const PtypeO& ptypeo) const
123 {
124 return getPiece(piece_index(ptypeo));
125 }
126 const std::string& kanji(Ptype ptype) const
127 {
128 return getPiece(newPtypeO(BLACK, ptype));
129 }
130 private:
131 size_t piece_index(const PtypeO& ptypeo) const
132 {
133#ifndef NDEBUG
134 static const size_t NPieces = PTYPEO_MAX - PTYPEO_MIN+2;
135#endif
136 const size_t index = ptypeo - PTYPEO_MIN;
137 assert(index < NPieces);
138 return index;
139 }
140 };
144 {
146 static const CArray<std::string,10> dan;
148 static const CArray<std::string,10> suji;
150 static const CArray<std::string,32> pieces;
151
152 const std::string& getDan(const size_t index) const {return dan[index];}
153 const std::string& getSuji(const size_t index) const {return suji[index];}
154 const std::string& getPiece(const size_t index) const {return pieces[index];}
155 };
156
159 {
162 static const CArray<std::string,32> pieces;
163
164 const std::string& getDan(const size_t index) const {return dan[index];}
165 const std::string& getSuji(const size_t index) const {return suji[index];}
166 const std::string& getPiece(const size_t index) const {return pieces[index];}
167 };
168
170 struct KIFCharacters : public Characters
171 {
173 static const CArray<std::string,10> suji;
174 static const CArray<std::string,32> pieces;
175
176 const std::string& getDan(const size_t index) const {return dan[index];}
177 const std::string& getSuji(const size_t index) const {return suji[index];}
178 const std::string& getPiece(const size_t index) const {return pieces[index];}
179 };
180
185 {
186 private:
187 std::ostream& os;
188 const std::shared_ptr<Characters> pieces;
192
193 public:
194 explicit KanjiPrint(std::ostream& os,
195 const std::shared_ptr<Characters> pieces=std::shared_ptr<Characters>(new StandardCharacters()))
196 : os(os), pieces(pieces),
197 black_color(Color::NONE),
198 white_color(Color::NONE),
199 last_move_color(Color::NONE) {}
201
207 void print(const SimpleState& state,
208 const Move *last_move=NULL) const;
209
210 void setBlackColor(const Color& c) {black_color = c;}
211 void setWhiteColor(const Color& c) {white_color = c;}
213 };
214 } // namespace record
215} // namespace osl
216
217#endif /* RECORD_KANJIPRINT_H */
218// ;;; Local Variables:
219// ;;; mode:c++
220// ;;; c-basic-offset:2
221// ;;; End:
圧縮していない moveの表現 .
shellの文字出力にて、色を変える。
Definition kanjiPrint.h:78
ChangeShellColor(std::ostream &os, const Color &color)
Definition kanjiPrint.h:86
駒の文字を管理するAbstract class。
Definition kanjiPrint.h:98
virtual const std::string & getDan(const size_t index) const =0
段数の文字を返す
static const CArray< std::string, 32 > stand
Definition kanjiPrint.h:100
const std::string & kanji(const PtypeO &ptypeo) const
Definition kanjiPrint.h:122
virtual const std::string & getPiece(const size_t index) const =0
盤面上の駒を返す
const std::string & getStand(const size_t index) const
持ち駒の漢字文字を返す。1文字を期待する
Definition kanjiPrint.h:112
const std::string & kanji(Ptype ptype) const
Definition kanjiPrint.h:126
size_t piece_index(const PtypeO &ptypeo) const
Definition kanjiPrint.h:131
const std::string & stand_kanji(const PtypeO &ptypeo) const
Definition kanjiPrint.h:117
virtual const std::string & getSuji(const size_t index) const =0
筋の文字を返す。駒の文字幅に合わせる必要がある。
カラーコードを保持するクラス。
Definition kanjiPrint.h:23
std::string value
Definition kanjiPrint.h:29
static const Color Red
Definition kanjiPrint.h:54
std::string name
Definition kanjiPrint.h:30
static const Color Cyan
Definition kanjiPrint.h:59
static const Color Yellow
Definition kanjiPrint.h:64
static const Color Brown
Definition kanjiPrint.h:56
bool operator!=(const Color &rhs) const
Definition kanjiPrint.h:40
static const Color Purple
Definition kanjiPrint.h:58
static const Color White
Definition kanjiPrint.h:68
static const Color colorFor(const std::string &str)
文字列に対応するColor objectを返す
Definition kanjiPrint.cc:40
static const Color LightGreen
Definition kanjiPrint.h:63
static const Color LightCyan
Definition kanjiPrint.h:67
static const Color Black
Definition kanjiPrint.h:53
bool operator==(const Color &rhs) const
Definition kanjiPrint.h:35
static const Color LightGray
Definition kanjiPrint.h:60
static const Color Blue
Definition kanjiPrint.h:57
static const Color LightBlue
Definition kanjiPrint.h:65
static const Color DarkGray
Definition kanjiPrint.h:61
static const Color Green
Definition kanjiPrint.h:55
friend std::ostream & operator<<(std::ostream &os, const Color &c)
bool isValid() const
Definition kanjiPrint.h:33
static const Color LightRed
Definition kanjiPrint.h:62
static const Color NONE
色指定しない(デフォルトのまま)ことを示す特別なオブジェクト
Definition kanjiPrint.h:52
const std::string & getName() const
Definition kanjiPrint.h:34
static const Color LightPurple
Definition kanjiPrint.h:66
局面を漢字でカラーで表示する.
Definition kanjiPrint.h:185
KanjiPrint(std::ostream &os, const std::shared_ptr< Characters > pieces=std::shared_ptr< Characters >(new StandardCharacters()))
Definition kanjiPrint.h:194
void setLastMoveColor(const Color &c)
Definition kanjiPrint.h:212
void setWhiteColor(const Color &c)
Definition kanjiPrint.h:211
void print(const SimpleState &state, const Move *last_move=NULL) const
出力
const std::shared_ptr< Characters > pieces
Definition kanjiPrint.h:188
void setBlackColor(const Color &c)
Definition kanjiPrint.h:210
std::string kanjiNumber(const int n)
漢数字を返す(持ち駒の数などで用いる)
Definition kanjiPrint.cc:69
std::ostream & operator<<(std::ostream &os, const Color &c)
Ptype
駒の種類を4ビットでコード化する
Definition basic_type.h:84
@ BLACK
Definition basic_type.h:9
PtypeO
Player + Ptype [-15, 15] PtypeO の O は Owner の O.
Definition basic_type.h:199
@ PTYPEO_MAX
Definition basic_type.h:201
@ PTYPEO_MIN
Definition basic_type.h:200
PtypeO newPtypeO(Player player, Ptype ptype)
Definition basic_type.h:211
柿木形式(KIF)。頭にv
Definition kanjiPrint.h:171
static const CArray< std::string, 10 > dan
Definition kanjiPrint.h:172
static const CArray< std::string, 32 > pieces
Definition kanjiPrint.h:143
const std::string & getSuji(const size_t index) const
筋の文字を返す。駒の文字幅に合わせる必要がある。
Definition kanjiPrint.h:177
static const CArray< std::string, 10 > suji
Definition kanjiPrint.h:141
const std::string & getPiece(const size_t index) const
盤面上の駒を返す
Definition kanjiPrint.h:178
const std::string & getDan(const size_t index) const
段数の文字を返す
Definition kanjiPrint.h:176
ロシア文字(激指フォント用)
Definition kanjiPrint.h:159
const std::string & getDan(const size_t index) const
段数の文字を返す
Definition kanjiPrint.h:164
static const CArray< std::string, 10 > suji
Definition kanjiPrint.h:161
const std::string & getSuji(const size_t index) const
筋の文字を返す。駒の文字幅に合わせる必要がある。
Definition kanjiPrint.h:165
static const CArray< std::string, 10 > dan
Definition kanjiPrint.h:160
const std::string & getPiece(const size_t index) const
盤面上の駒を返す
Definition kanjiPrint.h:166
static const CArray< std::string, 32 > pieces
Definition kanjiPrint.h:128
持ち駒用(標準文字)
Definition kanjiPrint.h:144
const std::string & getSuji(const size_t index) const
筋の文字を返す。駒の文字幅に合わせる必要がある。
Definition kanjiPrint.h:153
const std::string & getDan(const size_t index) const
段数の文字を返す
Definition kanjiPrint.h:152
static const CArray< std::string, 32 > pieces
盤面上の駒の漢字文字
Definition kanjiPrint.h:115
const std::string & getPiece(const size_t index) const
盤面上の駒を返す
Definition kanjiPrint.h:154
static const CArray< std::string, 10 > dan
段数の文字
Definition kanjiPrint.h:111
static const CArray< std::string, 10 > suji
筋の文字。駒の文字幅に合わせる必要がある。
Definition kanjiPrint.h:113