Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
lib
progress
ptypeProgress.cc
Go to the documentation of this file.
1
#include "
osl/progress/ptypeProgress.h
"
2
#include "
osl/pieceTable.h
"
3
#include <iostream>
4
5
namespace
osl
6
{
7
namespace
progress
8
{
10
template
<Ptype T>
11
struct
PtypeProgressTraits
;
12
// 歩
13
template
<>
14
struct
PtypeProgressTraits
<
PAWN
>{
15
static
const
int
val=2;
16
};
17
template
<>
18
struct
PtypeProgressTraits
<
PPAWN
>{
19
static
const
int
val=2;
20
};
21
//
22
template
<>
23
struct
PtypeProgressTraits
<
LANCE
>{
24
static
const
int
val=5;
25
};
26
template
<>
27
struct
PtypeProgressTraits
<
PLANCE
>{
28
static
const
int
val=5;
29
};
30
//
31
template
<>
32
struct
PtypeProgressTraits
<
KNIGHT
>{
33
static
const
int
val=5;
34
};
35
template
<>
36
struct
PtypeProgressTraits
<
PKNIGHT
>{
37
static
const
int
val=5;
38
};
39
//
40
template
<>
41
struct
PtypeProgressTraits
<
SILVER
>{
42
static
const
int
val=7;
43
};
44
template
<>
45
struct
PtypeProgressTraits
<
PSILVER
>{
46
static
const
int
val=7;
47
};
48
//
49
template
<>
50
struct
PtypeProgressTraits
<
GOLD
>{
51
static
const
int
val=8;
52
};
53
//
54
template
<>
55
struct
PtypeProgressTraits
<
BISHOP
>{
56
static
const
int
val=7;
57
};
58
template
<>
59
struct
PtypeProgressTraits
<
PBISHOP
>{
60
static
const
int
val=7;
61
};
62
//
63
template
<>
64
struct
PtypeProgressTraits
<
ROOK
>{
65
static
const
int
val=10;
66
};
67
template
<>
68
struct
PtypeProgressTraits
<
PROOK
>{
69
static
const
int
val=10;
70
};
71
//
72
template
<>
73
struct
PtypeProgressTraits
<
KING
>{
74
static
const
int
val=15;
75
};
76
}
// namespace progress
77
}
// namespace osl
78
79
osl::progress::
80
PtypeProgress::PtypeProgress
(SimpleState
const
& state)
81
{
82
int
ret=0;
83
for
(
int
num=0; num<Piece::SIZE; num++)
84
{
85
if
(state.standMask(
BLACK
).test(num)){
86
ret+=
Ptype_Progress_Table
.
progress
(
newPtypeO
(
BLACK
,
Piece_Table
.
getPtypeOf
(num)),
87
Square::STAND());
88
}
89
else
if
(state.standMask(
WHITE
).test(num)){
90
ret+=
Ptype_Progress_Table
.
progress
(
newPtypeO
(
WHITE
,
Piece_Table
.
getPtypeOf
(num)),
91
Square::STAND());
92
}
93
else
{
94
assert(state.isOnBoard(num));
95
const
Piece
p=state.pieceOf(num);
96
ret+=
Ptype_Progress_Table
.
progress
(p.ptypeO(),p.square());
97
}
98
}
99
val=ret;
100
}
101
102
osl::progress::PtypeProgressTable::PtypeProgressTable
()
103
{
104
ptype2Val
[
PAWN
]=
PtypeProgressTraits<PAWN>::val
;
105
ptype2Val
[
PPAWN
]=
PtypeProgressTraits<PPAWN>::val
;
106
ptype2Val
[
LANCE
]=
PtypeProgressTraits<LANCE>::val
;
107
ptype2Val
[
PLANCE
]=
PtypeProgressTraits<PLANCE>::val
;
108
ptype2Val
[
KNIGHT
]=
PtypeProgressTraits<KNIGHT>::val
;
109
ptype2Val
[
PKNIGHT
]=
PtypeProgressTraits<PKNIGHT>::val
;
110
ptype2Val
[
SILVER
]=
PtypeProgressTraits<SILVER>::val
;
111
ptype2Val
[
PSILVER
]=
PtypeProgressTraits<PSILVER>::val
;
112
ptype2Val
[
GOLD
]=
PtypeProgressTraits<GOLD>::val
;
113
ptype2Val
[
KING
]=
PtypeProgressTraits<KING>::val
;
114
ptype2Val
[
BISHOP
]=
PtypeProgressTraits<BISHOP>::val
;
115
ptype2Val
[
PBISHOP
]=
PtypeProgressTraits<PBISHOP>::val
;
116
ptype2Val
[
ROOK
]=
PtypeProgressTraits<ROOK>::val
;
117
ptype2Val
[
PROOK
]=
PtypeProgressTraits<PROOK>::val
;
118
for
(
int
i=
PTYPE_MIN
;i<=
PTYPE_MAX
;i++){
119
Ptype
ptype=
static_cast<
Ptype
>
(i);
120
pos2Val
[
newPtypeO
(
BLACK
,ptype)-
PTYPEO_MIN
][
Square::STAND
().
index
()]=
ptype2Val
[i]*
yVals
[5];
121
pos2Val
[
newPtypeO
(
WHITE
,ptype)-
PTYPEO_MIN
][
Square::STAND
().
index
()]=
ptype2Val
[i]*yVals[5];
122
for
(
int
y=1;y<10;y++)
123
{
124
for
(
int
x=9;x>0;x--)
125
{
126
pos2Val
[
newPtypeO
(
BLACK
,ptype)-
PTYPEO_MIN
][
Square
(x,y).
index
()]
127
=
ptype2Val
[i]*yVals[y];
128
pos2Val
[
newPtypeO
(
WHITE
,ptype)-
PTYPEO_MIN
][
Square
(x,10-y).
index
()]
129
=
ptype2Val
[i]*yVals[y];
130
}
131
}
132
}
133
}
134
135
osl::progress::PtypeProgressTable::~PtypeProgressTable
() {
136
}
137
138
#ifndef MINIMAL
139
std::ostream&
osl::progress::operator<<
(std::ostream& os,
PtypeProgress
prog)
140
{
141
return
os <<
"progress "
<< prog.
progress
();
142
}
143
#endif
144
// ;;; Local Variables:
145
// ;;; mode:c++
146
// ;;; c-basic-offset:2
147
// ;;; coding:utf-8
148
// ;;; End:
Generated on Sun Jul 21 2013 13:37:26 by
1.8.4