Go to the documentation of this file.00001
00002
00003
00004 #ifndef EVAL_ML_MOBILITY_H
00005 #define EVAL_ML_MOBILITY_H
00006
00007 #include "osl/eval/ml/weights.h"
00008 #include "osl/eval/ml/midgame.h"
00009 #include "osl/ptype.h"
00010 #include "osl/misc/carray.h"
00011 #include "osl/state/numEffectState.h"
00012 #include "osl/container/tripleInt.h"
00013
00014 namespace osl
00015 {
00016 namespace eval
00017 {
00018 namespace ml
00019 {
00020 class RookMobilityAll
00021 {
00022 friend class RookMobility;
00023 friend class RookMobilityX;
00024 friend class RookMobilityY;
00025 friend class RookMobilitySum;
00026 friend class RookMobilitySumKingX;
00027 friend class RookMobilityXKingX;
00028 public:
00029 template<int Sign>
00030 static void adjust(const NumEffectState&, bool promoted,
00031 int vertical, int horizontal,
00032 Square pos,
00033 MultiInt& value);
00034 static void eval(const NumEffectState&, MultiInt& out);
00035 private:
00036 static int indexX(Square rook, bool promoted,
00037 int count, bool vertical)
00038 {
00039 const int x = (rook.x() > 5 ?
00040 10 - rook.x() : rook.x());
00041 return x - 1 + 5 * ((promoted ? 1 : 0) +
00042 2 * ((vertical ? 1 : 0) + 2 * count));
00043 }
00044 template <int Sign>
00045 static int indexY(Square rook, bool promoted,
00046 int count, bool vertical)
00047 {
00048 const int y = (Sign > 0 ? rook.y() : 10 - rook.y());
00049 return y - 1 + 9 * ((promoted ? 1 : 0) +
00050 2 * ((vertical ? 1 : 0) + 2 * count));
00051 }
00052 template <int Sign>
00053 static int indexXKingX(Square rook, Square king, int count, bool vertical)
00054 {
00055 const Square r = (Sign > 0) ? rook : rook.rotate180();
00056 const Square k = (Sign > 0) ? king : king.rotate180();
00057 const bool flip = r.x() > 5;
00058 const int x = (flip ? 10 - r.x() : r.x());
00059 const int king_x = (flip ? 10 - k.x() : k.x());
00060 return king_x - 1 + 9 * (x - 1 + 5 * ((vertical ? 1 : 0) + 2 * count));
00061 }
00062 static CArray<MultiInt, 18> rook_vertical_table;
00063 static CArray<MultiInt, 18> rook_horizontal_table;
00064 static CArray<MultiInt, 34> sum_table;
00065 static CArray<MultiInt, 324> x_table;
00066 static CArray<MultiInt, 324> y_table;
00067 static CArray<MultiInt, 17 * 9> sumkingx_table;
00068 static CArray<MultiInt, 9 * 2 * 5 * 9> xkingx_table;
00069 };
00070
00071 class RookMobility
00072 {
00073 public:
00074 enum { DIM = 36 };
00075 static void setUp(const Weights &weights,int stage);
00076 };
00077
00078 class RookMobilitySum
00079 {
00080 public:
00081 enum { ONE_DIM = 34, DIM = ONE_DIM * EvalStages };
00082 static void setUp(const Weights &weights);
00083 };
00084 class RookMobilityX
00085 {
00086 public:
00087 enum { ONE_DIM = 180, DIM = ONE_DIM * EvalStages };
00088 static void setUp(const Weights &weights);
00089 };
00090 class RookMobilityY
00091 {
00092 public:
00093 enum { ONE_DIM = 324, DIM = ONE_DIM * EvalStages };
00094 static void setUp(const Weights &weights);
00095 };
00096 class RookMobilitySumKingX
00097 {
00098 public:
00099 enum { ONE_DIM = 17 * 9, DIM = ONE_DIM * EvalStages };
00100 static void setUp(const Weights &weights);
00101 };
00102 class RookMobilityXKingX
00103 {
00104 public:
00105 enum { ONE_DIM = 9 * 2 * 5 * 9, DIM = ONE_DIM * EvalStages };
00106 static void setUp(const Weights &weights);
00107 };
00108
00109 struct BishopMobilityAll
00110 {
00111 friend class BishopMobility;
00112 friend class BishopMobilityEach;
00113 public:
00114 template<int Sign>
00115 static void adjust(bool promoted, int mobility1, int mobility2,
00116 MultiInt& value);
00117 static void eval(const NumEffectState&, MultiInt& out);
00118 private:
00119 static CArray<MultiInt, 36> bishop_table;
00120 static CArray<MultiInt, 18> each_table;
00121 };
00122 class BishopMobility
00123 {
00124 public:
00125 enum { DIM = 36 };
00126 static void setUp(const Weights &weights,int stage);
00127 };
00128 class BishopMobilityEach
00129 {
00130 public:
00131 enum { ONE_DIM = 18, DIM = ONE_DIM * EvalStages };
00132 static void setUp(const Weights &weights);
00133 };
00134 struct LanceMobilityAll
00135 {
00136 template<int Sign>
00137 static void adjust(int index, MultiInt& value);
00138 static void eval(const NumEffectState&, MultiInt& out);
00139 };
00140 class LanceMobility
00141 {
00142 static CArray<MultiInt, 9> lance_table;
00143 friend struct LanceMobilityAll;
00144 public:
00145 enum { DIM = 9 };
00146 LanceMobility() { };
00147 static void setUp(const Weights &weights,int stage);
00148 };
00149 }
00150 }
00151 }
00152 #endif // EVAL_ML_MOBILITY_H
00153
00154
00155
00156