/usr/include/osl/eval/ppair/piecePairIndex.h 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 | /* piecePairIndex.h
*/
#ifndef EVAL_PIECEPAIRINDEX_H
#define EVAL_PIECEPAIRINDEX_H
#include "osl/state/simpleState.h"
#include "osl/squareCompressor.h"
namespace osl
{
namespace eval
{
namespace ppair
{
/**
* PiecePairEvalTable の添字計算.
* キャッシュのヒット率を上げるために,r2246から計算を変更する.
* r2246以降では片方あるいは両方がSquare::STAND()の場合は
* tableの中身が0であるとして,差分計算の対象から外す.
*/
struct PiecePairIndex
{
static const unsigned int maxSquareIndex = 82;
static const unsigned int maxPtypeOIndex = PTYPEO_SIZE;
static const unsigned int maxPieceIndex = maxSquareIndex*maxPtypeOIndex;
static const unsigned int maxPairIndex = maxPieceIndex*maxPieceIndex;
static unsigned int selfIndexOf(unsigned int i)
{
return indexOf(i, i);
}
static unsigned int indexOf(unsigned int i1, unsigned int i2)
{
assert(i1 < maxPieceIndex);
assert(i2 < maxPieceIndex);
return i1*maxPieceIndex + i2;
}
static unsigned int canonicalIndexOf(unsigned int i1, unsigned int i2)
{
if (i1 > i2)
std::swap(i1,i2);
return indexOf(i1,i2);
}
/** 逆変換 */
static void meltIndex(size_t index,
size_t& i1, size_t& i2)
{
i1 = index / maxPieceIndex;
i2 = index % maxPieceIndex;
}
static unsigned int positionIndexOf(Square pos)
{
unsigned int result = SquareCompressor::compress(pos);
assert(result < maxSquareIndex);
return result;
}
static unsigned int ptypeOIndexOf(PtypeO ptypeo)
{
return ptypeo - PTYPEO_MIN;
}
static unsigned int indexOf(Square pos, PtypeO ptypeo)
{
const int result = maxSquareIndex*ptypeOIndexOf(ptypeo)
+ positionIndexOf(pos);
return result;
}
/** 逆変換 */
static void meltIndex(size_t index, Square& pos, PtypeO& ptypeo)
{
ptypeo = static_cast<PtypeO>(static_cast<int>(index / maxSquareIndex)+PTYPEO_MIN);
pos = SquareCompressor::melt(index % maxSquareIndex);
}
static unsigned int indexOf(Piece piece)
{
return indexOf(piece.square(), piece.ptypeO());
}
static unsigned int indexOf(Piece p1, Piece p2)
{
return indexOf(indexOf(p1), indexOf(p2));
}
static unsigned int indexOfPieceNum(const SimpleState& s, int id)
{
return indexOf(s.pieceOf(id));
}
/** 全ての関係についてfを実行する.重複する関係は訪れない */
template <class F>
static void forEachRelation(F f);
};
} // namespace ppair
using ppair::PiecePairIndex;
} // namespace eval
} // namespace osl
template <class F>
void osl::eval::ppair::
PiecePairIndex::forEachRelation(F f)
{
for (int x=1; x<=9; ++x)
{
for (int y=1; y<=9; ++y)
{
const Square pos1(x,y);
for (int ptype=PPAWN; ptype<=PTYPE_MAX; ++ptype)
{
const Ptype p1 = static_cast<Ptype>(ptype);
const unsigned int i1 =
indexOf(pos1, newPtypeO(BLACK, p1));
const unsigned int i1w =
indexOf(pos1, newPtypeO(WHITE, p1));
f(indexOf(i1,i1));
f(indexOf(i1w,i1w));
for (int x2=x; x2<=9; ++x2)
{
for (int y2=((x2 == x) ? y+1 : 1); y2<=9; ++y2)
{
const Square pos2(x2,y2);
for (int ptype2=PPAWN; ptype2<=PTYPE_MAX; ++ptype2)
{
const Ptype p2 = static_cast<Ptype>(ptype2);
const unsigned int i2 =
indexOf(pos2, newPtypeO(BLACK, p2));
const unsigned int i2w =
indexOf(pos2, newPtypeO(WHITE, p2));
f(indexOf(i1, i2));
f(indexOf(i1, i2w));
f(indexOf(i1w, i2));
f(indexOf(i1w, i2w));
}
}
}
for (int ptype2=KING; ptype2<=PTYPE_MAX; ++ptype2)
{
const Ptype p2 = static_cast<Ptype>(ptype2);
const unsigned int i2 =
indexOf(Square::STAND(), newPtypeO(BLACK, p2));
const unsigned int i2w =
indexOf(Square::STAND(), newPtypeO(WHITE, p2));
f(indexOf(i1, i2));
f(indexOf(i1, i2w));
f(indexOf(i1w, i2));
f(indexOf(i1w, i2w));
}
} // ptype
} // x
} // y
// 持駒同士は最後に
for (int ptype=KING; ptype<=PTYPE_MAX; ++ptype)
{
const Ptype p1 = static_cast<Ptype>(ptype);
const unsigned int i1 =
indexOf(Square::STAND(), newPtypeO(BLACK, p1));
const unsigned int i1w =
indexOf(Square::STAND(), newPtypeO(WHITE, p1));
f(indexOf(i1, i1));
f(indexOf(i1, i1w));
f(indexOf(i1w, i1w));
for (int ptype2=ptype+1; ptype2<=PTYPE_MAX; ++ptype2)
{
const Ptype p2 = static_cast<Ptype>(ptype2);
const unsigned int i2 =
indexOf(Square::STAND(), newPtypeO(BLACK, p2));
const unsigned int i2w =
indexOf(Square::STAND(), newPtypeO(WHITE, p2));
f(indexOf(i1, i2));
f(indexOf(i1, i2w));
f(indexOf(i1w, i2));
f(indexOf(i1w, i2w));
}
}
}
#endif /* EVAL_PIECEPAIRINDEX_H */
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
|