piecePairPieceTable.cc Source File

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
piecePairPieceTable.cc
Go to the documentation of this file.
1 /* piecePairPieceTable.cc
2 */
3 #include "osl/eval/ppair/piecePairPieceEval.h"
4 #include "osl/eval/ppair/piecePairRawEval.h"
5 #include "osl/eval/ppair/piecePairEval.tcc"
6 #include "osl/eval/ppair/piecePairWithStand.tcc"
7 #include "osl/eval/pieceEval.h"
8
9 namespace osl
10 {
11 namespace eval
12 {
13 namespace ppair
14 {
15 template class PiecePairEvalTableBase<PiecePairPieceTable>;
16 template class PiecePairEval<PiecePairWithStand<PiecePairPieceTable>,PiecePairPieceTable>;
17 template class PiecePairWithStand<PiecePairPieceTable>;
18 } // namespace ppair
19 } // namespace eval
20 } // namespace osl
21
22 osl::eval::ppair::
23 PiecePairPieceTable::PiecePairPieceTable()
24 {
25 }
26
27 osl::eval::ppair::
28 PiecePairPieceTable::~PiecePairPieceTable()
29 {
30 }
31
32
33 bool osl::eval::ppair::
34 PiecePairPieceTable::
35 setUp(const char *filename) const
36 {
37 if (! PiecePairRawEval::setUp(filename))
38 return false;
39
40 for (unsigned int i=0; i<maxPairIndex; ++i)
41 {
42 values[i] = PiecePairRawTable::Table.value(i)
43 *128/100; // scale up according to pawn value change
44 }
45
46 // add once, decrease later
47 for (int y=1; y<=9; ++y)
48 {
49 for (int x=1; x<=9; ++x)
50 {
51 const Square position(x,y);
52 for (int p=PTYPEO_MIN; p<=PTYPEO_MAX; ++p)
53 {
54 const PtypeO ptypeo = static_cast<PtypeO>(p);
55 if (! isPiece(ptypeo))
56 continue;
57 const unsigned int index = indexOf(position, ptypeo);
58 values[indexOf(index, index)] += Ptype_Eval_Table.value(ptypeo);
59 }
60 }
61 }
62
63 // for gold, silver
64 static const CArray<Ptype,2> gold_silver = {{ GOLD, SILVER }};
65 for (size_t i=0; i<gold_silver.size(); ++i) {
66 const Ptype ptype = gold_silver[i];
67
68 for (int y=7; y<=9; ++y) {
69 Square right(1,y), left(9,y);
70 unsigned int index_r = indexOf(right, newPtypeO(BLACK, ptype));
71 unsigned int index_l = indexOf(left, newPtypeO(BLACK, ptype));
72 values[selfIndexOf(index_r)] = values[selfIndexOf(index_r)]*4/5;
73 values[selfIndexOf(index_l)] = values[selfIndexOf(index_l)]*4/5;
74
75 right = right.rotate180();
76 left = left.rotate180();
77 index_r = indexOf(right, newPtypeO(WHITE, ptype));
78 index_l = indexOf(left, newPtypeO(WHITE, ptype));
79 values[selfIndexOf(index_r)] = values[selfIndexOf(index_r)]*4/5;
80 values[selfIndexOf(index_l)] = values[selfIndexOf(index_l)]*4/5;
81 }
82 for (int x=1; x<=9; ++x) {
83 Square top(x,1);
84 unsigned int index = indexOf(top, newPtypeO(BLACK, ptype));
85 values[selfIndexOf(index)] = values[selfIndexOf(index)] * 2/3;
86
87 top = top.rotate180();
88 index = indexOf(top, newPtypeO(WHITE, ptype));
89 values[selfIndexOf(index)] = values[selfIndexOf(index)] * 2/3;
90 }
91 }
92 for (int y=1; y<=6; ++y) {
93 for (int x=1; x<=9; ++x) {
94 Square out(x,y);
95 unsigned int index = indexOf(out, newPtypeO(BLACK, GOLD));
96 values[selfIndexOf(index)] = values[selfIndexOf(index)] * 6/7;
97
98 out = out.rotate180();
99 index = indexOf(out, newPtypeO(WHITE, GOLD));
100 values[selfIndexOf(index)] = values[selfIndexOf(index)] * 6/7;
101 }
102 }
103 for (int y=7; y<=9; ++y) {
104 Square right(2,y), left(8,y);
105 unsigned int index_r = indexOf(right, newPtypeO(BLACK, GOLD));
106 unsigned int index_l = indexOf(left, newPtypeO(BLACK, GOLD));
107 values[selfIndexOf(index_r)] = values[selfIndexOf(index_r)]*7/8;
108 values[selfIndexOf(index_l)] = values[selfIndexOf(index_l)]*7/8;
109
110 right = right.rotate180();
111 left = left.rotate180();
112 index_r = indexOf(right, newPtypeO(WHITE, GOLD));
113 index_l = indexOf(left, newPtypeO(WHITE, GOLD));
114 values[selfIndexOf(index_r)] = values[selfIndexOf(index_r)]*7/8;
115 values[selfIndexOf(index_l)] = values[selfIndexOf(index_l)]*7/8;
116 }
117
118 // undo piece values
119 for (int y=1; y<=9; ++y)
120 {
121 for (int x=1; x<=9; ++x)
122 {
123 const Square position(x,y);
124 for (int p=PTYPEO_MIN; p<=PTYPEO_MAX; ++p)
125 {
126 const PtypeO ptypeo = static_cast<PtypeO>(p);
127 if (! isPiece(ptypeo))
128 continue;
129 const unsigned int index = indexOf(position, ptypeo);
130 values[indexOf(index, index)] -= Ptype_Eval_Table.value(ptypeo);
131 }
132 }
133 }
134
135 return true;
136 }
137
138 void osl::eval::ppair::
139 PiecePairPieceEval::resetWeights(const int *w)
140 {
141 CArray<int, PTYPE_SIZE> values;
142 std::copy(w, w+(int)PTYPE_SIZE, values.begin());
143 PiecePairPieceTable::Piece_Value.reset(values);
144 }
145
146 /* ------------------------------------------------------------------------- */
147 // ;;; Local Variables:
148 // ;;; mode:c++
149 // ;;; c-basic-offset:2
150 // ;;; End: