説明を見る。00001
00002
00003 #ifndef _KARANARI_H
00004 #define _KARANARI_H
00005
00006 #include "osl/rating/feature.h"
00007 #include "osl/effect_util/neighboring8Direct.h"
00008 namespace osl
00009 {
00010 namespace rating
00011 {
00012 class Karanari : public Feature
00013 {
00014 bool bishop, can_promote_area;
00015 public:
00016 Karanari(bool b, bool c) : Feature(b ? "Bishop" : "Rook"), bishop(b), can_promote_area(c) {}
00017 static bool matchGeneral(const NumEffectState& state, Move move)
00018 {
00019 if (! (move.isPromotion() && move.capturePtype() == PTYPE_EMPTY
00020 && move.from().canPromote(state.turn())))
00021 return false;
00022 const Square op_king = state.kingSquare(alt(state.turn()));
00023 if (! Neighboring8Direct::hasEffect(state, move.oldPtypeO(), move.from(), op_king)
00024 && Neighboring8Direct::hasEffect(state, move.ptypeO(), move.to(), op_king))
00025 return false;
00026 return true;
00027 }
00028 bool match(const NumEffectState& state, Move move, const RatingEnv&) const
00029 {
00030 if (! (move.ptype() == (bishop ? PBISHOP : PROOK)
00031 && matchGeneral(state, move)))
00032 return false;
00033 if (can_promote_area)
00034 return move.to().canPromote(move.player());
00035 const Square my_king = state.kingSquare(state.turn());
00036 if (bishop && move.to().isNeighboring8(my_king))
00037 return false;
00038 return true;
00039 }
00040 static int index(const NumEffectState& state, Move move)
00041 {
00042 int base;
00043 switch (move.ptype()) {
00044 case PBISHOP:
00045 base = 2;
00046 break;
00047 case PROOK:
00048 base = 0;
00049 break;
00050 default:
00051 return -1;
00052 }
00053 if (! matchGeneral(state, move))
00054 return -1;
00055 if (move.to().canPromote(move.player()))
00056 return base;
00057 const Square my_king = state.kingSquare(state.turn());
00058 if ( base && move.to().isNeighboring8(my_king))
00059 return -1;
00060 return base + 1;
00061 }
00062 };
00063 }
00064 }
00065
00066 #endif
00067
00068
00069
00070