My Project
std
osl
rating
feature
bigramAttack.h
Go to the documentation of this file.
1
/* bigramAttack.h
2
*/
3
#ifndef _BIGRAMATTACK_H
4
#define _BIGRAMATTACK_H
5
6
#include "
osl/rating/feature.h
"
7
8
namespace
osl
9
{
10
namespace
rating
11
{
12
class
BigramAttack
:
public
Feature
13
{
14
int
property
;
15
bool
same
,
focus_x
;
16
public
:
17
static
const
std::string
name
(
int
x1,
int
y1,
int
x2,
int
y2,
int
king_index,
bool
s,
bool
f);
18
BigramAttack
(
int
x1,
int
y1,
int
x2,
int
y2,
int
king_index,
bool
s,
bool
f)
19
:
Feature
(
name
(x1,y1,x2,y2,king_index,s,f)),
property
((((x1+2)*5+y1+2)*25 + (x2+2)*5+y2+2)*5 + king_index),
same
(s),
focus_x
(f)
20
{
21
}
22
// [0,4]
23
static
int
indexKing
(
Player
attack,
Square
king,
bool
focus_x
)
24
{
25
int
x =
focus_x
? king.
x
() : king.
y
();
26
if
(!
focus_x
&& attack ==
WHITE
)
27
x = 10 - x;
28
if
(x <= 3)
29
return
x-1;
30
if
(x >= 7)
31
return
x-5;
32
return
2;
33
}
34
static
int
indexOfMove
(
Square
king,
Move
move)
35
{
36
int
x_diff = move.
to
().
x
() - king.
x
();
37
if
(abs(x_diff) > 2)
38
return
-1;
39
x_diff += 2;
40
assert(x_diff >= 0 && x_diff <= 4);
41
int
y_diff = move.
to
().
y
() - king.
y
();
42
if
(abs(y_diff) > 2)
43
return
-1;
44
if
(move.
player
() ==
WHITE
)
45
y_diff = -y_diff;
46
y_diff += 2;
47
assert(y_diff >= 0 && y_diff <= 4);
48
return
x_diff * 5 + y_diff;
49
}
50
static
int
index
(
const
NumEffectState
& state,
Move
move,
const
RatingEnv
& env,
bool
same
,
bool
focus_x
)
51
{
52
if
(! env.
history
.
hasLastMove
(
same
+1))
53
return
-1;
54
const
Move
prev = env.
history
.
lastMove
(
same
+1);
55
if
(! prev.
isNormal
())
56
return
-1;
57
const
Square
king = state.
kingSquare
(
alt
(state.
turn
()));
58
const
int
index1 =
indexOfMove
(king, prev);
59
if
(index1 < 0)
60
return
-1;
61
const
int
index2 =
indexOfMove
(king, move);
62
if
(index2 < 0)
63
return
-1;
64
return
(index1 * 25 + index2) * 5 +
indexKing
(move.
player
(), king,
focus_x
);
65
}
66
bool
match
(
const
NumEffectState
& state,
Move
move,
const
RatingEnv
& env)
const
67
{
68
int
index
= this->
index
(state, move, env,
same
,
focus_x
);
69
return
index
==
property
;
70
}
71
};
72
}
73
}
74
75
#endif
/* _BIGRAMATTACK_H */
76
// ;;; Local Variables:
77
// ;;; mode:c++
78
// ;;; c-basic-offset:2
79
// ;;; End:
osl::Square
Definition:
basic_type.h:532
osl::rating::BigramAttack::indexKing
static int indexKing(Player attack, Square king, bool focus_x)
Definition:
bigramAttack.h:23
osl::WHITE
@ WHITE
Definition:
basic_type.h:10
osl::rating::BigramAttack::index
static int index(const NumEffectState &state, Move move, const RatingEnv &env, bool same, bool focus_x)
Definition:
bigramAttack.h:50
osl::alt
constexpr Player alt(Player player)
Definition:
basic_type.h:13
osl::Move
圧縮していない moveの表現 .
Definition:
basic_type.h:1052
osl::container::MoveStack::lastMove
const Move lastMove(size_t last=1) const
Definition:
moveStack.h:28
osl::rating::Feature::name
const std::string & name() const
Definition:
rating/feature.h:24
osl::rating::BigramAttack::indexOfMove
static int indexOfMove(Square king, Move move)
Definition:
bigramAttack.h:34
osl::rating::Feature
Definition:
rating/feature.h:15
osl::rating::RatingEnv
Definition:
ratingEnv.h:16
osl::rating::BigramAttack
Definition:
bigramAttack.h:13
osl::rating::RatingEnv::history
MoveStack history
Definition:
ratingEnv.h:18
osl::Move::isNormal
bool isNormal() const
INVALID でも PASS でもない.
Definition:
basic_type.h:1088
osl::Square::x
int x() const
将棋としてのX座標を返す.
Definition:
basic_type.h:563
osl::NumEffectState
利きを持つ局面
Definition:
numEffectState.h:34
osl::SimpleState::kingSquare
Square kingSquare() const
Definition:
simpleState.h:94
osl::Square::y
int y() const
将棋としてのY座標を返す.
Definition:
basic_type.h:567
osl::rating::BigramAttack::match
bool match(const NumEffectState &state, Move move, const RatingEnv &env) const
Definition:
bigramAttack.h:66
osl::SimpleState::turn
Player turn() const
Definition:
simpleState.h:220
osl::Player
Player
Definition:
basic_type.h:8
osl::rating::BigramAttack::focus_x
bool focus_x
Definition:
bigramAttack.h:15
osl::Move::to
const Square to() const
Definition:
basic_type.h:1132
osl::container::MoveStack::hasLastMove
bool hasLastMove(size_t last=1) const
Definition:
moveStack.h:27
osl::rating::BigramAttack::BigramAttack
BigramAttack(int x1, int y1, int x2, int y2, int king_index, bool s, bool f)
Definition:
bigramAttack.h:18
osl::rating::BigramAttack::property
int property
Definition:
bigramAttack.h:14
osl::rating::BigramAttack::same
bool same
Definition:
bigramAttack.h:15
osl::Move::player
Player player() const
Definition:
basic_type.h:1195
osl
Definition:
additionalEffect.h:6
feature.h
Generated by
1.8.18