Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
lib
checkmate
immediateCheckmateTable.cc
Go to the documentation of this file.
1
/* immediateCheckmateTable.cc
2
*/
3
#include "
osl/checkmate/immediateCheckmateTable.h
"
4
#include "
osl/boardTable.h
"
5
#include "
osl/ptypeTable.h
"
6
namespace
7
{
8
bool
canCheckmate(
osl::Ptype
ptype,
osl::Direction
dir,
unsigned
int
mask)
9
{
10
// 王はdropできない, 打ち歩詰め
11
if
(ptype==
osl::KING
|| ptype==
osl::PAWN
)
return
false
;
12
// ptypeがdir方向に利きを持たない == 王手をかけられない
13
if
(!(
osl::Ptype_Table
.getMoveMask(ptype)&
14
(
osl::dirToMask
(dir) |
osl::dirToMask
(
osl::shortToLong
(dir)))))
return
false
;
15
int
dx=
osl::Board_Table
.
getDxForBlack
(dir);
16
int
dy=
osl::Board_Table
.
getDyForBlack
(dir);
17
for
(
int
l=0;l<8;l++){
18
if
((mask&(1<<l))==0)
continue
;
19
osl::Direction
dir1=
static_cast<
osl::Direction
>
(l);
20
int
dx1=
osl::Board_Table
.
getDxForBlack
(dir1);
21
int
dy1=
osl::Board_Table
.
getDyForBlack
(dir1);
22
osl::Offset32
o32(dx-dx1,dy-dy1);
23
if
(!
osl::Ptype_Table
.getEffect(
osl::newPtypeO
(
osl::BLACK
,ptype),o32).
hasEffect
())
24
return
false
;
25
}
26
return
true
;
27
}
28
}
29
30
osl::checkmate::ImmediateCheckmateTable::ImmediateCheckmateTable
()
31
{
32
// ptypeDropMaskの初期化
33
for
(
int
i=0;i<0x100;i++){
34
for
(
int
k=
PTYPE_BASIC_MIN
;k<=
PTYPE_MAX
;k++){
35
unsigned
char
mask=0;
36
Ptype
ptype=
static_cast<
Ptype
>
(k);
37
for
(
int
j=0;j<8;j++){
38
// 玉の逃げ道がある
39
if
((i&(0x1<<j))!=0)
continue
;
40
Direction
dir=
static_cast<
Direction
>
(j);
41
if
(canCheckmate(ptype,dir,i))
42
mask|=(1<<j);
43
}
44
ptypeDropMasks
(i,ptype)=mask;
45
}
46
}
47
// dropPtypeMaskの初期化
48
for
(
int
i=0;i<0x10000;i++){
49
unsigned
char
ptypeMask=0;
50
for
(
int
k=
PTYPE_BASIC_MIN
;k<=
PTYPE_MAX
;k++){
51
Ptype
ptype=
static_cast<
Ptype
>
(k);
52
for
(
int
j=0;j<8;j++){
53
// 空白でない
54
if
((i&(0x1<<j))==0)
continue
;
55
// 玉の逃げ道がある
56
if
((i&(0x100<<j))!=0)
continue
;
57
Direction
dir=
static_cast<
Direction
>
(j);
58
if
(canCheckmate(ptype,dir,(i>>8)&0xff)){
59
ptypeMask|=1u<<(k-
PTYPE_BASIC_MIN
);
60
goto
nextPtype;
61
}
62
}
63
nextPtype:;
64
}
65
dropPtypeMasks
[i]=ptypeMask;
66
}
67
// blockingMaskの初期化
68
for
(
int
k=
PTYPE_BASIC_MIN
;k<=
PTYPE_MAX
;k++){
69
Ptype
ptype=
static_cast<
Ptype
>
(k);
70
for
(
int
j=0;j<8;j++){
71
unsigned
int
mask=0;
72
Direction
dir=
static_cast<
Direction
>
(j);
73
if
(
Ptype_Table
.
getMoveMask
(ptype)&
74
(
dirToMask
(dir) |
dirToMask
(
shortToLong
(dir)))){
75
int
dx=
Board_Table
.
getDxForBlack
(dir);
76
int
dy=
Board_Table
.
getDyForBlack
(dir);
77
for
(
int
l=0;l<8;l++){
78
Direction
dir1=
static_cast<
Direction
>
(l);
79
int
dx1=
Board_Table
.
getDxForBlack
(dir1);
80
int
dy1=
Board_Table
.
getDyForBlack
(dir1);
81
Offset32
o32(dx-dx1,dy-dy1);
82
if
(!
Ptype_Table
.
getEffect
(
newPtypeO
(
BLACK
,ptype),o32).
hasEffect
()){
83
if
(!
Board_Table
.
getShortOffsetNotKnight
(o32).
zero
() &&
84
!(dx==-dx1 && dy==-dy1)
85
){
86
mask|=1<<l;
87
}
88
}
89
}
90
}
91
blockingMasks
(ptype,dir)=mask;
92
}
93
}
94
// effectMaskの初期化
95
for
(
int
k=
PTYPE_PIECE_MIN
;k<=
PTYPE_MAX
;k++){
96
Ptype
ptype=
static_cast<
Ptype
>
(k);
97
for
(
int
j=0;j<8;j++){
98
unsigned
int
mask=0x1ff;
99
Direction
dir=
static_cast<
Direction
>
(j);
100
if
(
Ptype_Table
.
getMoveMask
(ptype)&
101
(
dirToMask
(dir) |
dirToMask
(
shortToLong
(dir)))){
// 王手をかけられる
102
mask=0;
103
int
dx=
Board_Table
.
getDxForBlack
(dir);
104
int
dy=
Board_Table
.
getDyForBlack
(dir);
105
for
(
int
l=0;l<8;l++){
106
Direction
dir1=
static_cast<
Direction
>
(l);
107
int
dx1=
Board_Table
.
getDxForBlack
(dir1);
108
int
dy1=
Board_Table
.
getDyForBlack
(dir1);
109
Offset32
o32(dx-dx1,dy-dy1);
110
if
(dir!= dir1 &&
111
!
Ptype_Table
.
getEffect
(
newPtypeO
(
BLACK
,ptype),o32).
hasEffect
()){
112
mask|=1<<l;
113
}
114
}
115
}
116
noEffectMasks
(ptype,dir)=mask;
117
}
118
}
119
}
120
121
122
123
/* ------------------------------------------------------------------------- */
124
// ;;; Local Variables:
125
// ;;; mode:c++
126
// ;;; c-basic-offset:2
127
// ;;; End:
128
129
Generated on Sun Jul 21 2013 13:37:24 by
1.8.4