pin.h Source File

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
eval/ml/pin.h
Go to the documentation of this file.
1 /* pin.h
2 */
3
4 #ifndef EVAL_ML_PIN_H
5 #define EVAL_ML_PIN_H
6
7 #include "osl/ptype.h"
8 #include "osl/misc/carray.h"
9 #include "osl/state/numEffectState.h"
10 #include "osl/eval/ml/weights.h"
11 #include "osl/eval/ml/midgame.h"
12
13 namespace osl
14 {
15 namespace eval
16 {
17 namespace ml
18 {
19 class SimplePin
20 {
21 static CArray<int, PTYPE_SIZE> table;
22 public:
23 SimplePin() { };
24 static void setUp(const Weights &weights);
25 int eval(const NumEffectState &state,
26 PieceMask black_mask, PieceMask white_mask) const;
27 };
28
29 class Pin
30 {
31 static int index(const Square king,
32 const Piece piece)
33 {
34 return std::abs(piece.square().x() - king.x()) * 17 +
35 (piece.owner() == BLACK ? (king.y() - piece.square().y()) :
36 (piece.square().y() - king.y())) + 8;
37 }
38 static CArray2d<MultiInt, PTYPE_SIZE, 17 * 9> table;
39 public:
40 enum { DIM = (osl::PTYPE_MAX - osl::PTYPE_PIECE_MIN + 1) * 17 * 9};
41 Pin() { };
42 static void setUp(const Weights &weights,int stage);
43 static MultiInt eval(const NumEffectState &state,
44 PieceMask black_mask, PieceMask white_mask);
45 };
46
47 class PinPtypeAll
48 {
49 public:
50 static MultiInt eval(const NumEffectState &state);
51 private:
52 template <Player Defense>
53 static MultiInt evalOne(const NumEffectState &state);
54 template <Player Defense>
55 static bool pawnAttack(const NumEffectState &state, Piece piece)
56 {
57 const Square up =
58 piece.square() + DirectionPlayerTraits<U, Defense>::offset();
59 return (up.isOnBoard() &&
60 (state.hasEffectByPtypeStrict<PAWN>(alt(Defense), up)
61 || (!state.isPawnMaskSet(alt(Defense),
62 piece.square().x())
63 && state.pieceAt(up).isEmpty())));
64 }
65 protected:
66 static CArray<MultiInt, 80> table;
67 static CArray<MultiInt, 48> pawn_table;
68 static CArray<MultiInt, 560> distance_table;
69 };
70
71 class PinPtype : public PinPtypeAll
72 {
73 public:
74 enum { ONE_DIM = 80, DIM = ONE_DIM * EvalStages };
75 static void setUp(const Weights &weights);
76 };
77
78 class PinPtypeDistance : public PinPtypeAll
79 {
80 public:
81 enum { ONE_DIM = 560, DIM = ONE_DIM * EvalStages };
82 static void setUp(const Weights &weights);
83 };
84
85 class PinPtypePawnAttack : public PinPtypeAll
86 {
87 public:
88 enum { ONE_DIM = 48, DIM = ONE_DIM * EvalStages };
89 static void setUp(const Weights &weights);
90 };
91
92 class CheckShadowPtype
93 {
94 public:
95 enum {
96 // rook v, rook h, bishop u, bishop d, lance
97 ONE_DIM = PTYPE_SIZE * 5,
98 DIM = ONE_DIM * EvalStages
99 };
100 static void setUp(const Weights &weights);
101 static MultiInt eval(const NumEffectState &state);
102 template <Player King>
103 static MultiInt evalOne(const NumEffectState &state);
104 static CArray<MultiInt, ONE_DIM> table;
105 };
106 }
107 }
108 }
109 #endif // EVAL_ML_PIN_H
110 // ;;; Local Variables:
111 // ;;; mode:c++
112 // ;;; c-basic-offset:2
113 // ;;; End: