piecePairWithStand.h
Go to the documentation of this file.
00001 /* piecePairWithStand.h
00002  */
00003 #ifndef EVAL_PPAIR_PIECEPAIRWITHSTAND_H
00004 #define EVAL_PPAIR_PIECEPAIRWITHSTAND_H
00005 
00006 #include "osl/eval/ppair/piecePairEval.h"
00007 #include "osl/eval/pieceEval.h"
00008 
00009 namespace osl
00010 {
00011   namespace eval
00012   {
00013     namespace ppair
00014     {
00022       template <class Table>
00023       class PiecePairWithStand
00024         : public PiecePairEval<PiecePairWithStand<Table>,Table>
00025       {
00026       public:
00027         static int standBonus(PtypeO ptypeo)
00028         {
00029           assert(isBasic(getPtype(ptypeo)));
00030           if (isMajorBasic(getPtype(ptypeo)))
00031             return Table::Piece_Value.value(newPtypeO(getOwner(ptypeo), PAWN));
00032           return 0;
00033         }
00034         static int standBonus(const SimpleState& state);
00035 
00036         typedef PiecePairEval<PiecePairWithStand<Table>, Table> base_t;
00037         explicit PiecePairWithStand(const SimpleState& state);
00038       protected:
00039         ~PiecePairWithStand() {}
00040       public:
00041         static int diffAfterDropMove(const SimpleState& state,Square to,PtypeO ptypeo)
00042         {
00043           const int bonus = standBonus(ptypeo);
00044           return base_t::diffAfterDropMove(state,to,ptypeo) - bonus;
00045         }
00046         static int diffAfterSimpleMove(const SimpleState& state,
00047                                        Square from, Square to, 
00048                                        int promote_mask)
00049         {
00050           int diff = base_t::diffAfterSimpleMove(state, from, to, promote_mask);
00051           if (promote_mask) {
00052             const Piece old_piece=state.pieceAt(from);
00053             const PtypeO newPtypeO = promoteWithMask(old_piece.ptypeO(), promote_mask);
00054             diff += Table::Piece_Value.promoteValue(newPtypeO);
00055           }
00056           return diff;
00057         }
00058         static int diffAfterCaptureMove(const SimpleState& state,
00059                                         Square from, Square to, 
00060                                         PtypeO victim,int promote_mask)
00061         {
00062           const PtypeO captured = osl::captured(victim);
00063           int bonus = standBonus(captured);
00064           if (promote_mask) {
00065             const Piece old_piece=state.pieceAt(from);
00066             const PtypeO newPtypeO = promoteWithMask(old_piece.ptypeO(), promote_mask);
00067             bonus += Table::Piece_Value.promoteValue(newPtypeO);
00068           }
00069           return base_t::diffAfterCaptureMove(state,from,to,victim,promote_mask) 
00070             + Table::Piece_Value.captureValue(victim) + bonus;
00071         }
00072         static int diffWithUpdate(const SimpleState& new_state, Move last_move)
00073         {
00074           int diff = base_t::diffWithUpdate(new_state, last_move);
00075           if (last_move.isDrop()) {
00076             const int bonus = standBonus(last_move.ptypeO());
00077             return diff - bonus;
00078           }
00079           if (last_move.isPromotion())
00080             diff += Table::Piece_Value.promoteValue(last_move.ptypeO());
00081           if (last_move.capturePtype() != PTYPE_EMPTY) {
00082             const PtypeO captured = last_move.capturePtypeO();
00083             const int bonus = standBonus(osl::captured(captured));
00084             diff += Table::Piece_Value.captureValue(captured) + bonus;
00085           }
00086           return diff;
00087         }
00088         static void setValues(const SimpleState&, container::PieceValues&);
00089       };
00090       
00091     } // namespace ppair
00092   } // namespace eval
00093 } // namespace osl
00094 
00095 
00096 #endif /* EVAL_PPAIR_PIECEPAIRWITHSTAND_H */
00097 // ;;; Local Variables:
00098 // ;;; mode:c++
00099 // ;;; c-basic-offset:2
00100 // ;;; End:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines