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 
11 namespace 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();}
88  ~ChangeShellColor() {escColReSet();}
89  };
90 
92  std::string kanjiNumber(const int n);
93 
97  class Characters
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
113  {
114  return stand[index];
115  }
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  };
141 
144  {
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  {
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  {
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;}
212  void setLastMoveColor(const Color& c) {last_move_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:
static const Color colorFor(const std::string &str)
文字列に対応するColor objectを返す
Definition: kanjiPrint.cc:40
std::string kanjiNumber(const int n)
漢数字を返す(持ち駒の数などで用いる)
Definition: kanjiPrint.cc:69
bool isValid() const
Definition: kanjiPrint.h:33
static const CArray< std::string, 32 > pieces
Definition: kanjiPrint.h:162
static const CArray< std::string, 32 > pieces
Definition: kanjiPrint.h:174
static const Color LightGray
Definition: kanjiPrint.h:60
const std::string & getDan(const size_t index) const
段数の文字を返す
Definition: kanjiPrint.h:176
持ち駒用(標準文字)
Definition: kanjiPrint.h:143
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:164
const std::string & getStand(const size_t index) const
持ち駒の漢字文字を返す。1文字を期待する
Definition: kanjiPrint.h:112
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 Color Blue
Definition: kanjiPrint.h:57
bool operator!=(const Color &rhs) const
Definition: kanjiPrint.h:40
static const Color LightCyan
Definition: kanjiPrint.h:67
shellの文字出力にて、色を変える。
Definition: kanjiPrint.h:77
ChangeShellColor(std::ostream &os, const Color &color)
Definition: kanjiPrint.h:86
static const CArray< std::string, 10 > dan
Definition: kanjiPrint.h:160
const std::string & kanji(const PtypeO &ptypeo) const
Definition: kanjiPrint.h:122
static const Color Green
Definition: kanjiPrint.h:55
static const Color NONE
色指定しない(デフォルトのまま)ことを示す特別なオブジェクト
Definition: kanjiPrint.h:52
static const Color DarkGray
Definition: kanjiPrint.h:61
カラーコードを保持するクラス。
Definition: kanjiPrint.h:22
PtypeO newPtypeO(Player player, Ptype ptype)
Definition: basic_type.h:211
Ptype
駒の種類を4ビットでコード化する
Definition: basic_type.h:83
static const CArray< std::string, 10 > suji
筋の文字。駒の文字幅に合わせる必要がある。
Definition: kanjiPrint.h:148
std::string value
Definition: kanjiPrint.h:29
const std::string & getName() const
Definition: kanjiPrint.h:34
const std::string & getPiece(const size_t index) const
盤面上の駒を返す
Definition: kanjiPrint.h:154
const std::string & getPiece(const size_t index) const
盤面上の駒を返す
Definition: kanjiPrint.h:166
static const Color White
Definition: kanjiPrint.h:68
void setWhiteColor(const Color &c)
Definition: kanjiPrint.h:211
static const Color Cyan
Definition: kanjiPrint.h:59
圧縮していない moveの表現 .
Definition: basic_type.h:1051
static const CArray< std::string, 10 > suji
Definition: kanjiPrint.h:161
static const Color Purple
Definition: kanjiPrint.h:58
static const Color Red
Definition: kanjiPrint.h:54
static const Color LightPurple
Definition: kanjiPrint.h:66
bool operator==(const Color &rhs) const
Definition: kanjiPrint.h:35
const std::shared_ptr< Characters > pieces
Definition: kanjiPrint.h:188
KanjiPrint(std::ostream &os, const std::shared_ptr< Characters > pieces=std::shared_ptr< Characters >(new StandardCharacters()))
Definition: kanjiPrint.h:194
static const Color Yellow
Definition: kanjiPrint.h:64
const std::string & getSuji(const size_t index) const
筋の文字を返す。駒の文字幅に合わせる必要がある。
Definition: kanjiPrint.h:165
size_t piece_index(const PtypeO &ptypeo) const
Definition: kanjiPrint.h:131
static const Color Brown
Definition: kanjiPrint.h:56
friend std::ostream & operator<<(std::ostream &os, const Color &c)
static const CArray< std::string, 10 > dan
段数の文字
Definition: kanjiPrint.h:146
const std::string & kanji(Ptype ptype) const
Definition: kanjiPrint.h:126
ロシア文字(激指フォント用)
Definition: kanjiPrint.h:158
std::ostream & os
Definition: kanjiPrint.h:187
PtypeO
Player + Ptype [-15, 15] PtypeO の O は Owner の O.
Definition: basic_type.h:199
static const Color LightBlue
Definition: kanjiPrint.h:65
const std::string & getSuji(const size_t index) const
筋の文字を返す。駒の文字幅に合わせる必要がある。
Definition: kanjiPrint.h:177
static const Color LightGreen
Definition: kanjiPrint.h:63
std::ostream & operator<<(std::ostream &os, const Color &c)
Definition: kanjiPrint.cc:156
駒の文字を管理するAbstract class。
Definition: kanjiPrint.h:97
static const CArray< std::string, 10 > dan
Definition: kanjiPrint.h:172
static const CArray< std::string, 32 > pieces
盤面上の駒の漢字文字
Definition: kanjiPrint.h:150
static const Color Black
Definition: kanjiPrint.h:53
static const Color LightRed
Definition: kanjiPrint.h:62
void setBlackColor(const Color &c)
Definition: kanjiPrint.h:210
static const CArray< std::string, 32 > stand
Definition: kanjiPrint.h:100
局面を漢字でカラーで表示する.
Definition: kanjiPrint.h:184
void setLastMoveColor(const Color &c)
Definition: kanjiPrint.h:212
static const CArray< std::string, 10 > suji
Definition: kanjiPrint.h:173
柿木形式(KIF)。頭にv
Definition: kanjiPrint.h:170
std::string name
Definition: kanjiPrint.h:30
const std::string & stand_kanji(const PtypeO &ptypeo) const
Definition: kanjiPrint.h:117