My Project
neighboring8Direct.h
Go to the documentation of this file.
1 /* neighboring8Direct.h
2  */
3 #ifndef EFFECT_UTIL_NEIGHBORING8DIRECT_H
4 #define EFFECT_UTIL_NEIGHBORING8DIRECT_H
5 
6 #include "osl/numEffectState.h"
7 
8 namespace osl
9 {
10  namespace effect_util
11  {
16  {
17  class Table
18  {
19  struct Entry
20  {
24  {
25  }
26  };
28  friend class Neighboring8Direct;
29  void init(Player);
30  public:
31  bool hasEffect(const NumEffectState& state,
32  PtypeO ptypeo, Square from,
33  Square target) const
34  {
35  assert(from.isOnBoard());
36  assert(target.isOnBoard());
37  const Offset32 offset32 = Offset32(target, from);
38  const Entry& e = table[ptypeOIndex(ptypeo)][offset32.index()];
40  return true;
41  if (e.nearest.zero())
42  return false;
43  assert(Ptype_Table.hasLongMove(getPtype(ptypeo)));
44  const Square nearest = from+e.nearest;
45  if (nearest.isEdge())
46  {
47  return false;
48  }
49  return state.isEmptyBetween(from, nearest, false);
50  }
52  PtypeO ptypeo, Square from,
53  Square target) const
54  {
55  const Offset32 offset32 = Offset32(target, from);
56  const Entry& e = table[ptypeOIndex(ptypeo)][offset32.index()];
58  return true;
59  if (e.nearest.zero())
60  return false;
61  assert(Ptype_Table.hasLongMove(getPtype(ptypeo)));
62  const Square nearest = from+e.nearest;
63  if (nearest.isEdge())
64  {
65  return false;
66  }
67  Offset offset=Board_Table.getShortOffset(Offset32(nearest,from));
68  assert(! offset.zero());
69  Square pos=from+offset;
70  Piece p = state.pieceAt(pos);
71  for (; p.isEmpty(); pos+=offset, p=state.pieceAt(pos)) {
72  if (pos==nearest)
73  return true;
74  }
75  assert(p.isPiece());
76  if (pos == nearest || state.hasEffectByPiece(p, nearest))
77  return true;
78  const Player attack = getOwner(ptypeo);
79  if (target != state.kingSquare(alt(attack)))
80  return false;
81  // new pin?
82  const Direction dir = longToShort(Board_Table.getLongDirection(attack,Offset32(nearest, from)));
83  return pos == state.kingMobilityOfPlayer(alt(attack), dir);
84  }
86  PtypeO ptypeo, Square from,
87  Square target) const
88  {
89  const Offset32 offset32 = Offset32(target, from);
90  const Entry& e = table[ptypeOIndex(ptypeo)][offset32.index()];
92  return from;
93  if (e.nearest.zero())
94  return Square::STAND();
95  assert(Ptype_Table.hasLongMove(getPtype(ptypeo)));
96  const Square nearest = from+e.nearest;
97  if (!nearest.isEdge() && state.isEmptyBetween(from, nearest, false))
98  return nearest;
99  return Square::STAND();
100  }
101  };
102  // tables.ccに入れればconstに出来る
103  static Table table;
104  public:
108  static bool hasEffect(const NumEffectState& state,
109  PtypeO ptypeo, Square from,
110  Square target)
111  {
112  return table.hasEffect(state, ptypeo, from, target);
113  }
118  static bool hasEffectOrAdditional(const NumEffectState& state,
119  PtypeO ptypeo, Square from,
120  Square target)
121  {
122  return table.hasEffectOrAdditional(state, ptypeo, from, target);
123  }
124  static Square findNearest(const NumEffectState& state,
125  PtypeO ptypeo, Square from,
126  Square target)
127  {
128  return table.findNearest(state, ptypeo, from, target);
129  }
130  private:
131  static bool hasEffectFromTo(const NumEffectState& state,
132  PtypeO ptypeo, Square from,
133  Square target, Direction d);
134  public:
135  static bool hasEffectNaive(const NumEffectState& state,
136  PtypeO ptypeo, Square from,
137  Square target);
138  static void init();
139  };
140 
141  } // namespace effect_util
142  using effect_util::Neighboring8Direct;
143 } // namespace osl
144 
145 #endif /* EFFECT_UTIL_NEIGHBORING8DIRECT_H */
146 // ;;; Local Variables:
147 // ;;; mode:c++
148 // ;;; c-basic-offset:2
149 // ;;; End:
osl::SimpleState::pieceAt
const Piece pieceAt(Square sq) const
Definition: simpleState.h:167
osl::Square
Definition: basic_type.h:532
osl::effect_util::Neighboring8Direct::Table::Entry::Entry
Entry()
Definition: neighboring8Direct.h:23
osl::Square::isOnBoard
bool isOnBoard() const
盤面上を表すかどうかの判定. 1<=x() && x()<=9 && 1<=y() && y()<=9 Squareの内部表現に依存する.
Definition: basic_type.h:583
osl::Board_Table
const BoardTable Board_Table
Definition: tables.cc:95
osl::alt
constexpr Player alt(Player player)
Definition: basic_type.h:13
Neighboring8Direct
Definition: neighboring8Direct.cc:9
osl::effect_util::Neighboring8Direct::findNearest
static Square findNearest(const NumEffectState &state, PtypeO ptypeo, Square from, Square target)
Definition: neighboring8Direct.h:124
osl::Offset32
Offset32Base< 8, 9 > Offset32
Definition: offset32.h:63
osl::effect_util::Neighboring8Direct::Table::Entry::has_unblockable_effect
bool has_unblockable_effect
Definition: neighboring8Direct.h:21
osl::getPtype
Ptype getPtype(PtypeO ptypeO)
Definition: basic_type.h:217
osl::PtypeTable::hasLongMove
bool hasLongMove(Ptype ptype) const
遅くて良い?
Definition: ptypeTable.h:54
osl::effect_util::Neighboring8Direct::Table::Entry
Definition: neighboring8Direct.h:20
osl::effect_util::Neighboring8Direct::hasEffectFromTo
static bool hasEffectFromTo(const NumEffectState &state, PtypeO ptypeo, Square from, Square target, Direction d)
Definition: neighboring8Direct.cc:92
osl::BoardTable::getLongDirection
Direction getLongDirection(Offset32 offset32) const
Definition: boardTable.h:71
osl::getOwner
Player getOwner(PtypeO ptypeO)
Definition: basic_type.h:256
osl::Offset
座標の差分
Definition: basic_type.h:430
osl::effect_util::Neighboring8Direct::Table::hasEffect
bool hasEffect(const NumEffectState &state, PtypeO ptypeo, Square from, Square target) const
Definition: neighboring8Direct.h:31
osl::effect_util::Neighboring8Direct::Table::Entry::nearest
Offset nearest
Definition: neighboring8Direct.h:22
osl::Ptype_Table
const PtypeTable Ptype_Table
Definition: tables.cc:97
osl::Piece
駒.
Definition: basic_type.h:788
osl::Offset::zero
bool zero() const
Definition: basic_type.h:502
osl::effect_util::Neighboring8Direct::hasEffectNaive
static bool hasEffectNaive(const NumEffectState &state, PtypeO ptypeo, Square from, Square target)
Definition: neighboring8Direct.cc:101
osl::effect_util::Neighboring8Direct::Table::hasEffectOrAdditional
bool hasEffectOrAdditional(const NumEffectState &state, PtypeO ptypeo, Square from, Square target) const
Definition: neighboring8Direct.h:51
osl::NumEffectState::hasEffectByPiece
bool hasEffectByPiece(Piece attack, Square target) const
駒attack が target に利きを持つか (旧hasEffectToと統合)
Definition: numEffectState.h:450
osl::NumEffectState::kingMobilityOfPlayer
Square kingMobilityOfPlayer(Player p, Direction d) const
玉がd方向にどこまで動けるかを返す
Definition: numEffectState.h:192
osl::Offset32Base
差が uniqになるような座標の差分.
Definition: offset32.h:17
osl::effect_util::Neighboring8Direct::Table::table
CArray2d< Entry, PTYPEO_SIZE, Offset32::SIZE > table
Definition: neighboring8Direct.h:27
osl::effect_util::Neighboring8Direct::Table::init
void init(Player)
Definition: neighboring8Direct.cc:22
osl::effect_util::Neighboring8Direct::Table::findNearest
Square findNearest(const NumEffectState &state, PtypeO ptypeo, Square from, Square target) const
Definition: neighboring8Direct.h:85
osl::PtypeO
PtypeO
Player + Ptype [-15, 15] PtypeO の O は Owner の O.
Definition: basic_type.h:199
osl::NumEffectState
利きを持つ局面
Definition: numEffectState.h:34
osl::Direction
Direction
Definition: basic_type.h:310
osl::Square::isEdge
bool isEdge() const
onBoardから8近傍のオフセットを足した点がedgeかどうかの判定 そこそこ速くなった.
Definition: basic_type.h:591
osl::SimpleState::isEmptyBetween
bool isEmptyBetween(Square from, Square to, Offset offset, bool pieceExistsAtTo=false) const
Definition: simpleState.h:267
osl::SimpleState::kingSquare
Square kingSquare() const
Definition: simpleState.h:94
osl::effect_util::Neighboring8Direct::table
static Table table
Definition: neighboring8Direct.h:103
osl::longToShort
constexpr Direction longToShort(Direction d)
Definition: basic_type.h:380
osl::Offset32Base::index
unsigned int index() const
Definition: offset32.h:40
osl::BoardTable::getShortOffset
const Offset getShortOffset(Offset32 offset32) const
Longの利きの可能性のあるoffsetの場合は, 反復に使う offsetを Shortの利きのoffsetの場合はそれ自身を返す.
Definition: boardTable.h:110
osl::Piece::isEmpty
bool isEmpty() const
Definition: basic_type.h:913
osl::ptypeOIndex
unsigned int ptypeOIndex(PtypeO ptypeo)
Definition: basic_type.h:205
osl::effect_util::Neighboring8Direct::hasEffect
static bool hasEffect(const NumEffectState &state, PtypeO ptypeo, Square from, Square target)
ptypeo の駒がfromからtargetの8近傍に直接の利きを持つか
Definition: neighboring8Direct.h:108
osl::Player
Player
Definition: basic_type.h:8
numEffectState.h
osl::effect_util::Neighboring8Direct::hasEffectOrAdditional
static bool hasEffectOrAdditional(const NumEffectState &state, PtypeO ptypeo, Square from, Square target)
ptypeo の駒がfromからtargetの8近傍に直接の利きを持つか そのような駒への追加/影利きになっている
Definition: neighboring8Direct.h:118
osl::effect_util::Neighboring8Direct::init
static void init()
Definition: neighboring8Direct.cc:15
osl::Square::STAND
static const Square STAND()
Definition: basic_type.h:548
osl::CArray
Definition: container.h:20
osl
Definition: additionalEffect.h:6
osl::effect_util::Neighboring8Direct::Table
Definition: neighboring8Direct.h:18