kanjiPrint.cc
Go to the documentation of this file.
#include "osl/record/kanjiPrint.h"
#include "osl/record/kanjiCode.h"
#include "osl/numEffectState.h"
#include "osl/misc/eucToLang.h"
#include <iostream>
#include <string>
#include <algorithm>
#include <cctype>
bool caseInsentiveCharCompare(char a, char b)
{
return toupper(a) == toupper(b);
}
bool caseInsentiveCompare(const std::string& s1, const std::string& s2)
{
return s1.size() == s2.size() &&
equal(s1.begin(), s1.end(), s2.begin(), caseInsentiveCharCompare);
}
const osl::record::Color osl::record::Color::NONE ("", "NONE", false);
const osl::record::Color osl::record::Color::Black ("0;30", "BLACK");
const osl::record::Color osl::record::Color::Red ("0;31", "RED");
const osl::record::Color osl::record::Color::Green ("0;32", "GREEN");
const osl::record::Color osl::record::Color::Brown ("0;33", "BROWN");
const osl::record::Color osl::record::Color::Blue ("0;34", "BLUE");
const osl::record::Color osl::record::Color::Purple ("0;35", "PURPLE");
const osl::record::Color osl::record::Color::Cyan ("0;36", "CYAN");
const osl::record::Color osl::record::Color::LightGray ("0;37", "LIGHTGRAY");
const osl::record::Color osl::record::Color::DarkGray ("1;30", "DARKGRAY");
const osl::record::Color osl::record::Color::LightRed ("1;31", "LIGHTRED");
const osl::record::Color osl::record::Color::LightGreen ("1;32", "LIGHTGREEN");
const osl::record::Color osl::record::Color::Yellow ("1;33", "YELLOW");
const osl::record::Color osl::record::Color::LightBlue ("1;34", "LIGHTBLUE");
const osl::record::Color osl::record::Color::LightPurple ("1;35", "LIGHTPURPLE");
const osl::record::Color osl::record::Color::LightCyan ("1;36", "LIGHTCYAN");
const osl::record::Color osl::record::Color::White ("1;37", "WHITE");
const osl::record::Color osl::record::
Color::colorFor(const std::string& str)
{
static const CArray<const osl::record::Color,17> colors = {{
osl::record::Color::NONE,
osl::record::Color::Black, osl::record::Color::Red,
osl::record::Color::Green, osl::record::Color::Brown,
osl::record::Color::Blue, osl::record::Color::Purple,
osl::record::Color::Cyan, osl::record::Color::LightGray,
osl::record::Color::DarkGray, osl::record::Color::LightRed,
osl::record::Color::LightGreen, osl::record::Color::Yellow,
osl::record::Color::LightBlue, osl::record::Color::LightPurple,
osl::record::Color::LightCyan, osl::record::Color::White}};
for (const auto& c: colors) {
if (caseInsentiveCompare(str, c.getName()))
return c;
}
return osl::record::Color::NONE;
}
osl::record::Color::Color(const std::string& value, const std::string& name, const bool valid)
: value(value), name(name), valid(valid)
{
}
osl::record::Color::~Color()
{
}
std::string osl::record::
kanjiNumber(const int n)
{
assert((1 <= n) && (n <= 18));
switch(n) {
case 1: return K_K1;
case 2: return K_K2;
case 3: return K_K3;
case 4: return K_K4;
case 5: return K_K5;
case 6: return K_K6;
case 7: return K_K7;
case 8: return K_K8;
case 9: return K_K9;
case 10: return K_K10;
case 11: return K_K11;
case 12: return K_K12;
case 13: return K_K13;
case 14: return K_K14;
case 15: return K_K15;
case 16: return K_K16;
case 17: return K_K17;
case 18: return K_K18;
}
assert(false);
return "";
}
osl::record::Characters::~Characters()
{
}
const osl::CArray<std::string,32> osl::record::Characters::stand =
{{// WHITE
K_NAKAGURO, "+E",
K_PPAWN, K_PLANCE, K_PKNIGHT, K_PSILVER, K_PBISHOP, K_PROOK, K_KING,
K_GOLD, K_PAWN, K_LANCE, K_KNIGHT, K_SILVER, K_BISHOP, K_ROOK,
// BLACK
K_NAKAGURO, "+E",
K_PPAWN, K_PLANCE, K_PKNIGHT, K_PSILVER, K_PBISHOP, K_PROOK, K_KING,
K_GOLD, K_PAWN, K_LANCE, K_KNIGHT, K_SILVER, K_BISHOP, K_ROOK
}};
const osl::CArray<std::string,10> osl::record::StandardCharacters::dan =
{{"", K_K1, K_K2, K_K3, K_K4, K_K5, K_K6, K_K7, K_K8, K_K9}};
const osl::CArray<std::string,10> osl::record::StandardCharacters::suji =
{{"", K_R1, K_R2, K_R3, K_R4, K_R5, K_R6, K_R7, K_R8, K_R9}};
const osl::CArray<std::string,32> osl::record::StandardCharacters::pieces =
{{// WHITE
K_NAKAGURO, "+E",
K_PPAWN, K_PLANCE, K_PKNIGHT, K_PSILVER, K_PBISHOP, K_PROOK, K_KING,
K_GOLD, K_PAWN, K_LANCE, K_KNIGHT, K_SILVER, K_BISHOP, K_ROOK,
// BLACK
K_NAKAGURO, "+E",
K_PPAWN, K_PLANCE, K_PKNIGHT, K_PSILVER, K_PBISHOP, K_PROOK, K_KING,
K_GOLD, K_PAWN, K_LANCE, K_KNIGHT, K_SILVER, K_BISHOP, K_ROOK
}};
const osl::CArray<std::string,10> osl::record::RussianCharacters::dan = osl::record::StandardCharacters::dan;
const osl::CArray<std::string,10> osl::record::RussianCharacters::suji = osl::record::StandardCharacters::suji;
const osl::CArray<std::string,32> osl::record::RussianCharacters::pieces =
{{// WHITE
K_NAKAGURO, "+E",
K_PPAWN_R, K_PLANCE_R, K_PKNIGHT_R, K_PSILVER_R, K_PBISHOP_R, K_PROOK_R, K_KING_R,
K_GOLD_R, K_PAWN_R, K_LANCE_R, K_KNIGHT_R, K_SILVER_R, K_BISHOP_R, K_ROOK_R,
// BLACK
K_NAKAGURO, "+E",
K_PPAWN, K_PLANCE, K_PKNIGHT, K_PSILVER, K_PBISHOP, K_PROOK, K_KING,
K_GOLD, K_PAWN, K_LANCE, K_KNIGHT, K_SILVER, K_BISHOP, K_ROOK
}};
const osl::CArray<std::string,10> osl::record::KIFCharacters::dan =
osl::record::StandardCharacters::dan;
const osl::CArray<std::string,10> osl::record::KIFCharacters::suji =
{{"", " " K_R1, " " K_R2, " " K_R3, " " K_R4, " " K_R5, " " K_R6, " " K_R7, " " K_R8, " " K_R9}};
const osl::CArray<std::string,32> osl::record::KIFCharacters::pieces =
{{// WHITE
" " K_NAKAGURO, "+E",
"v" K_PPAWN, "v" K_PLANCE, "v" K_PKNIGHT, "v" K_PSILVER, "v" K_PBISHOP, "v" K_PROOK, "v" K_KING,
"v" K_GOLD, "v" K_PAWN, "v" K_LANCE, "v" K_KNIGHT, "v" K_SILVER, "v" K_BISHOP, "v" K_ROOK,
// BLACK
" " K_NAKAGURO, "+E",
" " K_PPAWN, " " K_PLANCE, " " K_PKNIGHT, " " K_PSILVER, " " K_PBISHOP, " " K_PROOK, " " K_KING,
" " K_GOLD, " " K_PAWN, " " K_LANCE, " " K_KNIGHT, " " K_SILVER, " " K_BISHOP, " " K_ROOK
}};
std::ostream& osl::record::
operator<<(std::ostream& os, const Color& c)
{
return os << c.value;
}
void osl::record::ChangeShellColor::
escColSet() const
{
if (!color.isValid()) return;
os << "\033[" << color << "m"; //文字の属性をセットする
}
void osl::record::ChangeShellColor::
escColReSet() const
{
if (!color.isValid()) return;
os << "\033[0m";
}
void osl::record::KanjiPrint::
print(const SimpleState& state,
const Move *last_move) const
{
os << misc::eucToLang(K_WHITE_STAND) << " ";
for (Ptype ptype: PieceStand::order) {
const int count = state.countPiecesOnStand(WHITE, ptype);
if (count)
os << misc::eucToLang(pieces->stand_kanji(newPtypeO(BLACK, ptype)))
<< count << " ";
}
os << std::endl;
os << " ";
for(int x=9;x>0;x--)
{
os << misc::eucToLang(pieces->getSuji(x));
}
os << std::endl;
os << "+";
for(int x=9*pieces->getSuji(1).size();x>0;x--)
{
os << "-";
}
os << "+" << std::endl;
for(int y=1;y<=9;y++)
{
os << '|';
for(int x=9;x>0;x--)
{
const PtypeO ptypeo = state.pieceOnBoard(Square(x,y)).ptypeO();
const std::string piece = misc::eucToLang(pieces->kanji(ptypeo));
if (last_move &&
!last_move->isInvalid() &&
last_move->to() == Square(x,y))
{
ChangeShellColor csc(os, last_move_color);
os << piece;
} // csc destroyed
else if (isPiece(ptypeo)) {
Player owner = getOwner(ptypeo);
osl::record::Color color;
if (owner == BLACK)
color = black_color;
else
color = white_color;
ChangeShellColor csc(os, color);
os << piece;
} // csc destroyed
else
{ // empty space
os << piece;
}
}
os << '|';
os << misc::eucToLang(pieces->getDan(y));
os << std::endl;
}
os << "+";
for(int x=9*pieces->getSuji(1).size();x>0;x--)
{
os << "-";
}
os << "+" << std::endl;
// 持ち駒の表示
os << misc::eucToLang(K_BLACK_STAND) << " ";
for (Ptype ptype: PieceStand::order) {
const int count = state.countPiecesOnStand(BLACK, ptype);
if (count)
os << misc::eucToLang(pieces->stand_kanji(newPtypeO(BLACK, ptype)))
<< count << " ";
}
os << std::endl;
os << state.turn() << std::endl;
}
/* ------------------------------------------------------------------------- */
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
osl::CArray
Definition container.h:20
osl::Move
圧縮していない moveの表現 .
Definition basic_type.h:1052
osl::Move::isInvalid
bool isInvalid() const
state に apply 可能でない場合にtrue
Definition basic_type.h:1202
osl::Move::to
const Square to() const
Definition basic_type.h:1132
osl::PieceStand::order
static const CArray< Ptype, 7 > order
持駒の表示で良く使われる順番.
Definition bits/pieceStand.h:41
osl::Piece::ptypeO
PtypeO ptypeO() const
Definition basic_type.h:824
osl::SimpleState
Definition simpleState.h:35
osl::SimpleState::pieceOnBoard
const Piece pieceOnBoard(Square sq) const
Definition simpleState.h:170
osl::SimpleState::turn
Player turn() const
Definition simpleState.h:220
osl::SimpleState::countPiecesOnStand
int countPiecesOnStand(Player pl, Ptype ptype) const
持駒の枚数を数える
Definition simpleState.h:182
osl::Square
Definition basic_type.h:532
osl::record::ChangeShellColor
shellの文字出力にて、色を変える。
Definition kanjiPrint.h:78
osl::record::ChangeShellColor::escColSet
void escColSet() const
Definition kanjiPrint.cc:162
osl::record::ChangeShellColor::color
const Color color
Definition kanjiPrint.h:81
osl::record::ChangeShellColor::os
std::ostream & os
Definition kanjiPrint.h:80
osl::record::ChangeShellColor::escColReSet
void escColReSet() const
Definition kanjiPrint.cc:169
osl::record::Characters::stand
static const CArray< std::string, 32 > stand
Definition kanjiPrint.h:100
osl::record::Characters::~Characters
virtual ~Characters()
Definition kanjiPrint.cc:96
osl::record::Color
カラーコードを保持するクラス。
Definition kanjiPrint.h:23
osl::record::Color::value
std::string value
Definition kanjiPrint.h:29
osl::record::Color::Red
static const Color Red
Definition kanjiPrint.h:54
osl::record::Color::name
std::string name
Definition kanjiPrint.h:30
osl::record::Color::Cyan
static const Color Cyan
Definition kanjiPrint.h:59
osl::record::Color::valid
bool valid
Definition kanjiPrint.h:31
osl::record::Color::Yellow
static const Color Yellow
Definition kanjiPrint.h:64
osl::record::Color::Brown
static const Color Brown
Definition kanjiPrint.h:56
osl::record::Color::Color
Color()
Definition kanjiPrint.h:25
osl::record::Color::Purple
static const Color Purple
Definition kanjiPrint.h:58
osl::record::Color::~Color
~Color()
Definition kanjiPrint.cc:64
osl::record::Color::White
static const Color White
Definition kanjiPrint.h:68
osl::record::Color::colorFor
static const Color colorFor(const std::string &str)
文字列に対応するColor objectを返す
Definition kanjiPrint.cc:40
osl::record::Color::LightGreen
static const Color LightGreen
Definition kanjiPrint.h:63
osl::record::Color::LightCyan
static const Color LightCyan
Definition kanjiPrint.h:67
osl::record::Color::Black
static const Color Black
Definition kanjiPrint.h:53
osl::record::Color::LightGray
static const Color LightGray
Definition kanjiPrint.h:60
osl::record::Color::Blue
static const Color Blue
Definition kanjiPrint.h:57
osl::record::Color::LightBlue
static const Color LightBlue
Definition kanjiPrint.h:65
osl::record::Color::DarkGray
static const Color DarkGray
Definition kanjiPrint.h:61
osl::record::Color::Green
static const Color Green
Definition kanjiPrint.h:55
osl::record::Color::LightRed
static const Color LightRed
Definition kanjiPrint.h:62
osl::record::Color::NONE
static const Color NONE
色指定しない（デフォルトのまま）ことを示す特別なオブジェクト
Definition kanjiPrint.h:52
osl::record::Color::LightPurple
static const Color LightPurple
Definition kanjiPrint.h:66
osl::record::KanjiPrint::os
std::ostream & os
Definition kanjiPrint.h:187
osl::record::KanjiPrint::black_color
Color black_color
Definition kanjiPrint.h:189
osl::record::KanjiPrint::white_color
Color white_color
Definition kanjiPrint.h:190
osl::record::KanjiPrint::print
void print(const SimpleState &state, const Move *last_move=NULL) const
出力
Definition kanjiPrint.cc:176
osl::record::KanjiPrint::pieces
const std::shared_ptr< Characters > pieces
Definition kanjiPrint.h:188
osl::record::KanjiPrint::last_move_color
Color last_move_color
Definition kanjiPrint.h:191
eucToLang.h
kanjiCode.h
K_PSILVER
#define K_PSILVER
Definition kanjiCode.h:74
K_KNIGHT
#define K_KNIGHT
Definition kanjiCode.h:67
K_NAKAGURO
#define K_NAKAGURO
Definition kanjiCode.h:16
K_K18
#define K_K18
Definition kanjiCode.h:44
K_K13
#define K_K13
Definition kanjiCode.h:39
K_R4
#define K_R4
Definition kanjiCode.h:21
K_BLACK_STAND
#define K_BLACK_STAND
Definition kanjiCode.h:95
K_R2
#define K_R2
Definition kanjiCode.h:19
K_PROOK_R
#define K_PROOK_R
Definition kanjiCode.h:87
K_R5
#define K_R5
Definition kanjiCode.h:22
K_PLANCE
#define K_PLANCE
Definition kanjiCode.h:64
K_PLANCE_R
#define K_PLANCE_R
Definition kanjiCode.h:65
K_GOLD
#define K_GOLD
Definition kanjiCode.h:77
K_K3
#define K_K3
Definition kanjiCode.h:29
K_K14
#define K_K14
Definition kanjiCode.h:40
K_LANCE
#define K_LANCE
Definition kanjiCode.h:62
K_K7
#define K_K7
Definition kanjiCode.h:33
K_K15
#define K_K15
Definition kanjiCode.h:41
K_ROOK
#define K_ROOK
Definition kanjiCode.h:83
K_KING
#define K_KING
Definition kanjiCode.h:88
K_PAWN
#define K_PAWN
Definition kanjiCode.h:58
K_K11
#define K_K11
Definition kanjiCode.h:37
K_R8
#define K_R8
Definition kanjiCode.h:25
K_K8
#define K_K8
Definition kanjiCode.h:34
K_KNIGHT_R
#define K_KNIGHT_R
Definition kanjiCode.h:68
K_K9
#define K_K9
Definition kanjiCode.h:35
K_R7
#define K_R7
Definition kanjiCode.h:24
K_PPAWN_R
#define K_PPAWN_R
Definition kanjiCode.h:61
K_SILVER_R
#define K_SILVER_R
Definition kanjiCode.h:73
K_PSILVER_R
#define K_PSILVER_R
Definition kanjiCode.h:75
K_PPAWN
#define K_PPAWN
Definition kanjiCode.h:60
K_K4
#define K_K4
Definition kanjiCode.h:30
K_GOLD_R
#define K_GOLD_R
Definition kanjiCode.h:78
K_WHITE_STAND
#define K_WHITE_STAND
Definition kanjiCode.h:96
K_LANCE_R
#define K_LANCE_R
Definition kanjiCode.h:63
K_PKNIGHT_R
#define K_PKNIGHT_R
Definition kanjiCode.h:70
K_BISHOP
#define K_BISHOP
Definition kanjiCode.h:79
K_PBISHOP
#define K_PBISHOP
Definition kanjiCode.h:81
K_K5
#define K_K5
Definition kanjiCode.h:31
K_K1
#define K_K1
Definition kanjiCode.h:27
K_PKNIGHT
#define K_PKNIGHT
Definition kanjiCode.h:69
K_K10
#define K_K10
Definition kanjiCode.h:36
K_R6
#define K_R6
Definition kanjiCode.h:23
K_SILVER
#define K_SILVER
Definition kanjiCode.h:72
K_K17
#define K_K17
Definition kanjiCode.h:43
K_PROOK
#define K_PROOK
Definition kanjiCode.h:85
K_KING_R
#define K_KING_R
Definition kanjiCode.h:90
K_ROOK_R
#define K_ROOK_R
Definition kanjiCode.h:84
K_R3
#define K_R3
Definition kanjiCode.h:20
K_R9
#define K_R9
Definition kanjiCode.h:26
K_PBISHOP_R
#define K_PBISHOP_R
Definition kanjiCode.h:82
K_R1
#define K_R1
Definition kanjiCode.h:18
K_K2
#define K_K2
Definition kanjiCode.h:28
K_PAWN_R
#define K_PAWN_R
Definition kanjiCode.h:59
K_K6
#define K_K6
Definition kanjiCode.h:32
K_K16
#define K_K16
Definition kanjiCode.h:42
K_BISHOP_R
#define K_BISHOP_R
Definition kanjiCode.h:80
K_K12
#define K_K12
Definition kanjiCode.h:38
caseInsentiveCharCompare
bool caseInsentiveCharCompare(char a, char b)
Definition kanjiPrint.cc:10
caseInsentiveCompare
bool caseInsentiveCompare(const std::string &s1, const std::string &s2)
Definition kanjiPrint.cc:15
kanjiPrint.h
osl::misc::eucToLang
std::string eucToLang(const std::string &src)
Definition eucToLang.cc:14
osl::record::kanjiNumber
std::string kanjiNumber(const int n)
漢数字を返す（持ち駒の数などで用いる）
Definition kanjiPrint.cc:69
osl::record::operator<<
std::ostream & operator<<(std::ostream &os, const Color &c)
Definition kanjiPrint.cc:156
osl::Ptype
Ptype
駒の種類を4ビットでコード化する
Definition basic_type.h:84
osl::getOwner
Player getOwner(PtypeO ptypeO)
Definition basic_type.h:256
osl::Player
Player
Definition basic_type.h:8
osl::WHITE
@ WHITE
Definition basic_type.h:10
osl::BLACK
@ BLACK
Definition basic_type.h:9
osl::isPiece
constexpr bool isPiece(Ptype ptype)
ptypeが空白やEDGEでないかのチェック
Definition basic_type.h:120
osl::PtypeO
PtypeO
Player + Ptype [-15, 15] PtypeO の O は Owner の O.
Definition basic_type.h:199
osl::newPtypeO
PtypeO newPtypeO(Player player, Ptype ptype)
Definition basic_type.h:211
numEffectState.h
osl::record::KIFCharacters::dan
static const CArray< std::string, 10 > dan
Definition kanjiPrint.h:172
osl::record::KIFCharacters::pieces
static const CArray< std::string, 32 > pieces
Definition kanjiPrint.h:143
osl::record::KIFCharacters::suji
static const CArray< std::string, 10 > suji
Definition kanjiPrint.h:141
osl::record::RussianCharacters::suji
static const CArray< std::string, 10 > suji
Definition kanjiPrint.h:161
osl::record::RussianCharacters::dan
static const CArray< std::string, 10 > dan
Definition kanjiPrint.h:160
osl::record::RussianCharacters::pieces
static const CArray< std::string, 32 > pieces
Definition kanjiPrint.h:128
osl::record::StandardCharacters::pieces
static const CArray< std::string, 32 > pieces
盤面上の駒の漢字文字
Definition kanjiPrint.h:115
osl::record::StandardCharacters::dan
static const CArray< std::string, 10 > dan
段数の文字
Definition kanjiPrint.h:111
osl::record::StandardCharacters::suji
static const CArray< std::string, 10 > suji
筋の文字。駒の文字幅に合わせる必要がある。
Definition kanjiPrint.h:113