00001
00002
00003
00004 #ifndef EVAL_ML_PIN_H
00005 #define EVAL_ML_PIN_H
00006
00007 #include "osl/ptype.h"
00008 #include "osl/misc/carray.h"
00009 #include "osl/state/numEffectState.h"
00010 #include "osl/eval/ml/weights.h"
00011 #include "osl/eval/ml/midgame.h"
00012
00013 namespace osl
00014 {
00015 namespace eval
00016 {
00017 namespace ml
00018 {
00019 class SimplePin
00020 {
00021 static CArray<int, PTYPE_SIZE> table;
00022 public:
00023 SimplePin() { };
00024 static void setUp(const Weights &weights);
00025 int eval(const NumEffectState &state,
00026 PieceMask black_mask, PieceMask white_mask) const;
00027 };
00028
00029 class Pin
00030 {
00031 static int index(const Position king,
00032 const Piece piece)
00033 {
00034 return std::abs(piece.position().x() - king.x()) * 17 +
00035 (piece.owner() == BLACK ? (king.y() - piece.position().y()) :
00036 (piece.position().y() - king.y())) + 8;
00037 }
00038 static CArray2d<MultiInt, PTYPE_SIZE, 17 * 9> table;
00039 public:
00040 enum { DIM = (osl::PTYPE_MAX - osl::PTYPE_PIECE_MIN + 1) * 17 * 9};
00041 Pin() { };
00042 static void setUp(const Weights &weights,int stage);
00043 static MultiInt eval(const NumEffectState &state,
00044 PieceMask black_mask, PieceMask white_mask);
00045 };
00046
00047 class PinPtypeAll
00048 {
00049 public:
00050 static MultiInt eval(const NumEffectState &state);
00051 private:
00052 template <Player Defense>
00053 static MultiInt evalOne(const NumEffectState &state);
00054 template <Player Defense>
00055 static bool pawnAttack(const NumEffectState &state, Piece piece)
00056 {
00057 const Position up =
00058 piece.position() + DirectionPlayerTraits<U, Defense>::offset();
00059 return (up.isOnBoard() &&
00060 (state.hasEffectByPtypeStrict<PAWN>(
00061 PlayerTraits<Defense>::opponent,
00062 up) ||
00063 (!state.isPawnMaskSet(PlayerTraits<Defense>::opponent,
00064 piece.position().x()) &&
00065 state.getPieceAt(up).isEmpty())));
00066 }
00067 protected:
00068 static CArray<MultiInt, 80> table;
00069 static CArray<MultiInt, 48> pawn_table;
00070 static CArray<MultiInt, 560> distance_table;
00071 };
00072
00073 class PinPtype : public PinPtypeAll
00074 {
00075 public:
00076 enum { ONE_DIM = 80, DIM = ONE_DIM * EvalStages };
00077 static void setUp(const Weights &weights);
00078 };
00079
00080 class PinPtypeDistance : public PinPtypeAll
00081 {
00082 public:
00083 enum { ONE_DIM = 560, DIM = ONE_DIM * EvalStages };
00084 static void setUp(const Weights &weights);
00085 };
00086
00087 class PinPtypePawnAttack : public PinPtypeAll
00088 {
00089 public:
00090 enum { ONE_DIM = 48, DIM = ONE_DIM * EvalStages };
00091 static void setUp(const Weights &weights);
00092 };
00093 }
00094 }
00095 }
00096 #endif // EVAL_ML_PIN_H
00097
00098
00099
00100