All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
trapRook.cc
Go to the documentation of this file.
1 /* trapRook.cc
2  */
4 
5 
6 template <osl::Player P>
7 template <osl::Direction Dir>
9 TrapRook<P>::testDirection(const NumEffectState& state, Square initial)
10 {
11  const Player Opponent = PlayerTraits<P>::opponent;
14  {
15  const Piece focus = state.pieceAt(p);
16  if (! focus.canMoveOn<Opponent>())
17  break;
18 
19  if (! state.hasEffectAt<P>(p))
20  return false;
21  if (focus.isOnBoardByOwner<P>())
22  return true;
23  assert(focus.isEmpty());
24  }
25  return true;
26 }
27 
28 
29 template <osl::Player P>
31 TrapRook<P>::isMember(const NumEffectState& state,
32  Ptype ptype,Square from,Square to)
33 {
34  // 横に行けない、縦に成れない、飛車の一つ後ろに利きがある
35  // とりあえず歩で封じるものだけ
36  if (ptype != PAWN)
37  return false;
38  if (! from.isPieceStand())
39  return false;
40  if (! state.hasEffectAt<P>(to))
41  return false;
42  const Square back_position = to + DirectionPlayerTraits<D,P>::offset();
43  const Piece rook = state.pieceAt(back_position);
44  if (rook.ptypeO() != newPtypeO(alt(P), ROOK))
45  return false;
46  if (! testDirection<R>(state, back_position))
47  return false;
48  if (! testDirection<L>(state, back_position))
49  return false;
50 
51  const Player Opponent = PlayerTraits<P>::opponent;
52  for (Square p=back_position+DirectionPlayerTraits<D,P>::offset();;
53  p+=DirectionPlayerTraits<D,P>::offset())
54  {
55  const Piece focus = state.pieceAt(p);
56  if (! focus.canMoveOn<Opponent>())
57  break;
58 
59  if (focus.isOnBoardByOwner<P>())
60  return state.hasEffectAt<P>(p);
61  assert(focus.isEmpty());
62  if (state.hasEffectAt<P>(p))
63  continue;
64  if (p.canPromote<Opponent>())
65  return false;
66  }
67  return true;
68 }
69 namespace osl
70 {
71  namespace move_classifier
72  {
73  template struct TrapRook<BLACK>;
74  template struct TrapRook<WHITE>;
75  }
76 } // namespace osl
77 
78 /* ------------------------------------------------------------------------- */
79 // ;;; Local Variables:
80 // ;;; mode:c++
81 // ;;; c-basic-offset:2
82 // ;;; End: