/usr/include/osl/eval/ppair/piecePairEval.tcc is in libosl-dev 0.6.0-3.3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | /* piecePairEval.tcc
*/
#ifndef EVAL_PIECE_PAIR_EVAL_TCC
#define EVAL_PIECE_PAIR_EVAL_TCC
#include "osl/eval/ppair/piecePairEval.h"
#include "osl/eval/ppair/piecePairAssert.h"
#include "osl/container/pieceValues.h"
#include "osl/pieceTable.h"
#include "osl/oslConfig.h"
template <class Table>
osl::eval::ppair::
PiecePairEvalTableBase<Table>::PiecePairEvalTableBase(const SimpleState& state)
{
for (int i=0; i<Piece::SIZE; i++) {
for (int j=i; j<Piece::SIZE; j++) {
val += Table::Table.valueOf
(PiecePairIndex::indexOfPieceNum(state, i),
PiecePairIndex::indexOfPieceNum(state, j));
}
}
}
template <class Table>
bool& osl::eval::ppair::
PiecePairEvalTableBase<Table>::initializationFlag()
{
static bool flag = false;
return flag;
}
template <class Table>
bool osl::eval::ppair::
PiecePairEvalTableBase<Table>::setUp(const char *filename)
{
bool& result = initializationFlag();
result = Table::Table.setUp(filename);
return result;
}
template <class Table>
bool osl::eval::ppair::
PiecePairEvalTableBase<Table>::setUp()
{
std::string filename = OslConfig::home();
filename += "/data/sibling-attack.pair";
return setUp(filename.c_str());
}
template <class Table>
int osl::eval::ppair::PiecePairEvalTableBase<Table>::
adjustPairs(const SimpleState& state,
unsigned int new_index)
{
int diff = 0;
for (int i=0; i<Piece::SIZE; i++)
{
const Piece p=state.pieceOf(i);
if(p.isOnBoard()){
const unsigned int target =
PiecePairIndex::indexOf(p);
// 以下は target==old_index で1回以上(駒台)マッチ
diff += Table::Table.valueOf(target, new_index);
}
}
diff += Table::Table.valueOf(new_index, new_index);
return diff;
}
template <class Table>
int osl::eval::ppair::PiecePairEvalTableBase<Table>::
adjustPairs(const SimpleState& state,
unsigned int old_index, unsigned int new_index)
{
int diff = 0;
for (int i=0; i<Piece::SIZE; i++)
{
const Piece p=state.pieceOf(i);
if(p.isOnBoard()){
const unsigned int target =
PiecePairIndex::indexOf(p);
diff -= Table::Table.valueOf(target, old_index);
// 以下は target==old_index で1回以上(駒台)マッチ
diff += Table::Table.valueOf(target, new_index);
}
}
diff -= Table::Table.valueOf(old_index, new_index); // 足しすぎた分
diff += Table::Table.valueOf(new_index, new_index);
return diff;
}
template <class Table>
int osl::eval::ppair::PiecePairEvalTableBase<Table>::
adjustPairs(const SimpleState& state,
unsigned int old_index, unsigned int old_index2,
unsigned int new_index)
{
int diff = 0;
for (int i=0;i<Piece::SIZE; i++)
{
const Piece p=state.pieceOf(i);
if(p.isOnBoard()){
const unsigned int target =
PiecePairIndex::indexOf(p);
diff += Table::Table.valueOf(target, new_index);
diff -= Table::Table.valueOf(target, old_index);
diff -= Table::Table.valueOf(target, old_index2);
}
}
diff -= Table::Table.valueOf(old_index, new_index);
diff -= Table::Table.valueOf(old_index2, new_index);
diff += Table::Table.valueOf(old_index, old_index2);
diff += Table::Table.valueOf(new_index, new_index);
return diff;
}
// update
template <class Table>
int osl::eval::ppair::PiecePairEvalTableBase<Table>::
adjustPairsAfterMove(const SimpleState& state,
unsigned int new_index)
{
int diff = 0;
for (int i=0; i<Piece::SIZE; i++)
{
const Piece p=state.pieceOf(i);
if (p.isOnBoard()) {
const unsigned int target =
PiecePairIndex::indexOf(p);
diff += Table::Table.valueOf(target, new_index);
}
}
return diff;
}
template <class Table>
int osl::eval::ppair::PiecePairEvalTableBase<Table>::
adjustPairsAfterMove(const SimpleState& state,
unsigned int old_index, unsigned int new_index)
{
int diff = 0;
for (int i=0; i<Piece::SIZE; i++)
{
const Piece p=state.pieceOf(i);
if(p.isOnBoard()){
const unsigned int target =
PiecePairIndex::indexOf(p);
diff -= Table::Table.valueOf(target, old_index);
diff += Table::Table.valueOf(target, new_index);
}
}
diff -= Table::Table.valueOf(old_index, old_index);
diff += Table::Table.valueOf(new_index, old_index); // 引きすぎた分
return diff;
}
template <class Table>
int osl::eval::ppair::PiecePairEvalTableBase<Table>::
adjustPairsAfterMove(const SimpleState& state,
unsigned int old_index, unsigned int old_index2,
unsigned int new_index)
{
int diff = 0;
for (int i=0;i<Piece::SIZE; i++)
{
const Piece p=state.pieceOf(i);
if(p.isOnBoard()){
const unsigned int target =
PiecePairIndex::indexOf(p);
diff += Table::Table.valueOf(target, new_index);
diff -= Table::Table.valueOf(target, old_index);
diff -= Table::Table.valueOf(target, old_index2);
}
}
diff += Table::Table.valueOf(new_index, old_index);
diff += Table::Table.valueOf(new_index, old_index2);
diff -= Table::Table.valueOf(old_index, old_index2);
diff -= Table::Table.valueOf(old_index, old_index);
diff -= Table::Table.valueOf(old_index2, old_index2);
return diff;
}
template <class Table>
void osl::eval::ppair::PiecePairEvalTableBase<Table>::
setValues(const SimpleState& state, container::PieceValues& values)
{
values.fill(0);
// 速度は無視
for (int i=0; i<Piece::SIZE; i++) {
const bool i_is_king = (Piece_Table.getPtypeOf(i) == KING);
for (int j=0; j<Piece::SIZE; j++) {
if (i==j)
continue;
const bool j_is_king = (Piece_Table.getPtypeOf(j) == KING);
const int relation_value = Table::Table.valueOf
(PiecePairIndex::indexOfPieceNum(state, i),
PiecePairIndex::indexOfPieceNum(state, j));
if (i_is_king && (! j_is_king))
{
values[j] += relation_value;
}
else
{
values[i] += relation_value;
}
}
}
for (int i=0; i<Piece::SIZE; i++)
{
values[i] /= 2;
const unsigned int index = PiecePairIndex::indexOfPieceNum(state, i);
const int self_value = Table::Table.valueOf(index, index);
values[i] += self_value;
}
}
/* ------------------------------------------------------------------------- */
template <class Eval, class Table>
osl::eval::ppair::
PiecePairEval<Eval,Table>::PiecePairEval(const SimpleState& state)
: PiecePairEvalTableBase<Table>(state)
{
}
template <class Eval, class Table>
int osl::eval::ppair::PiecePairEval<Eval,Table>::
expect(const SimpleState& state, Move m) const
{
const Ptype ptype = m.ptype();
const Square to = m.to();
const Player player = state.turn();
if (m.isDrop()) {
piece_pair_assert(state.pieceAt(to) == Piece::EMPTY());
return this->roundUp(this->val + Eval::diffAfterDropMove(state, to, newPtypeO(player, ptype)));
}
const Square from = m.from();
piece_pair_assert(state.pieceAt(from) != Piece::EMPTY());
if (m.capturePtype() == PTYPE_EMPTY) {
piece_pair_assert(state.pieceAt(to) == Piece::EMPTY());
return this->roundUp(this->val + Eval::diffAfterSimpleMove(state, from, to, m.promoteMask()));
}
piece_pair_assert(state.pieceAt(to) != Piece::EMPTY());
return this->roundUp(this->val + Eval::diffAfterCaptureMove(state, from, to, m.capturePtypeO(), m.promoteMask()));
}
#endif /* EVAL_PIECE_PAIR_EVAL_TCC */
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
|