説明を見る。00001
00002
00003 #ifndef _PINATTACK_H
00004 #define _PINATTACK_H
00005
00006 #include "osl/rating/feature.h"
00007 #include "osl/bits/ptypeTable.h"
00008
00009 namespace osl
00010 {
00011 namespace rating
00012 {
00013 class PinAttack : public Feature
00014 {
00015 bool attack;
00016 Ptype self, target;
00017 public:
00018 PinAttack(bool a, Ptype s, Ptype t)
00019 : Feature(name(a,s,t)),
00020 attack(a), self(s), target(t)
00021 {
00022 }
00023 bool match(const NumEffectState& state, Move move, const RatingEnv&, Piece p) const
00024 {
00025 if (target != p.ptype())
00026 return false;
00027 return state.hasEffectIf(move.ptypeO(), move.to(), p.square())
00028 && (move.isDrop()
00029 || ! state.hasEffectByPiece(state.pieceOnBoard(move.from()), p.square()));
00030 }
00031 bool match(const NumEffectState& state, Move move, const RatingEnv& env) const
00032 {
00033 if (self != move.ptype())
00034 return false;
00035 if (state.countEffect(alt(state.turn()), move.to(), env.op_pin) > 0)
00036 return false;
00037 PieceMask pins = (attack ? env.op_pin : env.my_pin);
00038 while (pins.any()) {
00039 const Piece p = state.pieceOf(pins.takeOneBit());
00040 if (match(state, move, env, p))
00041 return true;
00042 }
00043 return false;
00044 }
00045 static int index(const NumEffectState& state, Move move, const RatingEnv&, bool attack, Piece p)
00046 {
00047 if (! (state.hasEffectIf(move.ptypeO(), move.to(), p.square())
00048 && (move.isDrop()
00049 || ! state.hasEffectByPiece(state.pieceOnBoard(move.from()), p.square()))))
00050 return -1;
00051 int index = (move.ptype() - PTYPE_PIECE_MIN) * (PTYPE_MAX+1 - PTYPE_PIECE_MIN) + p.ptype() - PTYPE_PIECE_MIN;
00052 index *= 2;
00053 return attack ? index : index + 1;
00054 }
00055 static int index(const NumEffectState& state, Move move, const RatingEnv& env, bool attack)
00056 {
00057 if (state.countEffect(alt(state.turn()), move.to(), env.op_pin) > 0)
00058 return -1;
00059 PieceMask pins = (attack ? env.op_pin : env.my_pin);
00060 while (pins.any()) {
00061 const Piece p = state.pieceOf(pins.takeOneBit());
00062 const int i = index(state, move, env, attack, p);
00063 if (i >= 0)
00064 return i;
00065 }
00066 return -1;
00067 }
00068 static const std::string name(bool attack, Ptype self, Ptype target)
00069 {
00070 return std::string(Ptype_Table.getCsaName(self))+">"+Ptype_Table.getCsaName(target)+(attack ? "!" : "=");
00071 }
00072 };
00073
00074 class EscapePin : public Feature
00075 {
00076 Ptype pinned;
00077 public:
00078 explicit EscapePin(Ptype p) : Feature(Ptype_Table.getCsaName(p)), pinned(p) {}
00079 bool match(const NumEffectState&, Move move, const RatingEnv& env) const
00080 {
00081 if (move.ptype() != KING)
00082 return false;
00083 return (env.my_pin.getMask(Ptype_Table.getIndex(pinned))
00084 & Ptype_Table.getMaskLow(pinned)).any();
00085 }
00086 };
00087
00088 }
00089 }
00090
00091 #endif
00092
00093
00094
00095