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 #include "osl/neighboring8.h"
00009 namespace osl
00010 {
00011 namespace rating
00012 {
00013 class Karanari : public Feature
00014 {
00015 bool bishop, can_promote_area;
00016 public:
00017 Karanari(bool b, bool c) : Feature(b ? "Bishop" : "Rook"), bishop(b), can_promote_area(c) {}
00018 static bool matchGeneral(const NumEffectState& state, Move move)
00019 {
00020 if (! (move.isPromote() && move.capturePtype() == PTYPE_EMPTY
00021 && move.from().canPromote(state.getTurn())))
00022 return false;
00023 const Position op_king = state.getKingPosition(alt(state.getTurn()));
00024 if (! Neighboring8Direct::hasEffect(state, move.oldPtypeO(), move.from(), op_king)
00025 && Neighboring8Direct::hasEffect(state, move.ptypeO(), move.to(), op_king))
00026 return false;
00027 return true;
00028 }
00029 bool match(const NumEffectState& state, Move move, const RatingEnv&) const
00030 {
00031 if (! (move.ptype() == (bishop ? PBISHOP : PROOK)
00032 && matchGeneral(state, move)))
00033 return false;
00034 if (can_promote_area)
00035 return move.to().canPromote(move.player());
00036 const Position my_king = state.getKingPosition(state.getTurn());
00037 if (bishop && Neighboring8::isNeighboring8(move.to(), my_king))
00038 return false;
00039 return true;
00040 }
00041 static int index(const NumEffectState& state, Move move)
00042 {
00043 int base;
00044 switch (move.ptype()) {
00045 case PBISHOP:
00046 base = 2;
00047 break;
00048 case PROOK:
00049 base = 0;
00050 break;
00051 default:
00052 return -1;
00053 }
00054 if (! matchGeneral(state, move))
00055 return -1;
00056 if (move.to().canPromote(move.player()))
00057 return base;
00058 const Position my_king = state.getKingPosition(state.getTurn());
00059 if ( base && Neighboring8::isNeighboring8(move.to(), my_king))
00060 return -1;
00061 return base + 1;
00062 }
00063 };
00064 }
00065 }
00066
00067 #endif
00068
00069
00070
00071