All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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;
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;
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: