00001
00002
00003 #include "osl/rating/feature.h"
00004 #include "osl/state/simpleState.tcc"
00005 #include "osl/apply_move/applyMove.h"
00006 #include <sstream>
00007
00008 osl::rating::Feature::~Feature()
00009 {
00010 }
00011
00012 const osl::CArray<const char*,4> osl::rating::Check::check_property = {{ "Di", "DO", "OC", "Bo" }};
00013 osl::rating::Check::Check(int p) : Feature(check_property[p]), property(p)
00014 {
00015 }
00016
00017 bool osl::rating::Check::match(const NumEffectState& state, Move move, const RatingEnv&) const
00018 {
00019 using namespace osl::move_classifier;
00020 if (property == 0 || property == 1) {
00021 if (! (PlayerMoveAdaptor<osl::move_classifier::DirectCheck>::isMember(state, move)
00022 && ! ConditionAdaptor<osl::move_classifier::OpenCheck>::isMember(state, move)))
00023 return false;
00024 return property == openLong(state, move);
00025 }
00026 if (property == 2)
00027 return ! PlayerMoveAdaptor<osl::move_classifier::DirectCheck>::isMember(state, move)
00028 && ConditionAdaptor<osl::move_classifier::OpenCheck>::isMember(state, move);
00029 return PlayerMoveAdaptor<osl::move_classifier::DirectCheck>::isMember(state, move)
00030 && ConditionAdaptor<osl::move_classifier::OpenCheck>::isMember(state, move);
00031 }
00032
00033 const std::string osl::rating::
00034 Block::name(int self, int opponent)
00035 {
00036 std::ostringstream os;
00037 os << "B" << self << opponent;
00038 return os.str();
00039 }
00040
00041 const std::string osl::rating::Open::name(int property)
00042 {
00043 std::ostringstream os;
00044 os << "Open" << property / 4 << property % 4;
00045 return os.str();
00046 }
00047
00048 struct osl::rating::ImmediateAddSupport::Test
00049 {
00050 bool *result;
00051 const NumEffectState& state;
00052 Move move;
00053 Test(bool *r, const NumEffectState& s, Move m)
00054 : result(r), state(s), move(m)
00055 {
00056 }
00057 template <Player P>
00058 void doAction(Piece , Position last_attack)
00059 {
00060 const Piece attacked = state.getPieceAt(last_attack);
00061 if (attacked.isOnBoardByOwner(state.getTurn())
00062 && state.hasEffectFromTo(move.ptypeO(), move.to(), last_attack))
00063 *result = true;
00064 }
00065 };
00066
00067 osl::rating::
00068 ImmediateAddSupport::ImmediateAddSupport(Ptype s, Ptype a)
00069 : Feature(std::string(Ptype_Table.getCsaName(s))+":"+Ptype_Table.getCsaName(a)),
00070 self(s), attack(a)
00071 {
00072 }
00073
00074 bool osl::rating::
00075 ImmediateAddSupport::match(const NumEffectState& state, Move move, const RatingEnv& env) const
00076 {
00077 if (move.ptype() != self)
00078 return false;
00079 const Move last_move=env.history.lastMove();
00080 if (! last_move.isNormal())
00081 return false;
00082 if (last_move.ptype() != attack)
00083 return false;
00084 const Position last_to = last_move.to();
00085 if (last_to==move.to())
00086 return false;
00087 bool result = false;
00088 Test action(&result, state, move);
00089 state.forEachEffectOfPiece(state.getPieceOnBoard(last_to), action);
00090 return result;
00091 }
00092
00093 int osl::rating::
00094 ImmediateAddSupport::index(const NumEffectState& state, Move move, const RatingEnv& env)
00095 {
00096 const Move last_move=env.history.lastMove();
00097 if (! last_move.isNormal())
00098 return -1;
00099 const Position last_to = last_move.to();
00100 if (last_to==move.to())
00101 return -1;
00102 bool result = false;
00103 Test action(&result, state, move);
00104 state.forEachEffectOfPiece(state.getPieceOnBoard(last_to), action);
00105 if (! result)
00106 return -1;
00107 return (move.ptype() - PTYPE_PIECE_MIN) * (PTYPE_MAX+1 - PTYPE_PIECE_MIN)
00108 + last_move.ptype() - PTYPE_PIECE_MIN;
00109 }
00110
00111 const std::string osl::rating::Chase::name(Ptype self, Ptype target, bool drop, OpponentType opponent_type)
00112 {
00113 return std::string(Ptype_Table.getCsaName(self))
00114 +(drop ? "d" : "m")+">"+Ptype_Table.getCsaName(target)
00115 +(opponent_type == CAPTURE ? "c" : (opponent_type == DROP ? "d" : "e"));
00116 }
00117
00118
00119
00120
00121
00122