00001
00002
00003
00004 #ifndef EVAL_ML_PIECESTAND_H
00005 #define EVAL_ML_PIECESTAND_H
00006
00007 #include "osl/eval/ml/weights.h"
00008 #include "osl/eval/ml/minorPiece.h"
00009 #include "osl/eval/ml/evalStagePair.h"
00010 #include "osl/ptype.h"
00011 #include "osl/misc/carray.h"
00012 #include "osl/state/numEffectState.h"
00013 #include "osl/checkmate/king8Info.h"
00014 #include "osl/container/tripleInt.h"
00015
00016 namespace osl
00017 {
00018 namespace eval
00019 {
00020 namespace ml
00021 {
00022 class PieceStand
00023 {
00024 static CArray<MultiInt, osl::Piece::SIZE> table;
00025 public:
00026 enum { DIM = osl::Piece::SIZE };
00027 PieceStand() { };
00028 static void setUp(const Weights &weights,int stage);
00029 static MultiInt eval(const NumEffectState &state);
00030 template<Player P>
00031 static MultiInt evalWithUpdate(const NumEffectState &state,
00032 Move moved, MultiInt last_value)
00033 {
00034 assert(moved.player()==P);
00035 osl::Ptype captured = moved.capturePtype();
00036 if (moved.isDrop())
00037 {
00038 const int count =
00039 state.countPiecesOnStand(P, moved.ptype()) + 1;
00040 const MultiInt value =
00041 table[Ptype_Table.getIndexMin(moved.ptype()) + count - 1];
00042 if(P==BLACK)
00043 return last_value - value;
00044 else
00045 return last_value + value;
00046 }
00047 else if (captured != PTYPE_EMPTY)
00048 {
00049 Ptype ptype = unpromote(captured);
00050 const int count = state.countPiecesOnStand(P, ptype);
00051 const MultiInt value = table[(Ptype_Table.getIndexMin(ptype) + count - 1)];
00052 if(P==BLACK)
00053 return last_value + value;
00054 else
00055 return last_value - value;
00056 }
00057 else
00058 return last_value;
00059 }
00060 };
00061
00062 class NonPawnPieceStand
00063 {
00064 static CArray<MultiInt, 21> table;
00065 public:
00066 enum { DIM = 21 };
00067 NonPawnPieceStand() { };
00068 static void setUp(const Weights &weights,int stage);
00069 static MultiInt eval(int black_count, int white_count);
00070 };
00071
00072 class NonPawnPieceStandCombination
00073 {
00074 friend class CanCheckNonPawnPieceStandCombination;
00075 public:
00076 enum { ONE_DIM = 5625, DIM = ONE_DIM * EvalStages};
00077 NonPawnPieceStandCombination() { };
00078 static void setUp(const Weights &weights);
00079 static MultiInt eval(const NumEffectState &state,
00080 const CArray<bool, 2> &can_check);
00081 static MultiInt evalWithUpdate(
00082 const NumEffectState &state,
00083 Move moved, const MultiInt &last_value,
00084 const CArray<bool, 2> &could_check,
00085 const CArray<bool, 2> &can_check);
00086 private:
00087 static MultiInt sumUp(const CArray<int, 6> &indices,
00088 const CArray<MultiInt, 5625> &values);
00089 static int index(int rook, int bishop, int gold, int silver,
00090 int knight, int lance)
00091 {
00092 return lance +
00093 5 * (knight + 5 * (silver + 5 * (gold + 5 * (3 * bishop + rook))));
00094 }
00095 static CArray<MultiInt, 5625> table;
00096 static CArray<MultiInt, 5625> check_table;
00097 };
00098
00099 class NonPawnPieceStandTurn
00100 {
00101 public:
00102 enum { ONE_DIM = 44, DIM = ONE_DIM * EvalStages };
00103 NonPawnPieceStandTurn() { };
00104 static void setUp(const Weights &weights);
00105 static void eval(const NumEffectState &state, MultiIntPair& out);
00106 template<Player P>
00107 static void evalWithUpdateBang(
00108 const NumEffectState &state,
00109 Move moved, MultiIntPair &last_value_and_out);
00110 private:
00111 static CArray<MultiInt, 44> table;
00112 static int index(Player player, Player turn, Ptype ptype, int count)
00113 {
00114 return Ptype_Table.getIndexMin(ptype) - 18 + count +
00115 (turn == player ? 22 : 0);
00116 }
00117 };
00118 class PieceStandY
00119 {
00120 private:
00121 static CArray<MultiInt, 360> y_attack_table;
00122 static CArray<MultiInt, 360> y_defense_table;
00123 static CArray<MultiInt, 9*7*19> y_attack_table_sum;
00124 static CArray<MultiInt, 9*7*19> y_defense_table_sum;
00125 static int index(Ptype ptype, Player player, Square king, int count)
00126 {
00127 const int king_y = (player == BLACK ? king.y() : 10 - king.y());
00128 return (king_y - 1) * 40 + Ptype_Table.getIndexMin(ptype) + count;
00129 }
00130 static int index(int i, Player player, Square king, int count)
00131 {
00132 const int king_y = (player == BLACK ? king.y() : 10 - king.y());
00133 return (king_y - 1) * 7*19 + i*19 + count;
00134 }
00135 static void updateResult(NumEffectState const& state, MultiInt &result,int i, Ptype ptype, CArray<Square,2> const&kings);
00136 public:
00137 enum { ONE_DIM = osl::Piece::SIZE * 9, DIM = ONE_DIM * 2*EvalStages };
00138 static void setUp(const Weights &weights);
00139 static MultiInt eval(const NumEffectState &state);
00140 template<Player P>
00141 static MultiInt evalWithUpdate(
00142 const NumEffectState &state, Move moved,
00143 const MultiInt &last_value);
00144 };
00145
00146 class CanCheckNonPawnPieceStandCombination
00147 {
00148 public:
00149 enum { ONE_DIM = 5625, DIM = ONE_DIM * EvalStages};
00150 static void setUp(const Weights &weights);
00151 template <Player Defense>
00152 static bool canCheck(const NumEffectState &state)
00153 {
00154 const Player Attack=PlayerTraits<Defense>::opponent;
00155 const King8Info king(state.Iking8Info(Defense));
00156 return (king.dropCandidate() != 0 ||
00157 king.hasMoveCandidate<Attack>(state) ||
00158 KnightCheck::canCheck<Defense>(state));
00159 }
00160 };
00161 class PieceStandCombinationBoth
00162 {
00163 public:
00164 enum { ONE_DIM = 16384, DIM = ONE_DIM * EvalStages };
00165 static void setUp(const Weights &weights);
00166 static MultiInt eval(const NumEffectState &state);
00167 private:
00168 static CArray<MultiInt, 16384> table;
00169 };
00170 }
00171 }
00172 }
00173 #endif // EVAL_ML_PIECESTAND_H
00174
00175
00176
00177