All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
additionalEffect.cc
Go to the documentation of this file.
5 #include <boost/foreach.hpp>
6 
8 AdditionalEffect::hasEffect(const NumEffectState& state, Square target,
9  Player attack)
10 {
11  PieceMask direct = state.effectSetAt(target) & state.piecesOnBoard(attack);
12  PieceMask mask;
13  mask.setAll();
14  mask.clearBit<KNIGHT>();
15  direct &= (state.promotedPieces() | mask);
16 
17  while (direct.any()) {
18  const int num = direct.takeOneBit();
19  const Square p = state.pieceOf(num).square();
21  const int num1=state.longEffectNumTable()[num][d];
22  if(!Piece::isEmptyNum(num1) && state.pieceOf(num1).owner()==attack) return true;
23  }
24  return false;
25 }
26 
27 template <int count_max>
29 AdditionalEffect::count(const NumEffectState& state, Square target,
30  Player attack)
31 {
32  PieceVector direct_pieces;
33  EffectUtil::findEffect(attack, state, target, direct_pieces);
34  return AdditionalOrShadow::count<count_max>
35  (direct_pieces, state, target, attack);
36 }
37 
39 AdditionalEffect::hasEffectStable(const NumEffectState& state, Square target,
40  Player attack)
41 {
42  return count<1>(state, target, attack);
43 }
44 
46 AdditionalEffect::count2(const NumEffectState& state, Square target,
47  Player attack)
48 {
49  return count<2>(state, target, attack);
50 }
51 
53 AdditionalEffect::find(const NumEffectState& state, Square target,
54  const PieceVector& direct_effects,
55  PieceVector& black, PieceVector& white)
56 {
57  BOOST_FOREACH(Piece p, direct_effects)
58  {
59  const Square from = p.square();
60  const Offset32 diff32 = Offset32(from, target);
61  const Offset step = Board_Table.getShortOffsetNotKnight(diff32);
62  if (step.zero())
63  continue;
64  // 利きが8方向の場合
65  Piece candidate=state.nextPiece(from, step);
66  if (! candidate.isPiece())
67  continue;
68  const Offset32 diff_reverse = Offset32(target,candidate.square());
69  for (; candidate.isPiece();
70  candidate=state.nextPiece(candidate.square(), step))
71  {
72  const EffectContent effect
73  = Ptype_Table.getEffect(candidate.ptypeO(), diff_reverse);
74  if (! effect.hasEffect())
75  break;
76  if (candidate.owner() == BLACK)
77  black.push_back(candidate);
78  else
79  white.push_back(candidate);
80  }
81  }
82 
83 }
84 
86 AdditionalEffect::find(const NumEffectState& state, Square target,
87  PieceVector& black, PieceVector& white)
88 {
89  PieceVector direct_pieces;
90  EffectUtil::findEffect(BLACK, state, target, direct_pieces);
91  find(state, target, direct_pieces, black, white);
92 
93  direct_pieces.clear();
94  EffectUtil::findEffect(WHITE, state, target, direct_pieces);
95  find(state, target, direct_pieces, black, white);
96 }
97 
99 AdditionalEffect::count(const NumEffectState& state, Square target,
100  int& black, int& white)
101 {
102  PieceVector black_pieces, white_pieces;
103  find(state, target, black_pieces, white_pieces);
104  black = black_pieces.size();
105  white = white_pieces.size();
106 }
107 
108 // ;;; Local Variables:
109 // ;;; mode:c++
110 // ;;; c-basic-offset:2
111 // ;;; End: