説明を見る。00001
00002
00003 #include "osl/rating/feature.h"
00004 #include "osl/simpleState.tcc"
00005 #include <sstream>
00006
00007 osl::rating::Feature::~Feature()
00008 {
00009 }
00010
00011 const osl::CArray<const char*,4> osl::rating::Check::check_property = {{ "Di", "DO", "OC", "Bo" }};
00012 osl::rating::Check::Check(int p) : Feature(check_property[p]), property(p)
00013 {
00014 }
00015
00016 bool osl::rating::Check::match(const NumEffectState& state, Move move, const RatingEnv&) const
00017 {
00018 if (property == 0 || property == 1) {
00019 if (! (state.isDirectCheck(move) && ! state.isOpenCheck(move)))
00020 return false;
00021 return property == openLong(state, move);
00022 }
00023 if (property == 2)
00024 return ! state.isDirectCheck(move) && state.isOpenCheck(move);
00025 return state.isDirectCheck(move) && state.isOpenCheck(move);
00026 }
00027
00028 const std::string osl::rating::
00029 Block::name(int self, int opponent)
00030 {
00031 std::ostringstream os;
00032 os << "B" << self << opponent;
00033 return os.str();
00034 }
00035
00036 const std::string osl::rating::Open::name(int property)
00037 {
00038 std::ostringstream os;
00039 os << "Open" << property / 4 << property % 4;
00040 return os.str();
00041 }
00042
00043 struct osl::rating::ImmediateAddSupport::Test
00044 {
00045 bool *result;
00046 const NumEffectState& state;
00047 Move move;
00048 Test(bool *r, const NumEffectState& s, Move m)
00049 : result(r), state(s), move(m)
00050 {
00051 }
00052 template <Player P>
00053 void doAction(Piece , Square last_attack)
00054 {
00055 const Piece attacked = state.pieceAt(last_attack);
00056 if (attacked.isOnBoardByOwner(state.turn())
00057 && state.hasEffectIf(move.ptypeO(), move.to(), last_attack))
00058 *result = true;
00059 }
00060 };
00061
00062 osl::rating::
00063 ImmediateAddSupport::ImmediateAddSupport(Ptype s, Ptype a)
00064 : Feature(std::string(Ptype_Table.getCsaName(s))+":"+Ptype_Table.getCsaName(a)),
00065 self(s), attack(a)
00066 {
00067 }
00068
00069 bool osl::rating::
00070 ImmediateAddSupport::match(const NumEffectState& state, Move move, const RatingEnv& env) const
00071 {
00072 if (move.ptype() != self)
00073 return false;
00074 const Move last_move=env.history.lastMove();
00075 if (! last_move.isNormal())
00076 return false;
00077 if (last_move.ptype() != attack)
00078 return false;
00079 const Square last_to = last_move.to();
00080 if (last_to==move.to())
00081 return false;
00082 bool result = false;
00083 Test action(&result, state, move);
00084 state.forEachEffectOfPiece(state.pieceOnBoard(last_to), action);
00085 return result;
00086 }
00087
00088 int osl::rating::
00089 ImmediateAddSupport::index(const NumEffectState& state, Move move, const RatingEnv& env)
00090 {
00091 const Move last_move=env.history.lastMove();
00092 if (! last_move.isNormal())
00093 return -1;
00094 const Square last_to = last_move.to();
00095 if (last_to==move.to())
00096 return -1;
00097 bool result = false;
00098 const Piece last_piece = state.pieceOnBoard(last_to);
00099
00100 if (! Ptype_Table.hasLongMove(last_piece.ptype()))
00101 {
00102 Test action(&result, state, move);
00103 state.forEachEffectOfPiece(last_piece, action);
00104 }
00105 else
00106 {
00107 const Player Turn = state.turn();
00108 PieceMask pieces = state.piecesOnBoard(Turn) & state.effectedMask(alt(Turn));
00109 mask_t m = pieces.getMask(0);
00110 while (m.any()) {
00111 const Piece p = state.pieceOf(m.takeOneBit());
00112 if (state.hasEffectByPiece(last_piece, p.square())
00113 && state.hasEffectIf(move.ptypeO(), move.to(), p.square())) {
00114 result = true;
00115 break;
00116 }
00117 }
00118 #if OSL_WORDSIZE == 32
00119 if (! result) {
00120 m = pieces.getMask(1);
00121 while (m.any()) {
00122 const Piece p = state.pieceOf(m.takeOneBit()+32);
00123 if (state.hasEffectByPiece(last_piece, p.square())
00124 && state.hasEffectIf(move.ptypeO(), move.to(), p.square())) {
00125 result = true;
00126 break;
00127 }
00128 }
00129 }
00130 #endif
00131 }
00132 if (! result)
00133 return -1;
00134 return (move.ptype() - PTYPE_PIECE_MIN) * (PTYPE_MAX+1 - PTYPE_PIECE_MIN)
00135 + last_move.ptype() - PTYPE_PIECE_MIN;
00136 }
00137
00138 const std::string osl::rating::Chase::name(Ptype self, Ptype target, bool drop, OpponentType opponent_type)
00139 {
00140 return std::string(Ptype_Table.getCsaName(self))
00141 +(drop ? "d" : "m")+">"+Ptype_Table.getCsaName(target)
00142 +(opponent_type == CAPTURE ? "c" : (opponent_type == DROP ? "d" : "e"));
00143 }
00144
00145
00146
00147
00148
00149