00001
00002
00003
00004 #ifndef EVAL_ML_KING8_H
00005 #define EVAL_ML_KING8_H
00006
00007 #include "osl/eval/weights.h"
00008 #include "osl/eval/evalStagePair.h"
00009 #include "osl/numEffectState.h"
00010 #include "osl/bits/king8Info.h"
00011
00012 namespace osl
00013 {
00014 namespace eval
00015 {
00016 namespace ml
00017 {
00018 class King8Effect
00019 {
00020 public:
00021 enum { DIM = 32 + 32 + 288 + 288 };
00022 static void setUp(const Weights &weights);
00023 static int eval(const NumEffectState &state);
00024 private:
00025 enum EffectState
00026 {
00027 NOT_EMPTY = -1,
00028 NO_EFFECT = 0,
00029 LESS_EFFECT,
00030 MORE_EFFECT,
00031 MORE_EFFECT_KING_ONLY
00032 };
00033 static CArray<int, 32> empty_table;
00034 static CArray<int, 32> defense_table;
00035 static CArray<int, 288> empty_y_table;
00036 static CArray<int, 288> defense_y_table;
00037 static int index(const Direction dir,
00038 EffectState state);
00039 static int indexY(Piece king,
00040 const Direction dir,
00041 EffectState state);
00042 static void effectState(const NumEffectState &state,
00043 const Player defense,
00044 const Direction dir,
00045 EffectState &empty,
00046 EffectState &);
00047 };
00048
00049
00050 class King8EffectBase
00051 {
00052 public:
00053 enum { DIM = 32 };
00054 typedef CArray<int, 32> table_t;
00055 enum EffectState
00056 {
00057 NOT_EMPTY = -1,
00058 NO_EFFECT = 0,
00059 LESS_EFFECT,
00060 MORE_EFFECT,
00061 MORE_EFFECT_KING_ONLY
00062 };
00063 template <class MakeEffectState>
00064 static const CArray<int,2> evalCommon(const NumEffectState &state, const table_t&);
00065 template <class MakeEffectState>
00066 static const CArray<int,2> evalWithUpdateCommon(const NumEffectState &new_state, Move last_move,
00067 const CArray<int,2>& last_value, const table_t&);
00068
00069 template <class MakeEffectState>
00070 static std::pair<CArray<int,2>, CArray<int,2> >
00071 evalWithUpdateCommon(const NumEffectState &new_state, Move last_move,
00072 const CArray<int,2>& last_value_opening, const CArray<int,2>& last_value_ending,
00073 const table_t&, const table_t&);
00074
00075 struct MakeEffectStateSimple;
00076 struct MakeEffectStateDefense;
00077 protected:
00078 static int index(const Direction dir, EffectState state)
00079 {
00080 return dir * 4 + state;
00081 }
00082 };
00083 class King8EffectEmptySquareBoth;
00084 template <bool Opening>
00085 class King8EffectEmptySquare : public King8EffectBase
00086 {
00087 friend class King8EffectEmptySquareBoth;
00088 static table_t table;
00089 public:
00090 static void setUp(const Weights &weights);
00091 static const CArray<int,2> eval(const NumEffectState &state);
00092 static const CArray<int,2> evalWithUpdate(const NumEffectState &new_state, Move last_move,
00093 const CArray<int,2>& last_value);
00094 };
00095
00096 class King8EffectEmptySquareBoth : public King8EffectBase
00097 {
00098 public:
00099 static std::pair<CArray<int,2>, CArray<int,2> >
00100 evalWithUpdate(const NumEffectState &new_state, Move last_move,
00101 const CArray<int,2>& last_value_opening,
00102 const CArray<int,2>& last_value_ending);
00103 };
00104 struct King8EffectEmptySquareOpening
00105 : public King8EffectEmptySquare<true>
00106 {
00107 };
00108 struct King8EffectEmptySquareEnding
00109 : public King8EffectEmptySquare<false>
00110 {
00111 };
00112
00113 class King8EffectDefenseSquareBoth;
00114 template <bool Opening>
00115 class King8EffectDefenseSquare
00116 : public King8EffectBase
00117 {
00118 friend class King8EffectDefenseSquareBoth;
00119 static CArray<int, 32> table;
00120 public:
00121 static void setUp(const Weights &weights);
00122 static const CArray<int,2> eval(const NumEffectState &state);
00123 static const CArray<int,2> evalWithUpdate(const NumEffectState &new_state, Move last_move,
00124 const CArray<int,2>& last_value);
00125 };
00126 class King8EffectDefenseSquareBoth : public King8EffectBase
00127 {
00128 public:
00129 static std::pair<CArray<int,2>, CArray<int,2> >
00130 evalWithUpdate(const NumEffectState &new_state, Move last_move,
00131 const CArray<int,2>& last_value_opening,
00132 const CArray<int,2>& last_value_ending);
00133 };
00134
00135 struct King8EffectDefenseSquareOpening
00136 : public King8EffectDefenseSquare<true>
00137 {
00138 };
00139 struct King8EffectDefenseSquareEnding
00140 : public King8EffectDefenseSquare<false>
00141 {
00142 };
00143
00144 class King8EffectAll
00145 {
00146 public:
00147 enum { ONE_DIM = 32, DIM = 32 * 5 * 2};
00148 private:
00149 static CArray<int, ONE_DIM> base_table;
00150 static CArray<int, ONE_DIM> u_table;
00151 static CArray<int, ONE_DIM> d_table;
00152 static CArray<int, ONE_DIM> l_table;
00153 static CArray<int, ONE_DIM> r_table;
00154 static CArray<int, ONE_DIM> base_defense_piece_table;
00155 static CArray<int, ONE_DIM> u_defense_piece_table;
00156 static CArray<int, ONE_DIM> d_defense_piece_table;
00157 static CArray<int, ONE_DIM> l_defense_piece_table;
00158 static CArray<int, ONE_DIM> r_defense_piece_table;
00159 public:
00160 enum EffectState
00161 {
00162 NOT_EMPTY = -1,
00163 NO_EFFECT = 0,
00164 LESS_EFFECT,
00165 MORE_EFFECT,
00166 MORE_EFFECT_KING_ONLY
00167 };
00168 static void setUp(const Weights &weights);
00169 King8EffectAll() { }
00170 static int eval(const NumEffectState &state,
00171 PieceMask black_mask, PieceMask white_mask);
00172 static void effectState(const NumEffectState &state,
00173 const Player defense,
00174 const Direction dir,
00175 EffectState &empty,
00176 EffectState &);
00177 static int index(const Direction dir, EffectState state);
00178 };
00179
00180 struct KingXBlockedBase
00181 {
00182 enum { DIM = 10 };
00183 typedef CArray<MultiInt, 10> table_t;
00184 static const MultiIntPair eval(const NumEffectState &state,
00185 const table_t& table);
00186 template <osl::Player P>
00187 static int index(Square king, int diff);
00188 template <osl::Player P>
00189 static bool isBlocked(const NumEffectState &state,
00190 int diff);
00191 #if 0
00192 static std::pair<CArray<int,2>,CArray<int,2> >
00193 evalWithUpdate(const NumEffectState &new_state, Move last_move,
00194 const CArray<int,2>& last_value_o,
00195 const CArray<int,2>& last_value_e,
00196 const table_t& table_o, const table_t& table_e);
00197 #endif
00198 };
00199 class KingXBlockedBoth;
00200
00201 class KingXBlocked : public KingXBlockedBase
00202 {
00203 friend class KingXBlockedBoth;
00204 friend class KingXBlockedYBase;
00205 public:
00206 static void setUp(const Weights &weights,int stage);
00207 static MultiIntPair eval(const NumEffectState &state)
00208 {
00209 return KingXBlockedBase::eval(state, table);
00210 }
00211 private:
00212 static table_t table;
00213 };
00214
00215 class KingXBlockedYBase
00216 {
00217 public:
00218 enum { DIM = 90 };
00219 typedef CArray<MultiInt, 90> table_t;
00220 static const MultiIntPair eval(const NumEffectState &state,
00221 const table_t& table);
00222 static void
00223 evalWithUpdateBang(const NumEffectState &state, Move laste_move,
00224 MultiIntPair &last_values_and_out);
00225 template <osl::Player P>
00226 static int index(Square king, int diff);
00227 private:
00228 template <int Sign>
00229 static void adjust(int index, int index_y, MultiInt &out);
00230 };
00231
00232 class KingXBlockedY : public KingXBlockedYBase
00233 {
00234 friend class KingXBlockedBoth;
00235 friend class KingXBlockedYBase;
00236 public:
00237 static void setUp(const Weights &weights,int stage);
00238 static const MultiIntPair eval(const NumEffectState &state)
00239 {
00240 return KingXBlockedYBase::eval(state, table);
00241 }
00242 private:
00243 static table_t table;
00244 };
00245
00246 class KingXBlockedBoth : public KingXBlockedBase
00247 {
00248 public:
00249 static void
00250 evalWithUpdateBang(const NumEffectState &new_state, Move last_move,
00251 MultiIntPair& last_values_and_out);
00252 };
00253
00254 class KingXBothBlocked
00255 {
00256 friend class KingXBlockedYBase;
00257 public:
00258 enum { ONE_DIM = 5, DIM = ONE_DIM * EvalStages };
00259 static void setUp(const Weights &weights);
00260 static MultiIntPair eval(const NumEffectState &state);
00261 private:
00262 static CArray<MultiInt, ONE_DIM> table;
00263 static int index(const Square king)
00264 {
00265 const int x = king.x();
00266 return (x > 5 ? 9 - x : x - 1);;
00267 }
00268 template <Player P>
00269 static int indexY(const Square king)
00270 {
00271 const int x = king.x();
00272 const int y = (P == BLACK ? king.y() : 10 - king.y());
00273 return (y - 1) * 5 + (x > 5 ? 9 - x : x - 1);
00274 }
00275 template <int Sign>
00276 static void adjust(int index, int index_y, MultiInt &out);
00277 };
00278
00279 class KingXBothBlockedY
00280 {
00281 friend class KingXBlockedYBase;
00282 friend class KingXBothBlocked;
00283 public:
00284 enum { ONE_DIM = 5 * 9, DIM = ONE_DIM * EvalStages };
00285 static void setUp(const Weights &weights);
00286 private:
00287 static CArray<MultiInt, ONE_DIM> table;
00288 };
00289
00290 class KingXBlocked3
00291 {
00292 friend class KingXBlocked3Y;
00293 public:
00294 enum { ONE_DIM = 80, DIM = ONE_DIM * EvalStages };
00295 static MultiInt eval(const NumEffectState &state);
00296 static void setUp(const Weights &weights);
00297 private:
00298 template <int Sign>
00299 static void adjust(int index_y, MultiInt &result)
00300 {
00301 if(Sign>0)
00302 result += y_table[index_y];
00303 else
00304 result -= y_table[index_y];
00305 }
00306 template <Player P>
00307 static int index(const Square king, bool is_l,
00308 bool u_blocked, bool opp_u_blocked, bool opp_blocked)
00309 {
00310 int x = king.x();
00311 if (x >= 6)
00312 {
00313 x = 10 - x;
00314 if (P == BLACK)
00315 {
00316 is_l = !is_l;
00317 }
00318 }
00319 else if (P == WHITE && x <= 4)
00320 {
00321 is_l = !is_l;
00322 }
00323 return x - 1 + 5 * ((is_l ? 1 : 0) + 2 * ((u_blocked ? 1 : 0) + 2 * ((opp_u_blocked ? 1 : 0) +2 * (opp_blocked ? 1 : 0))));
00324 }
00325 template <Player P>
00326 static int indexY(const Square king, bool is_l,
00327 bool u_blocked, bool opp_u_blocked,
00328 bool opp_blocked)
00329 {
00330 int x = king.x();
00331 const int y = (P == BLACK ? king.y() : 10 - king.y());
00332 if (x >= 6)
00333 {
00334 x = 10 - x;
00335 if (P == BLACK)
00336 {
00337 is_l = !is_l;
00338 }
00339 }
00340 else if (P == WHITE && x <= 4)
00341 {
00342 is_l = !is_l;
00343 }
00344 return x - 1 + 5 * (y - 1 + 9 * ((is_l ? 1 : 0) + 2 * ((u_blocked ? 1 : 0) + 2 * ((opp_u_blocked ? 1 : 0) + 2 * (opp_blocked ? 1 : 0)))));
00345 }
00346 static CArray<MultiInt, 80> table;
00347 static CArray<MultiInt, 720> y_table;
00348 };
00349
00350 class KingXBlocked3Y
00351 {
00352 public:
00353 enum { ONE_DIM = 720, DIM = ONE_DIM * EvalStages };
00354 static void setUp(const Weights &weights);
00355 };
00356
00357 class AnagumaEmpty
00358 {
00359 public:
00360 enum { DIM = 4 };
00361 static void setUp(const Weights &weights,int stage);
00362 static MultiInt eval(const NumEffectState &state);
00363 static int index(Square king, Square target);
00364 template <osl::Player Defense>
00365 static MultiInt evalOne(const NumEffectState &state);
00366 private:
00367 static CArray<MultiInt, 4> table;
00368 };
00369 }
00370 }
00371 }
00372
00373 #endif // EVAL_ML_KING8_H
00374
00375
00376
00377