attackDefense.h
Go to the documentation of this file.
00001 
00004 #ifndef EVAL_ENDGAME_ATTACKtDEFENSE_H
00005 #define EVAL_ENDGAME_ATTACKtDEFENSE_H
00006 
00007 #include "osl/eval/endgame/attackKing.h"
00008 #include "osl/eval/endgame/defenseKing.h"
00009 #include "osl/eval/pieceEval.h"
00010 #include "osl/eval/evalTraits.h"
00011 #include "osl/misc/carray.h"
00012 
00013 namespace osl
00014 {
00015   namespace container
00016   {
00017     class PieceValues;
00018   } // namespace container
00019   namespace eval
00020   {
00021     namespace endgame
00022     {
00027       class AttackDefense
00028       {
00029         CArray<int,2> values;
00030         void reset() { values.fill(0); }
00031         void addValue(Player owner, int value)
00032         {
00033           values[playerToIndex(owner)] += value;
00034         }
00035         void addValue(Piece king_black, Piece king_white, Piece target)
00036         {
00037           assert(king_black.ptype() == KING);
00038           assert(king_white.ptype() == KING);
00039           assert(king_black.owner() == BLACK);
00040           assert(king_white.owner() == WHITE);
00041           addValue(target.owner(), valueOf(king_black, king_white, target));
00042         }
00043       public:
00044         explicit AttackDefense(const SimpleState&);
00045         void changeTurn() {}
00046         static bool initialized() { return true; }
00047 
00048         int value() const { return values[0] + values[1]; }
00049         int value(Player p) const { return values[playerToIndex(p)]; }
00050 
00051         void update(const SimpleState& new_state, Move last_move);
00052         
00053         int expect(const SimpleState& state, Move move) const;
00054       private:
00055         void updateKingMove(const SimpleState&, Square from, Square to);
00056         void updateKingMove(const SimpleState&, Square from, Square to,
00057                             Piece target);
00058       public:
00059         static int infty()
00060         {
00061           return PieceEval::infty()*2; // 2倍未満のボーナス
00062         }
00063 
00064         static int valueOf(Piece black_king, Piece white_king,
00065                            Piece target)
00066         {
00067           return valueOf(black_king, white_king,
00068                          target.ptypeO(), target.square());
00069         }
00070         static int valueOf(Piece black_king, Piece white_king,
00071                            PtypeO ptypeo, Square position)
00072         {
00073           assert(black_king.owner() == BLACK);
00074           assert(white_king.owner() == WHITE);
00075           
00076           const Player player = getOwner(ptypeo);
00077           const Piece my_king 
00078             = (player == BLACK) ? black_king : white_king;
00079           const Piece op_king 
00080             = (player == BLACK) ? white_king : black_king;
00081 
00082           const int attack = AttackKing::valueOf(op_king, ptypeo, position);
00083           const int defense = DefenseKing::valueOf(my_king, ptypeo, position);
00084 
00085           return max(player, attack, defense);
00086         }
00087         static void setValues(const SimpleState&, container::PieceValues&);
00088         static void resetWeights(const int *w);
00089       };
00090     } // namespace endgame
00091   } // namespace endgame
00092 } // namespace osl
00093 
00094 #endif /* EVAL_ENDGAME_ATTACKKING_H */
00095 // ;;; Local Variables:
00096 // ;;; mode:c++
00097 // ;;; c-basic-offset:2
00098 // ;;; End:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines