All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
neighboring8Effect.h
Go to the documentation of this file.
1 /* neighboring8.h
2  */
3 #ifndef EFFECT_UTIL_NEIGHBORING8EFFECT_H
4 #define EFFECT_UTIL_NEIGHBORING8EFFECT_H
5 
7 #include "osl/direction.h"
8 
9 namespace osl
10 {
11  namespace effect_util
12  {
18  {
19  class Table
20  {
21  struct Entry
22  {
26  {
27  }
28  };
29  CArray2d<Entry,PTYPEO_SIZE,Offset32::SIZE> table;
30  void init(Player);
31 
32  template <int maxCount>
33  bool hasAtMaxPieceBetween(const NumEffectState& state,
34  Square from, Square target) const
35  {
36  assert(from.isOnBoard());
37  Offset offset=Board_Table.getShortOffset(Offset32(target, from));
38  assert(! offset.zero());
39  int count = 0;
40  for (Square pos=from+offset; pos != target; pos+=offset)
41  {
42  if (!state.pieceAt(pos).isEmpty())
43  {
44  count++;
45  if (count > maxCount) return false;
46  }
47  }
48  return true;
49  }
50 
51  public:
52  Table();
53 
54  bool hasEffect(const NumEffectState& state,
55  PtypeO ptypeo, Square from,
56  Square target) const
57  {
58  const Offset32 offset32 = Offset32(target, from);
59  const Entry& e = table[ptypeOIndex(ptypeo)][offset32.index()];
61  return true;
62  if (e.nearest.zero())
63  return false;
64  assert(Ptype_Table.hasLongMove(getPtype(ptypeo)));
65  const Square nearest = from+e.nearest;
66  if (! nearest.isOnBoard())
67  {
68  return false;
69  }
70  return hasAtMaxPieceBetween<1>(state, from, nearest);
71  }
72  };
73  static const Table table;
74  public:
78  static bool hasEffect(const NumEffectState& state,
79  PtypeO ptypeo, Square from,
80  Square target)
81  {
82  return table.hasEffect(state, ptypeo, from, target);
83  }
84  private:
85  static bool hasEffectFromTo(const NumEffectState& state,
86  PtypeO ptypeo, Square from,
88  public:
89  static bool hasEffectNaive(const NumEffectState& state,
90  PtypeO ptypeo, Square from,
91  Square target);
92  };
93 
94  } // namespace effect_util
95  using effect_util::Neighboring8Effect;
96 } // namespace osl
97 
98 #endif /* EFFECT_UTIL_NEIGHBORING8EFFECT_H */
99 // ;;; Local Variables:
100 // ;;; mode:c++
101 // ;;; c-basic-offset:2
102 // ;;; End: