My Project
sendOffSquare.cc
Go to the documentation of this file.
1/* sendOffSquare.cc
2 */
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
62template <osl::Player Attack>
64#if (defined __GNUC__) && (! defined GPSONE) && (! defined GPSUSIONE)
65__attribute__ ((used))
66#endif
68SendOffSquare::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
91SendOffSquare::unpack(SendOff8 flags8, Square king_square,
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
104SendOffSquare::find(Player attack, const NumEffectState& state,
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:
bool hasEffect() const
短い利きがあるか,間がemptyなら長い利きがある
利きを持つ局面
int countEffect(Player player, Square target) const
利きの数を数える.
差が uniqになるような座標の差分.
Definition offset32.h:17
座標の差分
Definition basic_type.h:430
int dx() const
Offsetから一般に dxは求まらないので, ここでの入力は12近傍のみとする
int dy() const
Offsetから一般に dyは求まらないので, ここでの入力は12近傍のみとする
bool isEdge() const
Definition basic_type.h:919
const EffectContent getEffect(PtypeO ptypeo, Square from, Square to) const
fromにいるptypeoがtoに利きを持つか?
Definition ptypeTable.h:112
const Piece pieceAt(Square sq) const
@ KING
Definition basic_type.h:93
const PtypeTable Ptype_Table
Definition tables.cc:97
Player
Definition basic_type.h:8
@ BLACK
Definition basic_type.h:9
PtypeO
Player + Ptype [-15, 15] PtypeO の O は Owner の O.
Definition basic_type.h:199
constexpr Player alt(Player player)
Definition basic_type.h:13
PtypeO newPtypeO(Player player, Ptype ptype)
Definition basic_type.h:211
static osl::SetUpRegister _initializer([](){ osl::effect_util::SendOffSquare::init();})
void push_back(Square position)
Definition square8.h:18
static void unpack(SendOff8, Square king, Square8 &out)
static SendOff8 find(const NumEffectState &state, Square king_position, Square8 &out)