My Project
pattern.cc
Go to the documentation of this file.
1 /* pattern.cc
2  */
4 #include <sstream>
5 
6 const std::string osl::rating::Pattern::name(Direction d, Direction d2, Ptype self, Ptype target, bool same)
7 {
8  std::ostringstream os;
9  os << d;
10  if (d2 != Pattern::INVALID)
11  os << d2;
12  os << "-" << Ptype_Table.getCsaName(self) << "-"
13  << Ptype_Table.getCsaName(target) << (same ? "=" : "!");
14  return os.str();
15 }
16 
17 const std::string osl::rating::LongTarget::name() const
18 {
19  std::ostringstream os;
20  os << Ptype_Table.getCsaName(target)
21  << (same ? "=" : "!") << (promotable ? "p" : "-");
22  return os.str() + CountEffect2::name(attack, defense);
23 }
24 const std::string osl::rating::LongTarget2::name() const
25 {
26  std::ostringstream os;
27  os << Ptype_Table.getCsaName(target)
28  << (same ? "=" : "!");
29  return os.str();
30 }
31 
34  : Feature(name(d, s)+"-"+t.name()), direction(d), self(s), target(t)
35 {
36  assert(unpromote(s) == LANCE || unpromote(s) == BISHOP || unpromote(s) == ROOK);
37 }
38 
40 PatternLong::nextPieceOrEnd(const SimpleState& state, Square start, Offset diff)
41 {
42  Square cur = start;
43  assert(cur.isOnBoard());
44  assert(! diff.zero());
45  cur += diff;
46  while (state.pieceAt(cur) == Piece::EMPTY())
47  cur += diff;
48  const Piece p = state.pieceAt(cur);
49  if (! p.isEdge())
50  return std::make_pair(p, cur);
51  cur -= diff;
52  assert(cur.isOnBoard());
53  if (cur == start)
54  return std::make_pair(p, cur); // EDGE
55  return std::make_pair(state.pieceOnBoard(cur), cur); // EMPTY
56 }
57 
59 PatternLong::nextPieceOrEnd(const SimpleState& state, Square start, Player player, Direction direction)
60 {
61  const Offset diff = Board_Table.getOffset(player, direction);
62  return nextPieceOrEnd(state, start, diff);
63 }
64 
66 PatternLong::find(const NumEffectState& state, Move move, Direction direction)
67 {
68  PieceSquare p = nextPieceOrEnd(state, move.to(), move.player(), direction);
69  if (p.second == move.from())
70  p = nextPieceOrEnd(state, p.second, move.player(), direction);
71  return p;
72 }
73 
75 {
76  std::ostringstream os;
77  os << d << "-" << Ptype_Table.getCsaName(self);
78  return os.str();
79 }
80 
81 
84  : Feature(name(d, s)+"--"+t2.name()), direction(d), self(s), target2(t2)
85 {
86  assert(unpromote(s) == LANCE || unpromote(s) == BISHOP || unpromote(s) == ROOK);
87 }
88 
89 const std::string osl::rating::
91 {
92  std::ostringstream os;
93  os << d << "-" << Ptype_Table.getCsaName(self);
94  return os.str();
95 }
96 
99  : Feature(std::string(Ptype_Table.getCsaName(s))/*+"-"+Ptype_Table.getCsaName(a)+">"*/+t.name()),
100  self(s), attack(a), target(t)
101 {
102 }
103 
105 PatternBlock::find(const NumEffectState& state, Move move, Ptype ap)
106 {
107  Piece attack;
108  if (ap == LANCE) {
109  attack = state.findAttackAt<LANCE>(alt(state.turn()), move.to());
110  if (attack.ptype() == LANCE)
112  (state, move.to(),
113  Board_Table.getShortOffset(Offset32(move.to(), attack.square())));
114  } else if (ap == BISHOP) {
115  attack = state.findAttackAt<BISHOP>(alt(state.turn()), move.to());
116  if (attack.isPiece())
118  (state, move.to(),
119  Board_Table.getShortOffset(Offset32(move.to(), attack.square())));
120  } else if (ap == ROOK) {
121  attack = state.findAttackAt<ROOK>(alt(state.turn()), move.to());
122  if (attack.isPiece())
124  (state, move.to(),
125  Board_Table.getShortOffset(Offset32(move.to(), attack.square())));
126  }
127  return std::make_pair(Piece::EDGE(), Square::STAND());
128 }
129 
130 /* ------------------------------------------------------------------------- */
131 // ;;; Local Variables:
132 // ;;; mode:c++
133 // ;;; c-basic-offset:2
134 // ;;; End:
const Offset getOffset(Direction dir) const
Definition: boardTable.h:47
const Offset getShortOffset(Offset32 offset32) const
Longの利きの可能性のあるoffsetの場合は, 反復に使う offsetを Shortの利きのoffsetの場合はそれ自身を返す.
Definition: boardTable.h:110
圧縮していない moveの表現 .
Definition: basic_type.h:1052
Player player() const
Definition: basic_type.h:1195
const Square to() const
Definition: basic_type.h:1132
const Square from() const
Definition: basic_type.h:1125
利きを持つ局面
const Piece findAttackAt(Player attack, Square target) const
return a piece s.t.
座標の差分
Definition: basic_type.h:430
bool zero() const
Definition: basic_type.h:502
Ptype ptype() const
Definition: basic_type.h:821
const Square square() const
Definition: basic_type.h:832
bool isEdge() const
Definition: basic_type.h:919
bool isPiece() const
Definition: basic_type.h:953
static const Piece EMPTY()
Definition: basic_type.h:797
static const Piece EDGE()
Definition: basic_type.h:798
const char * getCsaName(Ptype ptype) const
Definition: ptypeTable.h:80
const Piece pieceOnBoard(Square sq) const
Definition: simpleState.h:170
Player turn() const
Definition: simpleState.h:220
const Piece pieceAt(Square sq) const
Definition: simpleState.h:167
static const Square STAND()
Definition: basic_type.h:548
bool isOnBoard() const
盤面上を表すかどうかの判定. 1<=x() && x()<=9 && 1<=y() && y()<=9 Squareの内部表現に依存する.
Definition: basic_type.h:583
const std::string & name() const
PatternBlock(Ptype s, Ptype a, LongTarget t)
Definition: pattern.cc:98
static const PieceSquare find(const NumEffectState &state, Move move, Ptype attacker_ptype)
Definition: pattern.cc:105
PatternLong2(Direction d, Ptype s, LongTarget2 t2)
Definition: pattern.cc:83
PatternLong(Direction d, Ptype s, LongTarget t)
Definition: pattern.cc:33
static const PieceSquare nextPieceOrEnd(const SimpleState &state, Square start, Player player, Direction direction)
direction方向に空白を進み、駒を探す
Definition: pattern.cc:59
static const PieceSquare find(const NumEffectState &state, Move move, Direction direction)
Definition: pattern.cc:66
static const Direction INVALID
Definition: pattern.h:16
std::pair< Piece, Square > PieceSquare
Definition: pattern.h:60
Ptype
駒の種類を4ビットでコード化する
Definition: basic_type.h:84
@ ROOK
Definition: basic_type.h:100
@ BISHOP
Definition: basic_type.h:99
@ LANCE
Definition: basic_type.h:96
const PtypeTable Ptype_Table
Definition: tables.cc:97
Ptype unpromote(Ptype ptype)
ptypeがpromote後の型の時に,promote前の型を返す. promoteしていない型の時はそのまま返す
Definition: basic_type.h:157
const BoardTable Board_Table
Definition: tables.cc:95
Direction
Definition: basic_type.h:310
Offset32Base< 8, 9 > Offset32
Definition: offset32.h:63
Player
Definition: basic_type.h:8
constexpr Player alt(Player player)
Definition: basic_type.h:13
static std::string name(int attack, int defense)
Definition: countEffect2.cc:9
const std::string name() const
Definition: pattern.cc:24
const std::string name() const
Definition: pattern.cc:17