My Project
eval/pieceStand.h
Go to the documentation of this file.
1 /* pieceStand.h
2  */
3 
4 #ifndef EVAL_ML_PIECESTAND_H
5 #define EVAL_ML_PIECESTAND_H
6 
7 #include "osl/eval/weights.h"
8 #include "osl/eval/minorPiece.h"
10 #include "osl/numEffectState.h"
11 #include "osl/bits/king8Info.h"
12 
13 namespace osl
14 {
15  namespace eval
16  {
17  namespace ml
18  {
19  class PieceStand
20  {
22  public:
23  enum { DIM = osl::Piece::SIZE };
24  PieceStand() { };
25  static void setUp(const Weights &weights,int stage);
26  static MultiInt eval(const NumEffectState &state);
27  template<Player P>
28  static MultiInt evalWithUpdate(const NumEffectState &state,
29  Move moved, MultiInt last_value)
30  {
31  assert(moved.player()==P);
33  if (moved.isDrop())
34  {
35  const int count =
36  state.countPiecesOnStand(P, moved.ptype()) + 1;
37  const MultiInt value =
38  table[Ptype_Table.getIndexMin(moved.ptype()) + count - 1];
39  if(P==BLACK)
40  return last_value - value;
41  else
42  return last_value + value;
43  }
44  else if (captured != PTYPE_EMPTY)
45  {
46  Ptype ptype = unpromote(captured);
47  const int count = state.countPiecesOnStand(P, ptype);
48  const MultiInt value = table[(Ptype_Table.getIndexMin(ptype) + count - 1)];
49  if(P==BLACK)
50  return last_value + value;
51  else
52  return last_value - value;
53  }
54  else
55  return last_value;
56  }
57  };
58 
60  {
62  public:
63  enum { DIM = 21 };
65  static void setUp(const Weights &weights,int stage);
66  static MultiInt eval(int black_count, int white_count);
67  };
68 
70  {
72  public:
73  enum { ONE_DIM = 5625, DIM = ONE_DIM * EvalStages};
75  static void setUp(const Weights &weights);
76  static MultiInt eval(const NumEffectState &state,
77  const CArray<bool, 2> &can_check);
78  static MultiInt evalWithUpdate(
79  const NumEffectState &state,
80  Move moved, const MultiInt &last_value,
81  const CArray<bool, 2> &could_check,
82  const CArray<bool, 2> &can_check);
83  private:
84  static MultiInt sumUp(const CArray<int, 6> &indices,
85  const CArray<MultiInt, 5625> &values);
86  static int index(int rook, int bishop, int gold, int silver,
87  int knight, int lance)
88  {
89  return lance +
90  5 * (knight + 5 * (silver + 5 * (gold + 5 * (3 * bishop + rook))));
91  }
94  };
95 
97  {
98  public:
99  enum { ONE_DIM = 44, DIM = ONE_DIM * EvalStages };
101  static void setUp(const Weights &weights);
102  static void eval(const NumEffectState &state, MultiIntPair& out);
103  template<Player P>
104  static void evalWithUpdateBang(
105  const NumEffectState &state,
106  Move moved, MultiIntPair &last_value_and_out);
107  private:
109  static int index(Player player, Player turn, Ptype ptype, int count)
110  {
111  return Ptype_Table.getIndexMin(ptype) - 18 + count +
112  (turn == player ? 22 : 0);
113  }
114  };
116  {
117  private:
122  static int index(Ptype ptype, Player player, Square king, int count)
123  {
124  const int king_y = (player == BLACK ? king.y() : 10 - king.y());
125  return (king_y - 1) * 40 + Ptype_Table.getIndexMin(ptype) + count;
126  }
127  static int index(int i, Player player, Square king, int count)
128  {
129  const int king_y = (player == BLACK ? king.y() : 10 - king.y());
130  return (king_y - 1) * 7*19 + i*19 + count;
131  }
132  static void updateResult(NumEffectState const& state, MultiInt &result,int i, Ptype ptype, CArray<Square,2> const&kings);
133  public:
135  static void setUp(const Weights &weights);
136  static MultiInt eval(const NumEffectState &state);
137  template<Player P>
139  const NumEffectState &state, Move moved,
140  const MultiInt &last_value);
141  };
142 
144  {
145  public:
146  enum { ONE_DIM = 5625, DIM = ONE_DIM * EvalStages};
147  static void setUp(const Weights &weights);
148  template <Player Defense>
149  static bool canCheck(const NumEffectState &state)
150  {
151  const Player Attack=alt(Defense);
152  const King8Info king(state.Iking8Info(Defense));
153  return (king.dropCandidate() != 0 ||
154  king.hasMoveCandidate<Attack>(state) ||
155  KnightCheck::canCheck<Defense>(state));
156  }
157  };
159  {
160  public:
161  enum { ONE_DIM = 16384, DIM = ONE_DIM * EvalStages };
162  static void setUp(const Weights &weights);
163  static MultiInt eval(const NumEffectState &state);
164  private:
166  };
167  }
168  }
169 }
170 #endif // EVAL_ML_PIECESTAND_H
171 // ;;; Local Variables:
172 // ;;; mode:c++
173 // ;;; c-basic-offset:2
174 // ;;; End:
圧縮していない moveの表現 .
Definition: basic_type.h:1052
Ptype ptype() const
Definition: basic_type.h:1155
Player player() const
Definition: basic_type.h:1195
bool isDrop() const
Definition: basic_type.h:1150
Ptype capturePtype() const
Definition: basic_type.h:1180
利きを持つ局面
uint64_t Iking8Info(Player king) const
static const int SIZE
Definition: basic_type.h:794
int getIndexMin(Ptype ptype) const
Definition: ptypeTable.h:88
int countPiecesOnStand(Player pl, Ptype ptype) const
持駒の枚数を数える
Definition: simpleState.h:182
int y() const
将棋としてのY座標を返す.
Definition: basic_type.h:567
敵玉の8近傍の状態を表す.
Definition: king8Info.h:29
unsigned int dropCandidate() const
0-7 bit 目を返す
Definition: king8Info.h:49
bool hasMoveCandidate(NumEffectState const &state) const
Definition: king8Info.h:128
static bool canCheck(const NumEffectState &state)
static void setUp(const Weights &weights)
static MultiInt sumUp(const CArray< int, 6 > &indices, const CArray< MultiInt, 5625 > &values)
static CArray< MultiInt, 5625 > check_table
static MultiInt eval(const NumEffectState &state, const CArray< bool, 2 > &can_check)
static CArray< MultiInt, 5625 > table
static MultiInt evalWithUpdate(const NumEffectState &state, Move moved, const MultiInt &last_value, const CArray< bool, 2 > &could_check, const CArray< bool, 2 > &can_check)
static int index(int rook, int bishop, int gold, int silver, int knight, int lance)
static int index(Player player, Player turn, Ptype ptype, int count)
static void setUp(const Weights &weights)
static CArray< MultiInt, 44 > table
static void evalWithUpdateBang(const NumEffectState &state, Move moved, MultiIntPair &last_value_and_out)
static void eval(const NumEffectState &state, MultiIntPair &out)
static void setUp(const Weights &weights, int stage)
static MultiInt eval(int black_count, int white_count)
static CArray< MultiInt, 21 > table
static MultiInt eval(const NumEffectState &state)
static void setUp(const Weights &weights)
static CArray< MultiInt, 16384 > table
static CArray< MultiInt, 360 > y_attack_table
static int index(Ptype ptype, Player player, Square king, int count)
static CArray< MultiInt, 9 *7 *19 > y_attack_table_sum
static int index(int i, Player player, Square king, int count)
static void updateResult(NumEffectState const &state, MultiInt &result, int i, Ptype ptype, CArray< Square, 2 > const &kings)
static MultiInt evalWithUpdate(const NumEffectState &state, Move moved, const MultiInt &last_value)
static MultiInt eval(const NumEffectState &state)
static CArray< MultiInt, 9 *7 *19 > y_defense_table_sum
static CArray< MultiInt, 360 > y_defense_table
static void setUp(const Weights &weights)
static MultiInt evalWithUpdate(const NumEffectState &state, Move moved, MultiInt last_value)
static CArray< MultiInt, osl::Piece::SIZE > table
static MultiInt eval(const NumEffectState &state)
static void setUp(const Weights &weights, int stage)
Ptype
駒の種類を4ビットでコード化する
Definition: basic_type.h:84
@ PTYPE_EMPTY
Definition: basic_type.h:85
const PtypeTable Ptype_Table
Definition: tables.cc:97
Ptype unpromote(Ptype ptype)
ptypeがpromote後の型の時に,promote前の型を返す. promoteしていない型の時はそのまま返す
Definition: basic_type.h:157
Player
Definition: basic_type.h:8
@ BLACK
Definition: basic_type.h:9
const int EvalStages
Definition: midgame.h:12
constexpr Player alt(Player player)
Definition: basic_type.h:13
PtypeO captured(PtypeO ptypeO)
unpromoteすると共に,ownerを反転する.
Definition: basic_type.h:264