sendOffSquare.cc
Go to the documentation of this file.
1 /* sendOffSquare.cc
2  */
4 #include "osl/bits/ptypeTable.h"
5 #include "osl/oslConfig.h"
6 
8 
11 });
12 
15 {
16  normal[0] = Offset( 1, 1);
17  normal[1] = Offset( 1, 0);
18  normal[2] = Offset( 1,-1);
19  normal[3] = Offset( 0, 1);
20  normal[4] = Offset( 0,-1);
21  normal[5] = Offset(-1, 1);
22  normal[6] = Offset(-1, 0);
23  normal[7] = Offset(-1,-1);
24 
25  const Square center(5,5);
26  const PtypeO king = newPtypeO(BLACK, KING);
27  for (int i=0; i<8; ++i)
28  {
29  const Offset king_square = normal[i];
30  for (int j=0; j<8; ++j)
31  {
32  const Offset target = normal[j];
33  if (i==j)
34  continue;
35  const int dx = king_square.dx() - target.dx();
36  const int dy = king_square.dy() - target.dy();
37  const EffectContent effect
38  = Ptype_Table.getEffect(king, Offset32(dx, dy));
39  if (! effect.hasEffect())
40  {
41  reverse[i].push_back(j);
42  }
43  }
44  }
45 
46  for (int i=0; i<256; ++i)
47  {
48  unsigned int val = i;
49  while (val)
50  {
51  const int j = misc::BitOp::takeOneBit(val);
52 
53  for (int p: reverse[j])
54  {
55  if (! reverse_all[i].isMember(p))
56  reverse_all[i].push_back(p);
57  }
58  }
59  }
60 }
61 
62 template <osl::Player Attack>
64 #if (defined __GNUC__) && (! defined GPSONE) && (! defined GPSUSIONE)
65 __attribute__ ((used))
66 #endif
68 SendOffSquare::find(const NumEffectState& state, Square king_square,
69  Square8& out)
70 {
71  assert(out.empty());
72  int flags=0;
73  for (int i=0; i<8; ++i)
74  {
75  testSquare<Attack>(state, king_square+table.normal[i], i, flags);
76  }
77  SendOff8 data = 0;
78  for (int i: table.reverse_all[flags])
79  {
80  const Square candidate = king_square + table.normal[i];
81  if (! state.pieceAt(candidate).isEdge()
82  && state.countEffect(alt(Attack), candidate) == 1) {
83  out.push_back(candidate);
84  data |= (1<<i);
85  }
86  }
87  return data;
88 }
89 
92  Square8& out)
93 {
94  assert(out.empty());
95  unsigned int flags = flags8;
96  while (flags) {
97  const int i = misc::BitOp::takeOneBit(flags);
98  const Square candidate = king_square + table.normal[i];
99  out.push_back(candidate);
100  }
101 }
102 
105  Square king_square,
106  Square8& out)
107 {
108  if (attack == BLACK)
109  return find<BLACK>(state, king_square, out);
110  else
111  return find<WHITE>(state, king_square, out);
112 }
113 
114 /* ------------------------------------------------------------------------- */
115 // ;;; Local Variables:
116 // ;;; mode:c++
117 // ;;; c-basic-offset:2
118 // ;;; End:
int countEffect(Player player, Square target) const
利きの数を数える.
constexpr Player alt(Player player)
Definition: basic_type.h:13
const PtypeO PTYPEO_EDGE __attribute__((unused))
座標の差分
Definition: basic_type.h:429
bool hasEffect() const
短い利きがあるか,間がemptyなら長い利きがある
Definition: effectContent.h:34
const Piece pieceAt(Square sq) const
Definition: simpleState.h:167
int dy() const
Offsetから一般に dyは求まらないので, ここでの入力は12近傍のみとする
Definition: basic_type.cc:146
Offset32Base< 8, 9 > Offset32
Definition: offset32.h:63
PtypeO newPtypeO(Player player, Ptype ptype)
Definition: basic_type.h:211
void push_back(Square position)
Definition: square8.h:18
const PtypeTable Ptype_Table
Definition: tables.cc:97
static osl::SetUpRegister _initializer([](){ osl::effect_util::SendOffSquare::init();})
static SendOff8 find(const NumEffectState &state, Square king_position, Square8 &out)
const EffectContent getEffect(PtypeO ptypeo, Square from, Square to) const
fromにいるptypeoがtoに利きを持つか?
Definition: ptypeTable.h:112
bool isEdge() const
Definition: basic_type.h:919
利きを持つ局面
static void unpack(SendOff8, Square king, Square8 &out)
PtypeO
Player + Ptype [-15, 15] PtypeO の O は Owner の O.
Definition: basic_type.h:199
static int takeOneBit(Integer &mask)
Definition: mask.h:148
Player
Definition: basic_type.h:8
CArray< Offset8, 256 > reverse_all
Definition: sendOffSquare.h:40
int dx() const
Offsetから一般に dxは求まらないので, ここでの入力は12近傍のみとする
Definition: basic_type.cc:119