trapRook.cc
Go to the documentation of this file.
00001 /* trapRook.cc
00002  */
00003 #include "osl/move_classifier/trapRook.h"
00004 
00005 
00006 template <osl::Player P>
00007 template <osl::Direction Dir>
00008 bool osl::move_classifier::
00009 TrapRook<P>::testDirection(const NumEffectState& state, Square initial)
00010 {
00011   const Player Opponent = PlayerTraits<P>::opponent;
00012   for (Square p=initial+DirectionPlayerTraits<Dir,P>::offset();; 
00013        p+=DirectionPlayerTraits<Dir,P>::offset())
00014   {
00015     const Piece focus = state.pieceAt(p);
00016     if (! focus.canMoveOn<Opponent>())
00017       break;
00018 
00019     if (! state.hasEffectAt<P>(p))
00020       return false;
00021     if (focus.isOnBoardByOwner<P>())
00022       return true;
00023     assert(focus.isEmpty());
00024   }
00025   return true;
00026 }
00027 
00028 
00029 template <osl::Player P>
00030 bool osl::move_classifier::
00031 TrapRook<P>::isMember(const NumEffectState& state, 
00032                       Ptype ptype,Square from,Square to)
00033 {
00034   // 横に行けない、縦に成れない、飛車の一つ後ろに利きがある
00035   // とりあえず歩で封じるものだけ
00036   if (ptype != PAWN)
00037     return false;
00038   if (! from.isPieceStand())
00039     return false;
00040   if (! state.hasEffectAt<P>(to))
00041     return false;
00042   const Square back_position = to + DirectionPlayerTraits<D,P>::offset();
00043   const Piece rook = state.pieceAt(back_position);
00044   if (rook.ptypeO() != newPtypeO(alt(P), ROOK))
00045     return false;  
00046   if (! testDirection<R>(state, back_position))
00047     return false;
00048   if (! testDirection<L>(state, back_position))
00049     return false;
00050 
00051   const Player Opponent = PlayerTraits<P>::opponent;
00052   for (Square p=back_position+DirectionPlayerTraits<D,P>::offset();;
00053        p+=DirectionPlayerTraits<D,P>::offset())
00054   {
00055     const Piece focus = state.pieceAt(p);
00056     if (! focus.canMoveOn<Opponent>())
00057       break;
00058 
00059     if (focus.isOnBoardByOwner<P>())
00060       return state.hasEffectAt<P>(p);
00061     assert(focus.isEmpty());
00062     if (state.hasEffectAt<P>(p))
00063       continue;
00064     if (p.canPromote<Opponent>())
00065       return false;
00066   }
00067   return true;
00068 }
00069 namespace osl
00070 {
00071   namespace move_classifier
00072   {
00073     template struct TrapRook<BLACK>;
00074     template struct TrapRook<WHITE>;
00075   }
00076 } // namespace osl
00077 
00078 /* ------------------------------------------------------------------------- */
00079 // ;;; Local Variables:
00080 // ;;; mode:c++
00081 // ;;; c-basic-offset:2
00082 // ;;; End:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines