My Project
std
osl
effect_util
sendOffSquare.cc
Go to the documentation of this file.
1
/* sendOffSquare.cc
2
*/
3
#include "
osl/effect_util/sendOffSquare.h
"
4
#include "
osl/bits/ptypeTable.h
"
5
#include "
osl/oslConfig.h
"
6
7
osl::effect_util::SendOffSquare::Table
osl::effect_util::SendOffSquare::table
;
8
9
static
osl::SetUpRegister
_initializer
([](){
10
osl::effect_util::SendOffSquare::init
();
11
});
12
13
void
osl::effect_util::SendOffSquare::
14
Table::init
()
15
{
16
normal[0] =
Offset
( 1, 1);
17
normal[1] =
Offset
( 1, 0);
18
normal[2] =
Offset
( 1,-1);
19
normal[3] =
Offset
( 0, 1);
20
normal[4] =
Offset
( 0,-1);
21
normal[5] =
Offset
(-1, 1);
22
normal[6] =
Offset
(-1, 0);
23
normal[7] =
Offset
(-1,-1);
24
25
const
Square
center(5,5);
26
const
PtypeO
king =
newPtypeO
(
BLACK
,
KING
);
27
for
(
int
i=0; i<8; ++i)
28
{
29
const
Offset
king_square = normal[i];
30
for
(
int
j=0; j<8; ++j)
31
{
32
const
Offset
target = normal[j];
33
if
(i==j)
34
continue
;
35
const
int
dx = king_square.
dx
() - target.
dx
();
36
const
int
dy = king_square.
dy
() - target.
dy
();
37
const
EffectContent
effect
38
=
Ptype_Table
.
getEffect
(king,
Offset32
(dx, dy));
39
if
(! effect.
hasEffect
())
40
{
41
reverse[i].push_back(j);
42
}
43
}
44
}
45
46
for
(
int
i=0; i<256; ++i)
47
{
48
unsigned
int
val = i;
49
while
(val)
50
{
51
const
int
j = misc::BitOp::takeOneBit(val);
52
53
for
(
int
p: reverse[j])
54
{
55
if
(! reverse_all[i].isMember(p))
56
reverse_all[i].push_back(p);
57
}
58
}
59
}
60
}
61
62
template
<osl::Player Attack>
63
osl::effect_util::SendOffSquare::SendOff8
64
#if (defined __GNUC__) && (! defined GPSONE) && (! defined GPSUSIONE)
65
__attribute__ ((used))
66
#endif
67
osl::effect_util::
68
SendOffSquare::find
(
const
NumEffectState
& state,
Square
king_square,
69
Square8
& out)
70
{
71
assert(out.
empty
());
72
int
flags=0;
73
for
(
int
i=0; i<8; ++i)
74
{
75
testSquare<Attack>(state, king_square+table.normal[i], i, flags);
76
}
77
SendOff8
data = 0;
78
for
(
int
i: table.reverse_all[flags])
79
{
80
const
Square
candidate = king_square + table.normal[i];
81
if
(! state.
pieceAt
(candidate).
isEdge
()
82
&& state.
countEffect
(
alt
(Attack), candidate) == 1) {
83
out.
push_back
(candidate);
84
data |= (1<<i);
85
}
86
}
87
return
data;
88
}
89
90
void
osl::effect_util::
91
SendOffSquare::unpack
(
SendOff8
flags8,
Square
king_square,
92
Square8
& out)
93
{
94
assert(out.
empty
());
95
unsigned
int
flags = flags8;
96
while
(flags) {
97
const
int
i = misc::BitOp::takeOneBit(flags);
98
const
Square
candidate = king_square + table.normal[i];
99
out.
push_back
(candidate);
100
}
101
}
102
103
osl::effect_util::SendOffSquare::SendOff8
osl::effect_util::
104
SendOffSquare::find
(
Player
attack,
const
NumEffectState
& state,
105
Square
king_square,
106
Square8
& out)
107
{
108
if
(attack ==
BLACK
)
109
return
find<BLACK>(state, king_square, out);
110
else
111
return
find<WHITE>(state, king_square, out);
112
}
113
114
/* ------------------------------------------------------------------------- */
115
// ;;; Local Variables:
116
// ;;; mode:c++
117
// ;;; c-basic-offset:2
118
// ;;; End:
osl::EffectContent
Definition
effectContent.h:11
osl::EffectContent::hasEffect
bool hasEffect() const
短い利きがあるか,間がemptyなら長い利きがある
Definition
effectContent.h:34
osl::FixedCapacityVector::empty
bool empty() const
Definition
container.h:244
osl::NumEffectState
利きを持つ局面
Definition
numEffectState.h:34
osl::NumEffectState::countEffect
int countEffect(Player player, Square target) const
利きの数を数える.
Definition
numEffectState.h:266
osl::Offset32Base
差が uniqになるような座標の差分.
Definition
offset32.h:17
osl::Offset
座標の差分
Definition
basic_type.h:430
osl::Offset::dx
int dx() const
Offsetから一般に dxは求まらないので, ここでの入力は12近傍のみとする
Definition
basic_type.cc:119
osl::Offset::dy
int dy() const
Offsetから一般に dyは求まらないので, ここでの入力は12近傍のみとする
Definition
basic_type.cc:146
osl::Piece::isEdge
bool isEdge() const
Definition
basic_type.h:919
osl::PtypeTable::getEffect
const EffectContent getEffect(PtypeO ptypeo, Square from, Square to) const
fromにいるptypeoがtoに利きを持つか?
Definition
ptypeTable.h:112
osl::SimpleState::pieceAt
const Piece pieceAt(Square sq) const
Definition
simpleState.h:167
osl::Square
Definition
basic_type.h:532
osl::KING
@ KING
Definition
basic_type.h:93
osl::Ptype_Table
const PtypeTable Ptype_Table
Definition
tables.cc:97
osl::Player
Player
Definition
basic_type.h:8
osl::BLACK
@ BLACK
Definition
basic_type.h:9
osl::PtypeO
PtypeO
Player + Ptype [-15, 15] PtypeO の O は Owner の O.
Definition
basic_type.h:199
osl::alt
constexpr Player alt(Player player)
Definition
basic_type.h:13
osl::newPtypeO
PtypeO newPtypeO(Player player, Ptype ptype)
Definition
basic_type.h:211
oslConfig.h
ptypeTable.h
_initializer
static osl::SetUpRegister _initializer([](){ osl::effect_util::SendOffSquare::init();})
sendOffSquare.h
osl::SetUpRegister
Definition
oslConfig.h:128
osl::container::Square8
Definition
square8.h:16
osl::container::Square8::push_back
void push_back(Square position)
Definition
square8.h:18
osl::effect_util::SendOffSquare::Table
Definition
sendOffSquare.h:37
osl::effect_util::SendOffSquare::Table::init
void init()
Definition
sendOffSquare.cc:14
osl::effect_util::SendOffSquare::SendOff8
uint8_t SendOff8
Definition
sendOffSquare.h:18
osl::effect_util::SendOffSquare::init
static void init()
Definition
sendOffSquare.h:43
osl::effect_util::SendOffSquare::unpack
static void unpack(SendOff8, Square king, Square8 &out)
Definition
sendOffSquare.cc:91
osl::effect_util::SendOffSquare::find
static SendOff8 find(const NumEffectState &state, Square king_position, Square8 &out)
osl::effect_util::SendOffSquare::table
static Table table
Definition
sendOffSquare.h:45
Generated by
1.9.8