My Project
king8Group.cc
Go to the documentation of this file.
1/* king8Group.cc
2 */
4#include <sstream>
5
7 : Group("AttackKing8")
8{
9 for (int attack=0; attack<3; ++attack) {
10 for (int defense=0; defense<3; ++defense) {
11 for (int s=PTYPE_PIECE_MIN; s<= PTYPE_MAX; ++s) {
12 for (int t=PTYPE_PIECE_MIN; t<= PTYPE_MAX; ++t) {
13 for (int p=0; p<8; ++p) // progress8
14 push_back(new AttackKing8(static_cast<Ptype>(s), static_cast<Ptype>(t), true, attack, defense));
15 for (int p=0; p<8; ++p) // progress8
16 push_back(new AttackKing8(static_cast<Ptype>(s), static_cast<Ptype>(t), false, attack, defense));
17 }
18 for (int p=0; p<8; ++p) // progress8
19 push_back(new AttackKing8(static_cast<Ptype>(s), PTYPE_EMPTY, true, attack, defense));
20 }
21 }
22 }
23}
24
26{
27 const Ptype self = move.ptype();
28 const Square position
29 = Neighboring8Direct::findNearest(state, move.ptypeO(), move.to(),
30 state.kingSquare(alt(state.turn())));
31 if (position.isPieceStand() || position == move.from())
32 return -1;
33 if (! move.isDrop() && state.hasEffectByPiece(state.pieceOnBoard(move.from()), position))
34 return -1;
35 const Piece p = state.pieceAt(position);
36 const Ptype target = p.ptype();
37 const int base = CountEffect2::index(state, position, env)
39
40 const int self_index = self - PTYPE_PIECE_MIN;
41
42 int index = base + self_index*((PTYPE_MAX+1 - PTYPE_PIECE_MIN)*2 +1);
43 if (!isPiece(target)) {
44 index += (PTYPE_MAX+1 - PTYPE_PIECE_MIN)*2;
45 }
46 else {
47 index += (target - PTYPE_PIECE_MIN)*2 + (p.owner() != move.player());
48 }
49
50 const int progress8 = env.progress.value()/2;
51 return index*8 + progress8;
52}
53
55 : Group("DefenseKing8")
56{
57 for (int danger=0; danger<=4; ++danger) {
58 for (int s=PTYPE_PIECE_MIN; s<= PTYPE_MAX; ++s) {
59 for (int p=0; p<8; ++p) // progress8
60 push_back(new DefenseKing8(static_cast<Ptype>(s), true, danger));
61 for (int p=0; p<8; ++p) // progress8
62 push_back(new DefenseKing8(static_cast<Ptype>(s), false, danger));
63 }
64 }
65}
66
68{
69 assert(env.attack_count_for_turn == DefenseKing8::count(state));
70 const int self_index = (move.ptype() - PTYPE_PIECE_MIN)*2;
71 int index;
72 if (DefenseKing8::matchDrop(state, move))
73 index = env.attack_count_for_turn*(PTYPE_MAX+1-PTYPE_PIECE_MIN)*2 + self_index;
74 else if (DefenseKing8::matchMove(state, move))
75 index = env.attack_count_for_turn*(PTYPE_MAX+1-PTYPE_PIECE_MIN)*2 + self_index + 1;
76 else
77 return -1;
78 const int progress8 = env.progress.value()/2;
79 return index*8 + progress8;
80}
81
82/* ------------------------------------------------------------------------- */
83// ;;; Local Variables:
84// ;;; mode:c++
85// ;;; c-basic-offset:2
86// ;;; End:
圧縮していない moveの表現 .
PtypeO ptypeO() const
移動後のPtype, i.e., 成る手だった場合成った後
Ptype ptype() const
Player player() const
bool isDrop() const
const Square to() const
const Square from() const
利きを持つ局面
bool hasEffectByPiece(Piece attack, Square target) const
駒attack が target に利きを持つか (旧hasEffectToと統合)
Ptype ptype() const
Definition basic_type.h:821
Player owner() const
Definition basic_type.h:963
const Piece pieceOnBoard(Square sq) const
Player turn() const
Square kingSquare() const
Definition simpleState.h:94
const Piece pieceAt(Square sq) const
bool isPieceStand() const
Definition basic_type.h:576
static Square findNearest(const NumEffectState &state, PtypeO ptypeo, Square from, Square target)
static bool matchDrop(const NumEffectState &state, Move move)
static bool matchMove(const NumEffectState &state, Move move)
static int count(const NumEffectState &state)
mutually exclusive set of features
Definition group.h:17
Ptype
駒の種類を4ビットでコード化する
Definition basic_type.h:84
@ PTYPE_PIECE_MIN
Definition basic_type.h:104
@ PTYPE_MAX
Definition basic_type.h:105
@ PTYPE_EMPTY
Definition basic_type.h:85
constexpr bool isPiece(Ptype ptype)
ptypeが空白やEDGEでないかのチェック
Definition basic_type.h:120
constexpr Player alt(Player player)
Definition basic_type.h:13
int findMatch(const NumEffectState &state, Move m, const RatingEnv &) const
Definition king8Group.cc:25
static int index(const NumEffectState &state, Square position, const RatingEnv &env)
int findMatch(const NumEffectState &state, Move m, const RatingEnv &) const
Definition king8Group.cc:67