All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
kanjiPrint.cc
Go to the documentation of this file.
2 #include "osl/record/kanjiCode.h"
3 #include "osl/ptype.h"
4 #include "osl/pieceStand.h"
5 #include "osl/move.h"
6 #include "osl/misc/carray.h"
7 #include "osl/misc/eucToLang.h"
8 #include <boost/foreach.hpp>
9 #include <iostream>
10 #include <string>
11 #include <algorithm>
12 #include <cctype>
13 
14 bool caseInsentiveCharCompare(char a, char b)
15 {
16  return toupper(a) == toupper(b);
17 }
18 
19 bool caseInsentiveCompare(const std::string& s1, const std::string& s2)
20 {
21  return s1.size() == s2.size() &&
22  equal(s1.begin(), s1.end(), s2.begin(), caseInsentiveCharCompare);
23 }
24 
25 const osl::record::Color osl::record::Color::NONE ("", "NONE", false);
26 const osl::record::Color osl::record::Color::Black ("0;30", "BLACK");
27 const osl::record::Color osl::record::Color::Red ("0;31", "RED");
28 const osl::record::Color osl::record::Color::Green ("0;32", "GREEN");
29 const osl::record::Color osl::record::Color::Brown ("0;33", "BROWN");
30 const osl::record::Color osl::record::Color::Blue ("0;34", "BLUE");
31 const osl::record::Color osl::record::Color::Purple ("0;35", "PURPLE");
32 const osl::record::Color osl::record::Color::Cyan ("0;36", "CYAN");
33 const osl::record::Color osl::record::Color::LightGray ("0;37", "LIGHTGRAY");
34 const osl::record::Color osl::record::Color::DarkGray ("1;30", "DARKGRAY");
35 const osl::record::Color osl::record::Color::LightRed ("1;31", "LIGHTRED");
36 const osl::record::Color osl::record::Color::LightGreen ("1;32", "LIGHTGREEN");
37 const osl::record::Color osl::record::Color::Yellow ("1;33", "YELLOW");
38 const osl::record::Color osl::record::Color::LightBlue ("1;34", "LIGHTBLUE");
39 const osl::record::Color osl::record::Color::LightPurple ("1;35", "LIGHTPURPLE");
40 const osl::record::Color osl::record::Color::LightCyan ("1;36", "LIGHTCYAN");
41 const osl::record::Color osl::record::Color::White ("1;37", "WHITE");
42 
44 Color::colorFor(const std::string& str)
45 {
46  static const CArray<const osl::record::Color,17> colors = {{
56 
57  BOOST_FOREACH(const record::Color& c, colors)
58  {
59  if (caseInsentiveCompare(str, c.getName()))
60  return c;
61  }
63 }
64 
65 osl::record::Color::Color(const std::string& value, const std::string& name, const bool valid)
66  : value(value), name(name), valid(valid)
67 {
68 }
70 {
71 }
72 
73 std::string osl::record::
74 kanjiNumber(const int n)
75 {
76  assert((1 <= n) && (n <= 18));
77  switch(n) {
78  case 1: return K_K1;
79  case 2: return K_K2;
80  case 3: return K_K3;
81  case 4: return K_K4;
82  case 5: return K_K5;
83  case 6: return K_K6;
84  case 7: return K_K7;
85  case 8: return K_K8;
86  case 9: return K_K9;
87  case 10: return K_K10;
88  case 11: return K_K11;
89  case 12: return K_K12;
90  case 13: return K_K13;
91  case 14: return K_K14;
92  case 15: return K_K15;
93  case 16: return K_K16;
94  case 17: return K_K17;
95  case 18: return K_K18;
96  }
97  assert(false);
98  return "";
99 }
100 
102 {
103 }
104 
106  {{// WHITE
107  K_NAKAGURO, "+E",
110  // BLACK
111  K_NAKAGURO, "+E",
114  }};
115 
117  {{"", K_K1, K_K2, K_K3, K_K4, K_K5, K_K6, K_K7, K_K8, K_K9}};
119  {{"", K_R1, K_R2, K_R3, K_R4, K_R5, K_R6, K_R7, K_R8, K_R9}};
121  {{// WHITE
122  K_NAKAGURO, "+E",
125  // BLACK
126  K_NAKAGURO, "+E",
129  }};
130 
134  {{// WHITE
135  K_NAKAGURO, "+E",
138  // BLACK
139  K_NAKAGURO, "+E",
142  }};
143 
147  {{"", " " K_R1, " " K_R2, " " K_R3, " " K_R4, " " K_R5, " " K_R6, " " K_R7, " " K_R8, " " K_R9}};
149  {{// WHITE
150  " " K_NAKAGURO, "+E",
151  "v" K_PPAWN, "v" K_PLANCE, "v" K_PKNIGHT, "v" K_PSILVER, "v" K_PBISHOP, "v" K_PROOK, "v" K_KING,
152  "v" K_GOLD, "v" K_PAWN, "v" K_LANCE, "v" K_KNIGHT, "v" K_SILVER, "v" K_BISHOP, "v" K_ROOK,
153  // BLACK
154  " " K_NAKAGURO, "+E",
155  " " K_PPAWN, " " K_PLANCE, " " K_PKNIGHT, " " K_PSILVER, " " K_PBISHOP, " " K_PROOK, " " K_KING,
156  " " K_GOLD, " " K_PAWN, " " K_LANCE, " " K_KNIGHT, " " K_SILVER, " " K_BISHOP, " " K_ROOK
157  }};
158 
159 
160 std::ostream& osl::record::
161 operator<<(std::ostream& os, const Color& c)
162 {
163  return os << c.value;
164 }
165 
167 escColSet() const
168 {
169  if (!color.isValid()) return;
170  os << "\033[" << color << "m"; //文字の属性をセットする
171 }
172 
174 escColReSet() const
175 {
176  if (!color.isValid()) return;
177  os << "\033[0m";
178 }
179 
182  const osl::Move *last_move) const
183 {
184  os << misc::eucToLang(K_WHITE_STAND) << " ";
185  BOOST_FOREACH(Ptype ptype, PieceStand::order)
186  {
187  const int count = state.countPiecesOnStand(WHITE, ptype);
188  if (count)
189  os << misc::eucToLang(pieces->stand_kanji(newPtypeO(BLACK, ptype)))
190  << count << " ";
191  }
192  os << std::endl;
193 
194  os << " ";
195  for(int x=9;x>0;x--)
196  {
197  os << misc::eucToLang(pieces->getSuji(x));
198  }
199  os << std::endl;
200 
201  os << "+";
202  for(int x=9*pieces->getSuji(1).size();x>0;x--)
203  {
204  os << "-";
205  }
206  os << "+" << std::endl;
207 
208  for(int y=1;y<=9;y++)
209  {
210  os << '|';
211  for(int x=9;x>0;x--)
212  {
213  const PtypeO ptypeo = state.pieceOnBoard(Square(x,y)).ptypeO();
214  const std::string piece = misc::eucToLang(pieces->kanji(ptypeo));
215  if (last_move &&
216  !last_move->isInvalid() &&
217  last_move->to() == Square(x,y))
218  {
219  ChangeShellColor csc(os, last_move_color);
220  os << piece;
221  } // csc destroyed
222  else if (isPiece(ptypeo)) {
223  Player owner = getOwner(ptypeo);
224  osl::record::Color color;
225  if (owner == BLACK)
226  color = black_color;
227  else
228  color = white_color;
229  ChangeShellColor csc(os, color);
230  os << piece;
231  } // csc destroyed
232  else
233  { // empty space
234  os << piece;
235  }
236  }
237  os << '|';
238  os << misc::eucToLang(pieces->getDan(y));
239 
240  os << std::endl;
241  }
242 
243  os << "+";
244  for(int x=9*pieces->getSuji(1).size();x>0;x--)
245  {
246  os << "-";
247  }
248  os << "+" << std::endl;
249 
250  // 持ち駒の表示
251  os << misc::eucToLang(K_BLACK_STAND) << " ";
252  BOOST_FOREACH(Ptype ptype, PieceStand::order)
253  {
254  const int count = state.countPiecesOnStand(BLACK, ptype);
255  if (count)
256  os << misc::eucToLang(pieces->stand_kanji(newPtypeO(BLACK, ptype)))
257  << count << " ";
258  }
259  os << std::endl;
260  os << state.turn() << std::endl;
261 }
262 
263 /* ------------------------------------------------------------------------- */
264 // ;;; Local Variables:
265 // ;;; mode:c++
266 // ;;; c-basic-offset:2
267 // ;;; End: