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