My Project
additionalEffect.cc
Go to the documentation of this file.
3
6 Player attack)
7{
8 PieceMask direct = state.effectSetAt(target) & state.piecesOnBoard(attack);
9 PieceMask mask;
10 mask.setAll();
11 mask.clearBit<KNIGHT>();
12 direct &= (state.promotedPieces() | mask);
13
14 while (direct.any()) {
15 const int num = direct.takeOneBit();
16 const Square p = state.pieceOf(num).square();
17 const Direction d=Board_Table.getShort8<BLACK>(p,target);
18 const int num1=state.longEffectNumTable()[num][d];
19 if(!Piece::isEmptyNum(num1) && state.pieceOf(num1).owner()==attack) return true;
20 }
21 return false;
22}
23
24template <int count_max>
27 Player attack)
28{
29 PieceVector direct_pieces;
30 state.findEffect(attack, target, direct_pieces);
31 return AdditionalOrShadow::count<count_max>
32 (direct_pieces, state, target, attack);
33}
34
37 Player attack)
38{
39 return count<1>(state, target, attack);
40}
41
44 Player attack)
45{
46 return count<2>(state, target, attack);
47}
48
50AdditionalEffect::find(const NumEffectState& state, Square target,
51 const PieceVector& direct_effects,
52 PieceVector& black, PieceVector& white)
53{
54 for (Piece p: direct_effects)
55 {
56 const Square from = p.square();
57 const Offset32 diff32 = Offset32(from, target);
58 const Offset step = Board_Table.getShortOffsetNotKnight(diff32);
59 if (step.zero())
60 continue;
61 // 利きが8方向の場合
62 Piece candidate=state.nextPiece(from, step);
63 if (! candidate.isPiece())
64 continue;
65 const Offset32 diff_reverse = Offset32(target,candidate.square());
66 for (; candidate.isPiece();
67 candidate=state.nextPiece(candidate.square(), step))
68 {
69 const EffectContent effect
70 = Ptype_Table.getEffect(candidate.ptypeO(), diff_reverse);
71 if (! effect.hasEffect())
72 break;
73 if (candidate.owner() == BLACK)
74 black.push_back(candidate);
75 else
76 white.push_back(candidate);
77 }
78 }
79
80}
81
83AdditionalEffect::find(const NumEffectState& state, Square target,
84 PieceVector& black, PieceVector& white)
85{
86 PieceVector direct_pieces;
87 state.findEffect(BLACK, target, direct_pieces);
88 find(state, target, direct_pieces, black, white);
89
90 direct_pieces.clear();
91 state.findEffect(WHITE, target, direct_pieces);
92 find(state, target, direct_pieces, black, white);
93}
94
97 int& black, int& white)
98{
99 PieceVector black_pieces, white_pieces;
100 find(state, target, black_pieces, white_pieces);
101 black = black_pieces.size();
102 white = white_pieces.size();
103}
104
105// ;;; Local Variables:
106// ;;; mode:c++
107// ;;; c-basic-offset:2
108// ;;; End:
const Offset getShortOffsetNotKnight(Offset32 offset32) const
Longの利きの可能性のあるoffsetの場合は, 反復に使う offsetを Knight以外のShortの利きのoffsetの場合はそれ自身を返す.
Definition boardTable.h:119
Direction getShort8(Square from, Square to) const
Definition boardTable.h:147
bool hasEffect() const
短い利きがあるか,間がemptyなら長い利きがある
size_t size() const
Definition container.h:243
void push_back(const T &e)
Definition container.h:204
利きを持つ局面
const NumBitmapEffect effectSetAt(Square sq) const
const EffectedNumTable & longEffectNumTable() const
const PieceMask promotedPieces() const
void findEffect(Player P, Square target, PieceVector &out) const
target に利きのあるPieceをoutに格納する
const PieceMask & piecesOnBoard(Player p) const
差が uniqになるような座標の差分.
Definition offset32.h:17
座標の差分
Definition basic_type.h:430
bool zero() const
Definition basic_type.h:502
駒番号のビットセット.
Definition pieceMask.h:21
void clearBit()
unpromote(PTYPE) の駒のbit を消す
Definition pieceMask.h:74
bool any() const
Definition pieceMask.h:57
PtypeO ptypeO() const
Definition basic_type.h:824
const Square square() const
Definition basic_type.h:832
Player owner() const
Definition basic_type.h:963
bool isPiece() const
Definition basic_type.h:953
const EffectContent getEffect(PtypeO ptypeo, Square from, Square to) const
fromにいるptypeoがtoに利きを持つか?
Definition ptypeTable.h:112
Piece nextPiece(Square cur, Offset diff) const
diff方向にあるPiece を求める.
const Piece pieceOf(int num) const
Definition simpleState.h:76
unsigned int square
Definition basic_type.h:533
@ KNIGHT
Definition basic_type.h:97
const PtypeTable Ptype_Table
Definition tables.cc:97
const BoardTable Board_Table
Definition tables.cc:95
Direction
Definition basic_type.h:310
Player
Definition basic_type.h:8
@ WHITE
Definition basic_type.h:10
@ BLACK
Definition basic_type.h:9
static bool hasEffectStable(const NumEffectState &, Square target, Player attack)
static int count(const NumEffectState &, Square target, Player attack)
static void find(const NumEffectState &, Square target, const PieceVector &direct_effects, PieceVector &black, PieceVector &white)
static bool hasEffect(const NumEffectState &, Square target, Player attack)
target に attack の追加利きが一つでもあるか. 相手の影利きが先にある場合は対象としない.
static int count2(const NumEffectState &, Square target, Player attack)
target に attack の追加利きを二つまで数える.