Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
include
osl
eval
ppair
piecePairIndex.h
Go to the documentation of this file.
1
/* piecePairIndex.h
2
*/
3
#ifndef EVAL_PIECEPAIRINDEX_H
4
#define EVAL_PIECEPAIRINDEX_H
5
6
#include "
osl/state/simpleState.h
"
7
#include "
osl/squareCompressor.h
"
8
9
namespace
osl
10
{
11
namespace
eval
12
{
13
namespace
ppair
14
{
21
struct
PiecePairIndex
22
{
23
static
const
unsigned
int
maxSquareIndex
= 82;
24
static
const
unsigned
int
maxPtypeOIndex
=
PTYPEO_SIZE
;
25
static
const
unsigned
int
maxPieceIndex
=
maxSquareIndex
*
maxPtypeOIndex
;
26
static
const
unsigned
int
maxPairIndex
=
maxPieceIndex
*
maxPieceIndex
;
27
28
static
unsigned
int
selfIndexOf
(
unsigned
int
i)
29
{
30
return
indexOf
(i, i);
31
}
32
33
static
unsigned
int
indexOf
(
unsigned
int
i1,
unsigned
int
i2)
34
{
35
assert(i1 <
maxPieceIndex
);
36
assert(i2 <
maxPieceIndex
);
37
return
i1*
maxPieceIndex
+ i2;
38
}
39
static
unsigned
int
canonicalIndexOf
(
unsigned
int
i1,
unsigned
int
i2)
40
{
41
if
(i1 > i2)
42
std::swap(i1,i2);
43
return
indexOf
(i1,i2);
44
}
46
static
void
meltIndex
(
size_t
index,
47
size_t
& i1,
size_t
& i2)
48
{
49
i1 = index /
maxPieceIndex
;
50
i2 = index %
maxPieceIndex
;
51
}
52
static
unsigned
int
positionIndexOf
(
Square
pos)
53
{
54
unsigned
int
result
=
SquareCompressor::compress
(pos);
55
assert(result <
maxSquareIndex
);
56
return
result
;
57
}
58
static
unsigned
int
ptypeOIndexOf
(
PtypeO
ptypeo)
59
{
60
return
ptypeo -
PTYPEO_MIN
;
61
}
62
static
unsigned
int
indexOf
(
Square
pos,
PtypeO
ptypeo)
63
{
64
const
int
result
=
maxSquareIndex
*
ptypeOIndexOf
(ptypeo)
65
+
positionIndexOf
(pos);
66
return
result
;
67
}
69
static
void
meltIndex
(
size_t
index,
Square
& pos,
PtypeO
& ptypeo)
70
{
71
ptypeo =
static_cast<
PtypeO
>
(
static_cast<
int
>
(index /
maxSquareIndex
)+
PTYPEO_MIN
);
72
pos =
SquareCompressor::melt
(index %
maxSquareIndex
);
73
}
74
75
static
unsigned
int
indexOf
(
Piece
piece)
76
{
77
return
indexOf
(piece.
square
(), piece.
ptypeO
());
78
}
79
static
unsigned
int
indexOf
(
Piece
p1,
Piece
p2)
80
{
81
return
indexOf
(
indexOf
(p1),
indexOf
(p2));
82
}
83
84
static
unsigned
int
indexOfPieceNum
(
const
SimpleState& s,
int
id
)
85
{
86
return
indexOf
(s.pieceOf(
id
));
87
}
88
89
91
template
<
class
F>
92
static
void
forEachRelation
(F f);
93
};
94
95
}
// namespace ppair
96
using
ppair::PiecePairIndex;
97
}
// namespace eval
98
}
// namespace osl
99
100
101
template
<
class
F>
102
void
osl::eval::ppair::
103
PiecePairIndex::forEachRelation
(F f)
104
{
105
for
(
int
x=1; x<=9; ++x)
106
{
107
for
(
int
y=1; y<=9; ++y)
108
{
109
const
Square
pos1(x,y);
110
for
(
int
ptype=
PPAWN
; ptype<=
PTYPE_MAX
; ++ptype)
111
{
112
const
Ptype
p1 =
static_cast<
Ptype
>
(ptype);
113
const
unsigned
int
i1 =
114
indexOf(pos1,
newPtypeO
(
BLACK
, p1));
115
const
unsigned
int
i1w =
116
indexOf(pos1,
newPtypeO
(
WHITE
, p1));
117
f(indexOf(i1,i1));
118
f(indexOf(i1w,i1w));
119
120
for
(
int
x2=x; x2<=9; ++x2)
121
{
122
for
(
int
y2=((x2 == x) ? y+1 : 1); y2<=9; ++y2)
123
{
124
const
Square
pos2(x2,y2);
125
126
for
(
int
ptype2=
PPAWN
; ptype2<=
PTYPE_MAX
; ++ptype2)
127
{
128
const
Ptype
p2 =
static_cast<
Ptype
>
(ptype2);
129
const
unsigned
int
i2 =
130
indexOf(pos2,
newPtypeO
(
BLACK
, p2));
131
const
unsigned
int
i2w =
132
indexOf(pos2,
newPtypeO
(
WHITE
, p2));
133
134
f(indexOf(i1, i2));
135
f(indexOf(i1, i2w));
136
f(indexOf(i1w, i2));
137
f(indexOf(i1w, i2w));
138
}
139
}
140
}
141
142
for
(
int
ptype2=
KING
; ptype2<=
PTYPE_MAX
; ++ptype2)
143
{
144
const
Ptype
p2 =
static_cast<
Ptype
>
(ptype2);
145
const
unsigned
int
i2 =
146
indexOf(Square::STAND(),
newPtypeO
(
BLACK
, p2));
147
const
unsigned
int
i2w =
148
indexOf(Square::STAND(),
newPtypeO
(
WHITE
, p2));
149
150
f(indexOf(i1, i2));
151
f(indexOf(i1, i2w));
152
f(indexOf(i1w, i2));
153
f(indexOf(i1w, i2w));
154
}
155
}
// ptype
156
}
// x
157
}
// y
158
159
// 持駒同士は最後に
160
for
(
int
ptype=
KING
; ptype<=
PTYPE_MAX
; ++ptype)
161
{
162
const
Ptype
p1 =
static_cast<
Ptype
>
(ptype);
163
const
unsigned
int
i1 =
164
indexOf(Square::STAND(),
newPtypeO
(
BLACK
, p1));
165
const
unsigned
int
i1w =
166
indexOf(Square::STAND(),
newPtypeO
(
WHITE
, p1));
167
f(indexOf(i1, i1));
168
f(indexOf(i1, i1w));
169
f(indexOf(i1w, i1w));
170
for
(
int
ptype2=ptype+1; ptype2<=
PTYPE_MAX
; ++ptype2)
171
{
172
const
Ptype
p2 =
static_cast<
Ptype
>
(ptype2);
173
const
unsigned
int
i2 =
174
indexOf(Square::STAND(),
newPtypeO
(
BLACK
, p2));
175
const
unsigned
int
i2w =
176
indexOf(Square::STAND(),
newPtypeO
(
WHITE
, p2));
177
178
f(indexOf(i1, i2));
179
f(indexOf(i1, i2w));
180
f(indexOf(i1w, i2));
181
f(indexOf(i1w, i2w));
182
}
183
}
184
}
185
186
#endif
/* EVAL_PIECEPAIRINDEX_H */
187
// ;;; Local Variables:
188
// ;;; mode:c++
189
// ;;; c-basic-offset:2
190
// ;;; End:
Generated on Sun Jul 21 2013 13:37:26 by
1.8.4