All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
neighboring8Effect.cc
Go to the documentation of this file.
1 /* neighboring8.cc
2  */
4 
7 {
8  init(BLACK);
9  init(WHITE);
10 }
11 
13 Table::init(const Player player)
14 {
15  for (int p=PTYPE_PIECE_MIN; p<=PTYPE_MAX; ++p)
16  {
17  const Ptype ptype = static_cast<Ptype>(p);
18  assert(isPiece(ptype));
19  const PtypeO ptypeo = newPtypeO(player, ptype);
20  const int mask = Ptype_Table.getMoveMask(ptype);
21  for (int d=DIRECTION_MIN; d<=DIRECTION_MAX; ++d)
22  {
23  const Direction direction = static_cast<Direction>(d);
24  if (! (mask & (1<<direction)))
25  continue;
26  const Offset offset = Board_Table.getOffset(player, direction);
27  assert(! offset.zero());
28  const int x = offset.dx();
29  const int y = offset.dy();
30  for (int dy=-1; dy<=1; ++dy)
31  {
32  for (int dx=-1; dx<=1; ++dx)
33  {
34  const Offset32 offset32 = Offset32(x+dx, y+dy);
35  table[ptypeOIndex(ptypeo)][offset32.index()].
36  has_unblockable_effect = true;
37  }
38  }
39  if (isLong(direction))
40  {
41  assert(abs(x)<=1);
42  assert(abs(y)<=1);
43  for (int i=1; i<8; ++i)
44  {
45  const int long_x = x*i;
46  const int long_y = y*i;
47  const int target_x = x*(i+1);
48  const int target_y = y*(i+1);
49  const Offset32 offset32 = Offset32(target_x, target_y);
50  Entry& e = table[ptypeOIndex(ptypeo)][offset32.index()];
51  e.nearest = Offset(long_x, long_y);
52  }
53  for (int i=1; i<9; ++i)
54  {
55  const int long_x = x*i;
56  const int long_y = y*i;
57  for (int dy=-1; dy<=1; ++dy)
58  {
59  const int target_y = long_y+dy;
60  if ((target_y < -8) || (8 < target_y))
61  continue;
62  for (int dx=-1; dx<=1; ++dx)
63  {
64  const int target_x = long_x+dx;
65  if ((target_x < -8) || (8 < target_x))
66  continue;
67  const Offset32 offset32 = Offset32(target_x, target_y);
68  Entry& e = table[ptypeOIndex(ptypeo)][offset32.index()];
69  // 近いところ優先
70  if (e.nearest.zero())
71  {
72  e.nearest = Offset(long_x, long_y);
73  }
74  }
75  }
76  }
77  }
78  }
79  }
80 }
81 
83 hasEffectFromTo(const NumEffectState& state, PtypeO ptypeo, Square from,
85 {
86  target += Board_Table.getOffsetForBlack(d); // 8 近傍全て試すなら手番による符合変換は不要
87  return target.isOnBoard() && state.hasEffectIf(ptypeo, from, target);
88 }
89 
91 hasEffectNaive(const NumEffectState& state, PtypeO ptypeo, Square from,
92  Square target)
93 {
94  const Ptype ptype = getPtype(ptypeo);
95  if (! Ptype_Table.hasLongMove(ptype))
96  {
97  if (abs(from.y() - target.y()) > 3) // knight だけ3
98  return false;
99  if (abs(from.x() - target.x()) > 2)
100  return false;
101  }
102  else if (ptype == LANCE)
103  {
104  if (abs(from.x() - target.x()) > 1)
105  return false;
106  }
107 
108  // naive な実装
109  return hasEffectFromTo(state, ptypeo, from, target, UL)
110  || hasEffectFromTo(state, ptypeo, from, target, U)
111  || hasEffectFromTo(state, ptypeo, from, target, UR)
112  || hasEffectFromTo(state, ptypeo, from, target, L)
113  || hasEffectFromTo(state, ptypeo, from, target, R)
114  || hasEffectFromTo(state, ptypeo, from, target, DL)
115  || hasEffectFromTo(state, ptypeo, from, target, D)
116  || hasEffectFromTo(state, ptypeo, from, target, DR);
117 }
118 
119 // ;;; Local Variables:
120 // ;;; mode:c++
121 // ;;; c-basic-offset:2
122 // ;;; End: