oracleAdjust.h
Go to the documentation of this file.
00001 /* oracleAdjust.h
00002  */
00003 #ifndef _ORACLEADUST_H
00004 #define _ORACLEADUST_H
00005 
00006 #include "osl/state/numEffectState.h"
00007 
00008 namespace osl
00009 {
00010   namespace checkmate
00011   {
00012     struct OracleAdjust
00013     {
00014       static const Move attack(const NumEffectState& state, Move check_move) 
00015       {
00016         assert(check_move.isValid());
00017         if (! check_move.isDrop())
00018         {
00019           // capture
00020           {
00021             const Piece p=state.pieceOnBoard(check_move.to());
00022             if (p.isPtype<KING>())
00023               return Move();
00024             check_move=check_move.newCapture(p);
00025           }
00026 
00027           // from
00028           if (state.pieceOnBoard(check_move.from()).ptype() != check_move.oldPtype()
00029               && Ptype_Table.hasLongMove(check_move.ptype())) {
00030             Piece p;
00031             switch (unpromote(check_move.ptype())) {
00032             case ROOK:
00033             {
00034               mask_t m = state.allEffectAt<ROOK>(check_move.player(), check_move.to());
00035               while (m.any()) {
00036                 const int num = m.takeOneBit()+PtypeFuns<ROOK>::indexNum*32;
00037                 p = state.pieceOf(num);
00038                 if (Board_Table.getShortOffsetNotKnight(Offset32(check_move.to(), check_move.from()))
00039                     == Board_Table.getShortOffsetNotKnight(Offset32(check_move.to(), p.square())))
00040                   break;
00041               }
00042               break;
00043             }
00044             case BISHOP: 
00045             {
00046               mask_t m = state.allEffectAt<BISHOP>(check_move.player(), check_move.to());
00047               while (m.any()) {
00048                 const int num = m.takeOneBit()+PtypeFuns<BISHOP>::indexNum*32;
00049                 p = state.pieceOf(num);
00050                 if (Board_Table.getShortOffsetNotKnight(Offset32(check_move.to(), check_move.from()))
00051                     == Board_Table.getShortOffsetNotKnight(Offset32(check_move.to(), p.square())))
00052                   break;
00053               }
00054               break;
00055             }
00056             case LANCE:  p = state.findAttackAt<LANCE>(check_move.player(), check_move.to()); 
00057               break;
00058             default:
00059               assert(0);
00060             }
00061             if (p.isPiece()) {
00062               if (check_move.oldPtype() == p.ptype())
00063                 check_move=check_move.newFrom(p.square());
00064               else if (check_move.ptype() == p.ptype())
00065                 check_move = Move(p.square(), check_move.to(), check_move.ptype(), 
00066                                   check_move.capturePtype(), false, check_move.player());
00067               if (! state.isValidMoveByRule(check_move, false))
00068                 return Move();
00069             }
00070           }
00071         }
00072         if (! state.isAlmostValidMove<false>(check_move))
00073           return Move();
00074         return check_move;
00075       }
00076     };
00077   }
00078 }
00079 
00080 
00081 #endif /* _ORACLEADUST_H */
00082 // ;;; Local Variables:
00083 // ;;; mode:c++
00084 // ;;; c-basic-offset:2
00085 // ;;; End:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines