My Project
core
osl
bits
ptypeTable.cc
Go to the documentation of this file.
1
/* ptypeTable.cc
2
*/
3
#include "
osl/bits/ptypeTable.h
"
4
#include "
osl/bits/boardTable.h
"
5
6
osl::PtypeTable::PtypeTable
()
7
{
8
init
();
9
10
{
11
// guard
12
assert(&
effect
(
newPtypeO
(
WHITE
,
ROOK
),
Offset32
(2,8))
13
== &
getEffect
(
newPtypeO
(
WHITE
,
ROOK
),
Offset32
(2,8)));
14
assert(
getEffect
(
newPtypeO
(
BLACK
,
PPAWN
),
15
Offset32
(
Square
(7,1),
Square
(8,1)))
16
==
EffectContent::DIRECT
());
17
}
18
}
19
20
template
<osl::Ptype T>
21
void
osl::PtypeTable::initPtypeSub
(
Int2Type<true>
)
22
{
23
initPtypeSub<T>(
Int2Type<false>
());
24
numMaskLows[
static_cast<
int
>
(T)]=mask_t::makeDirect(
PtypeFuns<T>::indexMask
);
25
numIndices[
static_cast<
int
>
(T)]=
PtypeFuns<T>::indexNum
;
26
if
(
canPromote
(T)){
27
numMaskLows[
static_cast<
int
>
(
promote
(T))]=mask_t::makeDirect(
PtypeFuns<T>::indexMask
);
28
numIndices[
static_cast<
int
>
(
promote
(T))]=
PtypeFuns<T>::indexNum
;
29
}
31
canDropLimit[0][
static_cast<
int
>
(T)]=
PtypeTraits<T>::dropBlackFromY
;
33
canDropLimit[1][
static_cast<
int
>
(T)]=
Square::reverseY
(
PtypeTraits<T>::dropBlackFromY
);
34
indexMins[
static_cast<
int
>
(T)]=
PtypeTraits<T>::indexMin
;
35
indexLimits[
static_cast<
int
>
(T)]=
PtypeTraits<T>::indexLimit
;
36
}
37
38
template
<osl::Ptype T>
39
void
osl::PtypeTable::initPtypeSub
(
Int2Type<false>
/*is_basic*/
)
40
{
41
names[
static_cast<
int
>
(T)]=
PtypeTraits<T>::name
();
42
csaNames[
static_cast<
int
>
(T)]=
PtypeTraits<T>::csaName
();
43
moveMasks[
static_cast<
int
>
(T)]=
PtypeTraits<T>::moveMask
;
44
betterToPromote[
static_cast<
int
>
(T)]=
PtypeTraits<T>::betterToPromote
;
45
}
46
47
template
<osl::Ptype T>
48
void
osl::PtypeTable::initPtype
()
49
{
50
initPtypeSub<T>(
Int2Type
<
PtypeTraits<T>::isBasic
>());
51
}
52
53
void
osl::PtypeTable::init
()
54
{
55
numMaskLows.fill();
56
numIndices.fill();
57
58
initPtype<PTYPE_EMPTY>();
59
initPtype<PTYPE_EDGE>();
60
initPtype<PPAWN>();
61
initPtype<PLANCE>();
62
initPtype<PKNIGHT>();
63
initPtype<PSILVER>();
64
initPtype<PBISHOP>();
65
initPtype<PROOK>();
66
initPtype<GOLD>();
67
initPtype<KING>();
68
initPtype<PAWN>();
69
initPtype<LANCE>();
70
initPtype<KNIGHT>();
71
initPtype<SILVER>();
72
initPtype<BISHOP>();
73
initPtype<ROOK>();
74
effectTable.fill();
75
effectTableNotLongU.fill();
76
shortMoveMask.fill();
77
static_assert(
sizeof
(
EffectContent
) == 4,
"size"
);
78
assert(&effect(
newPtypeO
(
WHITE
,
ROOK
),
Offset32
(2,8))
79
== &getEffect(
newPtypeO
(
WHITE
,
ROOK
),
Offset32
(2,8)));
80
assert(! getEffect(
newPtypeO
(
BLACK
,
ROOK
),
Offset32
(-1,8)).hasEffect());
81
82
for
(
int
ptype=
PTYPE_MIN
;ptype<=
PTYPE_MAX
;ptype++){
83
for
(
int
j=
DIRECTION_MIN
;j<=
DIRECTION_MAX
;j++){
84
Direction
dir=
static_cast<
Direction
>
(j);
85
86
if
((moveMasks[ptype]&(1<<dir))!=0){
87
int
dx=
Board_Table
.
getDxForBlack
(dir);
88
int
dy=
Board_Table
.
getDyForBlack
(dir);
89
Offset32
offset32=
Offset32
(dx,dy);
90
Offset
offset=
newOffset
(dx,dy);
91
if
(
isLong
(dir)){
92
shortMoveMask[0][dir-10]|=1<<(ptype-
PTYPEO_MIN
);
93
shortMoveMask[1][dir-10]|=1<<(ptype-16-
PTYPEO_MIN
);
94
95
effectTable[ptype-
PTYPEO_MIN
][offset32.
index
()]=
EffectContent::DIRECT
(offset);
96
effectTable[ptype-16-
PTYPEO_MIN
][(-offset32).index()]=
EffectContent::DIRECT
(-offset);
97
98
for
(
int
i=2;i<9;i++){
99
offset32=
Offset32
(dx*i,dy*i);
100
effectTable[ptype-
PTYPEO_MIN
][offset32.
index
()]=
EffectContent
(offset);
101
effectTable[ptype-16-
PTYPEO_MIN
][(-offset32).index()]=
EffectContent
(-offset);
102
103
if
(
static_cast<
int
>
(dir)!=
LONG_U
){
104
effectTableNotLongU[ptype-
PTYPEO_MIN
][offset32.
index
()]=effectTable[ptype-
PTYPEO_MIN
][offset32.
index
()];
105
effectTableNotLongU[ptype-16-
PTYPEO_MIN
][(-offset32).index()]=effectTable[ptype-16-
PTYPEO_MIN
][(-offset32).index()];
106
}
107
}
108
}
109
else
{
110
shortMoveMask[0][dir]|=1<<(ptype-
PTYPEO_MIN
);
111
shortMoveMask[1][dir]|=1<<(ptype-16-
PTYPEO_MIN
);
112
effectTable[ptype-
PTYPEO_MIN
][offset32.
index
()]=
EffectContent::DIRECT
();
113
effectTable[ptype-16-
PTYPEO_MIN
][(-offset32).index()]=
EffectContent::DIRECT
();
114
115
assert(! getEffect(
newPtypeO
(
BLACK
,
ROOK
),
Offset32
(-1,8)).hasEffect());
116
}
117
}
118
}
119
}
120
}
121
122
/* ------------------------------------------------------------------------- */
123
// ;;; Local Variables:
124
// ;;; mode:c++
125
// ;;; c-basic-offset:2
126
// ;;; End:
osl::Square
Definition:
basic_type.h:532
osl::Square::reverseY
static int reverseY(int y)
Definition:
basic_type.h:652
osl::WHITE
@ WHITE
Definition:
basic_type.h:10
ptypeTable.h
osl::Board_Table
const BoardTable Board_Table
Definition:
tables.cc:95
boardTable.h
osl::PtypeTable::getEffect
const EffectContent getEffect(PtypeO ptypeo, Square from, Square to) const
fromにいるptypeoがtoに利きを持つか?
Definition:
ptypeTable.h:112
osl::Offset32
Offset32Base< 8, 9 > Offset32
Definition:
offset32.h:63
osl::promote
Ptype promote(Ptype ptype)
promote可能なptypeに対して,promote後の型を返す promote不可のptypeを与えてはいけない.
Definition:
basic_type.h:173
osl::PtypeFuns
Definition:
ptypeTraits.h:311
osl::PtypeTable::initPtypeSub
void initPtypeSub(Int2Type< false > isBasic)
Definition:
ptypeTable.cc:39
osl::PtypeTable::init
void init()
Definition:
ptypeTable.cc:53
osl::PtypeTraits
Definition:
ptypeTraits.h:12
osl::newPtypeO
PtypeO newPtypeO(Player player, Ptype ptype)
Definition:
basic_type.h:211
osl::Offset
座標の差分
Definition:
basic_type.h:430
osl::DIRECTION_MAX
@ DIRECTION_MAX
Definition:
basic_type.h:337
osl::DIRECTION_MIN
@ DIRECTION_MIN
Definition:
basic_type.h:334
osl::BoardTable::getDyForBlack
int getDyForBlack(Direction dir) const
Definition:
boardTable.h:43
osl::PTYPE_MAX
@ PTYPE_MAX
Definition:
basic_type.h:105
osl::PtypeTable::effect
EffectContent & effect(PtypeO ptypeo, Offset32 offset32)
Definition:
ptypeTable.h:123
osl::LONG_U
@ LONG_U
Definition:
basic_type.h:326
osl::BoardTable::getDxForBlack
int getDxForBlack(Direction dir) const
Definition:
boardTable.h:40
osl::PtypeTable::PtypeTable
PtypeTable()
Definition:
ptypeTable.cc:6
osl::PPAWN
@ PPAWN
Definition:
basic_type.h:87
osl::PTYPE_MIN
@ PTYPE_MIN
Definition:
basic_type.h:102
osl::Offset32Base
差が uniqになるような座標の差分.
Definition:
offset32.h:17
osl::misc::Int2Type
Definition:
basic_type.h:69
osl::Direction
Direction
Definition:
basic_type.h:310
osl::ROOK
@ ROOK
Definition:
basic_type.h:100
osl::isLong
constexpr bool isLong(Direction d)
Definition:
basic_type.h:350
osl::PTYPEO_MIN
@ PTYPEO_MIN
Definition:
basic_type.h:200
osl::PtypeTable::initPtype
void initPtype()
Definition:
ptypeTable.cc:48
osl::Offset32Base::index
unsigned int index() const
Definition:
offset32.h:40
osl::newOffset
Offset newOffset(int dx, int dy)
@obsolete
Definition:
basic_type.h:508
osl::BLACK
@ BLACK
Definition:
basic_type.h:9
osl::canPromote
bool canPromote(Ptype ptype)
ptypeがpromote可能な型かどうかのチェック promote済みの場合はfalseを返す
Definition:
basic_type.h:147
osl::EffectContent
Definition:
effectContent.h:11
osl::EffectContent::DIRECT
static const EffectContent DIRECT()
Definition:
effectContent.h:24
Generated by
1.8.20