My Project
feature/escape.h
Go to the documentation of this file.
1 /* escape.h
2  */
3 #ifndef _ESCAPE_H
4 #define _ESCAPE_H
5 
6 #include "osl/rating/feature.h"
8 
9 namespace osl
10 {
11  namespace rating
12  {
15  {
16  public:
19  bool match(const NumEffectState& state, Move move, const RatingEnv& env) const
20  {
21  return ! move.isDrop() && CountEffect2::match(state, move.from(), env);
22  }
23  };
24 
25  class PtypeAttacked : public Feature
26  {
27  Ptype self, attack;
28  public:
30  : Feature(std::string(Ptype_Table.getCsaName(s))+"<"+Ptype_Table.getCsaName(a)),
31  self(s), attack(a)
32  {
33  }
34  bool match(const NumEffectState& state, Move move, const RatingEnv&) const
35  {
36  return move.oldPtype() == self
37  && ! move.isDrop()
38  && state.findCheapAttack(alt(move.player()), move.from()).ptype()== attack;
39  }
40  };
41 
42  class ToSupported : public Feature
43  {
44  public:
45  ToSupported() : Feature("TS") {}
46  bool match(const NumEffectState& state, Move move, const RatingEnv&) const
47  {
48  return state.hasEffectAt(move.player(), move.to());
49  }
50  };
51 
52  class ImmediateEscape : public Feature
53  {
54  Ptype self, attack;
55  public:
57  : Feature(std::string(Ptype_Table.getCsaName(s))+"<"+Ptype_Table.getCsaName(a)),
58  self(s), attack(a)
59  {
60  }
61  bool match(const NumEffectState& state, Move move, const RatingEnv& env) const
62  {
63  if (move.isDrop())
64  return false;
65  if (move.ptype() != self)
66  return false;
67  const Move last_move = env.history.lastMove();
68  if (! last_move.isNormal() || last_move.ptype() != attack)
69  return false;
70  return state.hasEffectIf(last_move.ptypeO(), last_move.to(), move.from());
71  }
72  };
73 
74  class KingEscape : public Feature
75  {
77  public:
79  : Feature(std::string(Ptype_Table.getCsaName(s))), ptype(s)
80  {
81  }
82  bool match(const NumEffectState& state, Move move, const RatingEnv&) const
83  {
84  return state.inCheck()
85  && move.ptype() == ptype;
86  }
87  bool effectiveInCheck() const { return true; }
88  };
89  }
90 }
91 
92 #endif /* _ESCAPE_H */
93 // ;;; Local Variables:
94 // ;;; mode:c++
95 // ;;; c-basic-offset:2
96 // ;;; End:
osl::rating::FromEffect
移動元へのきき。attack defense は言葉の意味と逆で自分がattack
Definition: feature/escape.h:15
osl::rating::CountEffect2::defense
int defense
Definition: countEffect2.h:17
osl::NumEffectState::findCheapAttack
const Piece findCheapAttack(Player P, Square square) const
Definition: numEffectState.h:560
osl::rating::CountEffect2
Definition: countEffect2.h:15
osl::rating::ImmediateEscape::ImmediateEscape
ImmediateEscape(Ptype s, Ptype a)
Definition: feature/escape.h:56
osl::rating::KingEscape
Definition: feature/escape.h:75
osl::alt
constexpr Player alt(Player player)
Definition: basic_type.h:13
osl::rating::KingEscape::effectiveInCheck
bool effectiveInCheck() const
Definition: feature/escape.h:87
osl::rating::KingEscape::ptype
Ptype ptype
Definition: feature/escape.h:76
osl::rating::ImmediateEscape::match
bool match(const NumEffectState &state, Move move, const RatingEnv &env) const
Definition: feature/escape.h:61
osl::Move
圧縮していない moveの表現 .
Definition: basic_type.h:1052
osl::rating::ImmediateEscape
Definition: feature/escape.h:53
osl::rating::FromEffect::FromEffect
FromEffect(int attack, int defense)
Definition: feature/escape.h:17
osl::container::MoveStack::lastMove
const Move lastMove(size_t last=1) const
Definition: moveStack.h:28
osl::rating::Feature::name
const std::string & name() const
Definition: rating/feature.h:24
osl::rating::ToSupported::match
bool match(const NumEffectState &state, Move move, const RatingEnv &) const
Definition: feature/escape.h:46
osl::rating::ToSupported::ToSupported
ToSupported()
Definition: feature/escape.h:45
osl::Ptype
Ptype
駒の種類を4ビットでコード化する
Definition: basic_type.h:84
osl::NumEffectState::hasEffectIf
bool hasEffectIf(PtypeO ptypeo, Square attacker, Square target) const
attackerにptypeoの駒がいると仮定した場合にtargetに利きがあるかどうか を stateをupdateしないで確かめる.
Definition: numEffectState.h:465
osl::rating::PtypeAttacked::attack
Ptype attack
Definition: feature/escape.h:27
osl::NumEffectState::hasEffectAt
bool hasEffectAt(Square target) const
対象とするマスにあるプレイヤーの利きがあるかどうか.
Definition: numEffectState.h:324
osl::Ptype_Table
const PtypeTable Ptype_Table
Definition: tables.cc:97
osl::NumEffectState::inCheck
bool inCheck(Player P) const
Pの玉が王手状態
Definition: numEffectState.h:88
osl::rating::CountEffect2::match
bool match(const NumEffectState &state, Square position, const RatingEnv &env) const
Definition: countEffect2.h:37
osl::rating::Feature
Definition: rating/feature.h:15
osl::rating::PtypeAttacked
Definition: feature/escape.h:26
osl::Move::oldPtype
Ptype oldPtype() const
移動前のPtype, i.e., 成る手だった場合成る前
Definition: basic_type.h:1174
osl::rating::RatingEnv
Definition: ratingEnv.h:16
osl::rating::KingEscape::KingEscape
KingEscape(Ptype s)
Definition: feature/escape.h:78
osl::Move::isDrop
bool isDrop() const
Definition: basic_type.h:1150
osl::Move::ptypeO
PtypeO ptypeO() const
移動後のPtype, i.e., 成る手だった場合成った後
Definition: basic_type.h:1162
osl::rating::RatingEnv::history
MoveStack history
Definition: ratingEnv.h:18
osl::Move::isNormal
bool isNormal() const
INVALID でも PASS でもない.
Definition: basic_type.h:1088
osl::Move::from
const Square from() const
Definition: basic_type.h:1125
osl::NumEffectState
利きを持つ局面
Definition: numEffectState.h:34
osl::rating::PtypeAttacked::match
bool match(const NumEffectState &state, Move move, const RatingEnv &) const
Definition: feature/escape.h:34
osl::rating::ImmediateEscape::self
Ptype self
Definition: feature/escape.h:54
osl::Piece::ptype
Ptype ptype() const
Definition: basic_type.h:821
osl::rating::PtypeAttacked::self
Ptype self
Definition: feature/escape.h:27
std
Definition: basic_type.h:1353
osl::rating::CountEffect2::attack
int attack
Definition: countEffect2.h:17
osl::Move::ptype
Ptype ptype() const
Definition: basic_type.h:1155
osl::rating::ToSupported
Definition: feature/escape.h:43
osl::rating::FromEffect::match
bool match(const NumEffectState &state, Move move, const RatingEnv &env) const
Definition: feature/escape.h:19
osl::rating::ImmediateEscape::attack
Ptype attack
Definition: feature/escape.h:54
osl::rating::PtypeAttacked::PtypeAttacked
PtypeAttacked(Ptype s, Ptype a)
Definition: feature/escape.h:29
osl::Move::to
const Square to() const
Definition: basic_type.h:1132
countEffect2.h
osl::rating::KingEscape::match
bool match(const NumEffectState &state, Move move, const RatingEnv &) const
Definition: feature/escape.h:82
osl::Move::player
Player player() const
Definition: basic_type.h:1195
osl
Definition: additionalEffect.h:6
feature.h