progress.cc
Go to the documentation of this file.
#include "osl/progress.h"
#include "osl/eval/weights.h"
#include "osl/eval/midgame.h"
#include "osl/eval/minorPiece.h"
#include "osl/additionalEffect.h"
#include "osl/bits/centering5x3.h"
#include "osl/oslConfig.h"
#include <iostream>
#include <fstream>
bool osl::progress::ml::
operator==(const NewProgressData& l, const NewProgressData& r)
{
return l.progresses == r.progresses
&& l.attack5x5_progresses == r.attack5x5_progresses
&& l.stand_progresses == r.stand_progresses
&& l.effect_progresses == r.effect_progresses
&& l.defenses == r.defenses
&& l.rook == r.rook && l.bishop == r.bishop && l.gold == r.gold
&& l.silver == r.silver && l.promoted == r.promoted
&& l.king_relative_attack == r.king_relative_attack
&& l.king_relative_defense == r.king_relative_defense
&& l.non_pawn_ptype_attacked_pair == r.non_pawn_ptype_attacked_pair
&& l.non_pawn_ptype_attacked_pair_eval == r.non_pawn_ptype_attacked_pair_eval;
}
osl::CArray<int, 81*15*10>
osl::progress::ml::NewProgress::attack_relative;
osl::CArray<int, 81*15*10>
osl::progress::ml::NewProgress::defense_relative;
osl::CArray<int, osl::Piece::SIZE>
osl::progress::ml::NewProgress::stand_weight;
osl::CArray<int, 1125>
osl::progress::ml::NewProgress::attack5x5_weight;
osl::CArray<int, 5625>
osl::progress::ml::NewProgress::attack5x5_x_weight;
osl::CArray<int, 10125>
osl::progress::ml::NewProgress::attack5x5_y_weight;
osl::CArray<int, 75>
osl::progress::ml::NewProgress::effectstate_weight;
osl::CArray<int, 4284>
osl::progress::ml::NewProgress::king_relative_weight;
osl::CArray<int, 262144>
osl::progress::ml::NewProgress::attacked_ptype_pair_weight;
osl::CArray<int, 10>
osl::progress::ml::NewProgress::pawn_facing_weight;
osl::CArray<int, 16>
osl::progress::ml::NewProgress::promotion37_weight;
osl::CArray<int, 56>
osl::progress::ml::NewProgress::piecestand7_weight;
int osl::progress::ml::NewProgress::max_progress;
bool osl::progress::ml::NewProgress::initialized_flag;
bool osl::progress::ml::NewProgress::setUp(const char *filename)
{
if (initialized_flag)
return true;
static CArray<int, 25> effect_weight;
static CArray<int, 225> effect_x_weight, effect_y_weight;
static CArray<int, 25> effect_defense_weight;
static CArray<int, 225> effect_per_effect;
static CArray<int, 225> effect_per_effect_defense;
static CArray<int, 2025> effect_per_effect_y, effect_per_effect_x;
std::ifstream is(filename);
int read_count = 0;
osl::eval::ml::Weights weights(25);
for (size_t i = 0; i < weights.dimension(); ++i)
{
int val;
is >> val;
effect_weight[i] = val;
++read_count;
}
for (size_t i = 0; i < 225; ++i)
{
int val;
is >> val;
effect_x_weight[i] = val;
++read_count;
}
for (size_t i = 0; i < 225; ++i)
{
int val;
is >> val;
effect_y_weight[i] = val;
++read_count;
}
weights.resetDimension(25);
for (size_t i = 0; i < weights.dimension(); ++i)
{
int val;
is >> val;
effect_defense_weight[i] = val;
++read_count;
}
weights.resetDimension(225);
for (size_t i = 0; i < weights.dimension(); ++i)
{
int val;
is >> val;
effect_per_effect[i] = val;
++read_count;
}
weights.resetDimension(225);
for (size_t i = 0; i < weights.dimension(); ++i)
{
int val;
is >> val;
effect_per_effect_defense[i] = val;
++read_count;
}
weights.resetDimension(2025);
for (size_t i = 0; i < weights.dimension(); ++i)
{
int val;
is >> val;
effect_per_effect_y[i] = val;
++read_count;
}
weights.resetDimension(2025);
for (size_t i = 0; i < weights.dimension(); ++i)
{
int val;
is >> val;
effect_per_effect_x[i] = val;
++read_count;
}
weights.resetDimension(Piece::SIZE);
for (size_t i = 0; i < weights.dimension(); ++i)
{
int val;
is >> val;
stand_weight[i] = val;
++read_count;
}
weights.resetDimension(1125);
for (size_t i = 0; i < weights.dimension(); ++i)
{
int val;
is >> val;
attack5x5_weight[i] = val;
++read_count;
}
weights.resetDimension(75);
for (size_t i = 0; i < weights.dimension(); ++i)
{
int val;
is >> val;
effectstate_weight[i] = val;
++read_count;
}
weights.resetDimension(5625);
for (size_t i = 0; i < weights.dimension(); ++i)
{
int val;
is >> val;
attack5x5_x_weight[i] = val;
++read_count;
}
weights.resetDimension(10125);
for (size_t i = 0; i < weights.dimension(); ++i)
{
int val;
is >> val;
attack5x5_y_weight[i] = val;
++read_count;
}
weights.resetDimension(4284);
for (size_t i = 0; i < weights.dimension(); ++i)
{
int val;
is >> val;
king_relative_weight[i] = val;
++read_count;
}
weights.resetDimension(262144);
for (size_t i = 0; i < weights.dimension(); ++i)
{
int val;
is >> val;
attacked_ptype_pair_weight[i] = val;
++read_count;
}
weights.resetDimension(10);
for (size_t i = 0; i < weights.dimension(); ++i)
{
int val;
is >> val;
pawn_facing_weight[i] = val;
++read_count;
}
weights.resetDimension(16);
for (size_t i = 0; i < weights.dimension(); ++i)
{
int val;
is >> val;
promotion37_weight[i] = val;
++read_count;
}
weights.resetDimension(56);
for (size_t i = 0; i < weights.dimension(); ++i)
{
int val;
is >> val;
piecestand7_weight[i] = val;
++read_count;
}
{
int val;
is >> val;
max_progress = val;
++read_count;
#ifdef EVAL_QUAD
while (((max_progress/ProgressScale) % 3) && max_progress > 0)
--max_progress;
#endif
}
for(int king_x=1;king_x<=9;king_x++){
for(int king_y=1;king_y<=9;king_y++){
Square king(king_x,king_y);
int king_index=(king_x-1)*9+king_y-1;
const Square center = Centering5x3::adjustCenter(king);
const int min_x = center.x() - 2;
const int min_y = center.y() - 1;
int i=0;
for (int dx=0; dx<5; ++dx)
{
for (int dy=0; dy<3; ++dy,++i)
{
const Square target(min_x+dx,min_y+dy);
int index0=king_index*15+i;
int index_a=index0*10;
int index_d=index0*10;
attack_relative[index_a]=
effect_weight[index<BLACK>(king, target)] +
effect_x_weight[indexX<BLACK>(king, target)] +
effect_y_weight[indexY<BLACK>(king, target)];
defense_relative[index_d]=
effect_defense_weight[index<BLACK>(king, target)];
for(int count=0;count<=8;count++){
attack_relative[index_a+count+1]=
effect_per_effect[indexPerEffect<BLACK>(king, target, count)] +
effect_per_effect_y[indexPerEffectY<BLACK>(king, target, count)] +
effect_per_effect_x[indexPerEffectX<BLACK>(king, target, count)];
defense_relative[index_d+count+1]=
effect_per_effect_defense[indexPerEffect<BLACK>(king, target, count)];
}
}
}
}
}
for(int king_x=1;king_x<=5;king_x++)
for(int promoted=0;promoted<=4;promoted++)
for(int silver=0;silver<=4;silver++)
for(int gold=0;gold<=4;gold++)
for(int bishop=0;bishop<=2;bishop++)
for(int rook=0;rook<=2;rook++){
int index0=promoted + 5 * (silver + 5 * (gold + 5 * (bishop + 3 * rook)));
int index1=king_x - 1 + 5 * (promoted + 5 * (silver + 5 * (gold + 5 * (bishop + 3 * rook))));
attack5x5_x_weight[index1]+=attack5x5_weight[index0];
}
for (int i=0; i<PTYPE_SIZE*2*PTYPE_SIZE; ++i)
for (int j=i+1; j<PTYPE_SIZE*2*PTYPE_SIZE; ++j) {
attacked_ptype_pair_weight[eval::ml::NonPawnAttackedPtypePair::index2(j,i)]
= attacked_ptype_pair_weight[eval::ml::NonPawnAttackedPtypePair::index2(i,j)];
}
// set sum of [1..i] into [i], keep [0] as is.
for (int i=2; i<10; ++i)
pawn_facing_weight[i] += pawn_facing_weight[i-1];
initialized_flag = static_cast<bool>(is);
if (!initialized_flag)
{
std::cerr << "Failed to load NewProgress data " << read_count
<< " from file " << filename << std::endl;
}
return initialized_flag;
}
bool osl::progress::ml::NewProgress::setUp()
{
return setUp(defaultFilename().c_str());
}
std::string osl::progress::ml::NewProgress::defaultFilename()
{
std::string filename = OslConfig::home();
filename += "/data/progress.txt";
return filename;
}
template <osl::Player P>
void osl::progress::ml::NewProgress::progressOne(
const NumEffectState &state, int &attack, int &defense)
{
const Square king = state.kingSquare<P>();
const Square center = Centering5x3::adjustCenter(king);
const int min_x = center.x() - 2;
const int min_y = center.y() - 1;
attack = defense = 0;
Square kingRel=king;
if(P==WHITE){
kingRel=kingRel.rotate180();
}
int index0=((kingRel.x()-1)*9+kingRel.y()-1)*15;
int index_a=index0*10 + (P==WHITE ? 10*14 : 0);
for (int dx=0; dx<5; ++dx)
{
for (int dy=0; dy<3; ++dy)
{
const Square target(min_x+dx,min_y+dy);
const int attack_count =
state.countEffect(alt(P), target);
const int defense_count =
state.countEffect(P, target);
attack += attack_count *attack_relative[index_a]+
attack_relative[index_a+std::min(attack_count,8)+1];
defense +=
defense_count * defense_relative[index_a]+
defense_relative[index_a+std::min(defense_count,8)+1];
if(P==BLACK){
index_a+=10;
}
else{
index_a-=10;
}
}
}
}
template <osl::Player P>
void osl::progress::ml::NewProgress::updateAttack5x5PiecesAndState(
const NumEffectState &state)
{
const Square king = state.kingSquare<P>();
const int min_x = std::max(1, king.x() - 2);
const int max_x = std::min(9, king.x() + 2);
const int min_y = std::max(1, king.y() - 2);
const int max_y = std::min(9, king.y() + 2);
effect_progresses[P] = 0;
PieceMask mask;
for (int y = min_y; y <= max_y; ++y)
{
for (int x = min_x; x <= max_x; ++x)
{
const Square target(x, y);
const NumBitmapEffect effect = state.effectSetAt(target);
const int effect_diff =
effect.countEffect(alt(P)) - effect.countEffect(P);
const int x_diff = std::abs(x - king.x());
const int y_diff = (P == WHITE ? king.y() - y : y - king.y());
int index = std::max(std::min(effect_diff, 2), -2) + 2 + 5 * x_diff +
5 * 3 * (y_diff + 2);
effect_progresses[P] += effectstate_weight[index];
mask |= effect;
}
}
updateAttack5x5Pieces<P>(mask, state);
}
template <osl::Player P>
void osl::progress::ml::NewProgress::updateAttack5x5Pieces(
PieceMask mask, const NumEffectState& state)
{
const Player attack = alt(P);
mask &= state.piecesOnBoard(attack);
rook[attack] = mask.selectBit<ROOK>().countBit();
bishop[attack] = mask.selectBit<BISHOP>().countBit();
gold[attack] = mask.selectBit<GOLD>().countBit();
silver[attack] =
(mask & ~state.promotedPieces()).selectBit<SILVER>().countBit();
PieceMask promoted_pieces = mask & state.promotedPieces();
promoted_pieces.clearBit<ROOK>();
promoted_pieces.clearBit<BISHOP>();
promoted[attack] =
std::min(promoted_pieces.countBit(), 4);
}
template <osl::Player P>
int osl::progress::ml::NewProgress::attack5x5Value(
const NumEffectState &state) const
{
const Player attack = alt(P);
int king_x = state.kingSquare<P>().x();
if (king_x > 5)
king_x = 10 - king_x;
const int king_y = (P == BLACK ? state.kingSquare<P>().y() :
10 - state.kingSquare<P>().y());
return (attack5x5_x_weight[index5x5x(
rook[attack] + state.countPiecesOnStand<ROOK>(attack),
bishop[attack] + state.countPiecesOnStand<BISHOP>(attack),
gold[attack] + state.countPiecesOnStand<GOLD>(attack),
silver[attack] + state.countPiecesOnStand<SILVER>(attack),
promoted[attack], king_x)] +
attack5x5_y_weight[index5x5y(
rook[attack] + state.countPiecesOnStand<ROOK>(attack),
bishop[attack] + state.countPiecesOnStand<BISHOP>(attack),
gold[attack] + state.countPiecesOnStand<GOLD>(attack),
silver[attack] + state.countPiecesOnStand<SILVER>(attack),
promoted[attack], king_y)]);
}
void
osl::progress::ml::NewProgress::updatePieceKingRelativeBonus(
const NumEffectState &state)
{
const CArray<Square,2> kings = {{
state.kingSquare(BLACK),
state.kingSquare(WHITE),
}};
king_relative_attack.fill(0);
king_relative_defense.fill(0);
for (int i = 0; i < Piece::SIZE; ++i)
{
const Piece piece = state.pieceOf(i);
if (piece.ptype() == osl::KING || !piece.isOnBoard())
continue;
Player pl = piece.owner();
const int index_attack = indexRelative(piece.owner(), kings[alt(pl)],
piece);
const int index_defense = indexRelative(piece.owner(), kings[pl],
piece) + 2142;
king_relative_attack[pl] += king_relative_weight[index_attack];
king_relative_defense[pl] += king_relative_weight[index_defense];
}
}
template <osl::Player Owner>
void osl::progress::ml::NewProgress::
updateNonPawnAttackedPtypePairOne(const NumEffectState& state)
{
PieceMask attacked = state.effectedMask(alt(Owner)) & state.piecesOnBoard(Owner);
attacked.reset(state.kingPiece<Owner>().number());
mask_t ppawn = state.promotedPieces().getMask<PAWN>() & attacked.selectBit<PAWN>();
attacked.clearBit<PAWN>();
attacked.orMask(PtypeFuns<PAWN>::indexNum, ppawn);
PieceVector pieces;
while (attacked.any())
{
const Piece piece = state.pieceOf(attacked.takeOneBit());
pieces.push_back(piece);
}
typedef eval::ml::NonPawnAttackedPtypePair feature_t;
int result = 0;
MultiInt result_eval;
for (size_t i=0; i<pieces.size(); ++i) {
const int i0 = feature_t::index1(state, pieces[i]);
result += attacked_ptype_pair_weight[feature_t::index2(0,i0)];
for (size_t j=i+1; j<pieces.size(); ++j) {
const int i1 = feature_t::index1(state, pieces[j]);
result += attacked_ptype_pair_weight[feature_t::index2(i0,i1)];
if (Owner == BLACK)
result_eval += feature_t::table[feature_t::index2(i0, i1)];
else
result_eval -= feature_t::table[feature_t::index2(i0, i1)];
}
}
non_pawn_ptype_attacked_pair[Owner] = result;
non_pawn_ptype_attacked_pair_eval[Owner] = result_eval;
}
void osl::progress::ml::NewProgress::
updateNonPawnAttackedPtypePair(const NumEffectState& state)
{
updateNonPawnAttackedPtypePairOne<BLACK>(state);
updateNonPawnAttackedPtypePairOne<WHITE>(state);
}
void osl::progress::ml::NewProgress::
updatePawnFacing(const NumEffectState& state)
{
PieceMask attacked = state.effectedMask(WHITE) & state.piecesOnBoard(BLACK);
mask_t pawn = attacked.selectBit<PAWN>()
& ~(state.promotedPieces().getMask<PAWN>());
int count = 0;
while (pawn.any()) {
const Piece p(state.pieceOf(pawn.takeOneBit()+PtypeFuns<PAWN>::indexNum*32));
if (state.hasEffectByPtypeStrict<PAWN>(WHITE, p.square()))
++count;
}
pawn_facing = pawn_facing_weight[count];
}
template <osl::Player P>
void osl::progress::ml::
NewProgress::promotion37One(const NumEffectState& state, int rank)
{
typedef eval::ml::Promotion37 feature_t;
CArray<int,PTYPE_SIZE> count = {{ 0 }};
for (int x=1; x<=9; ++x) {
const Square target(x, rank);
if (! state[target].isEmpty())
continue;
int a = state.countEffect(P, target);
const int d = state.countEffect(alt(P), target);
if (a > 0 && a == d)
a += AdditionalEffect::hasEffect(state, target, P);
if (a <= d)
continue;
const Ptype ptype = state.findCheapAttack(P, target).ptype();
if (isPiece(ptype) && ! isPromoted(ptype))
count[ptype]++;
}
for (int p=PTYPE_BASIC_MIN; p<=PTYPE_MAX; ++p) {
if (count[p] > 0) {
promotion37 += promotion37_weight[p];
promotion37_eval += feature_t::table[p]*sign(P);
}
if (count[p] > 1) {
promotion37 += promotion37_weight[p-8]*(count[p]-1);
promotion37_eval += feature_t::table[p-8]*(sign(P)*(count[p]-1));
}
}
}
void osl::progress::ml::NewProgress::
updatePromotion37(const NumEffectState& state)
{
promotion37 = 0;
promotion37_eval = MultiInt();
promotion37One<BLACK>(state, 3);
promotion37One<WHITE>(state, 7);
}
void osl::progress::ml::NewProgress::
updatePieceStand7(const NumEffectState& state)
{
piecestand7 = 0;
for (int z=0; z<2; ++z) {
CArray<int,7> stand = {{ 0 }};
int filled = 0;
for (Ptype ptype: PieceStand::order)
if (state.hasPieceOnStand(indexToPlayer(z), ptype))
stand[filled++] = ptype-PTYPE_BASIC_MIN;
for (int i=0; i<std::min(7,filled+1); ++i)
piecestand7 += piecestand7_weight[stand[i] + 8*i];
}
}
osl::progress::ml::NewProgress::NewProgress(
const NumEffectState &state)
{
assert(initialized_flag);
progressOne<BLACK>(state,
progresses[BLACK],
defenses[WHITE]);
progressOne<WHITE>(state,
progresses[WHITE],
defenses[BLACK]);
updateAttack5x5PiecesAndState<BLACK>(state);
updateAttack5x5PiecesAndState<WHITE>(state);
attack5x5_progresses[BLACK] =
attack5x5Value<BLACK>(state);
attack5x5_progresses[WHITE] =
attack5x5Value<WHITE>(state);
stand_progresses.fill(0);
for (Ptype ptype: PieceStand::order)
{
const int black_count =
state.countPiecesOnStand(BLACK, ptype);
const int white_count =
state.countPiecesOnStand(WHITE, ptype);
for (int j = 0; j < black_count; ++j)
{
stand_progresses[WHITE] +=
stand_weight[Ptype_Table.getIndexMin(ptype) + j];
}
for (int j = 0; j < white_count; ++j)
{
stand_progresses[BLACK] +=
stand_weight[Ptype_Table.getIndexMin(ptype) + j];
}
}
updatePieceKingRelativeBonus(state);
updateNonPawnAttackedPtypePair(state);
updatePawnFacing(state);
updatePromotion37(state);
updatePieceStand7(state);
}
template<osl::Player P>
inline
void osl::progress::ml::NewProgress::updateMain(
const NumEffectState &new_state,
Move last_move)
{
const Player altP=alt(P);
assert(new_state.turn()==altP);
assert(last_move.player()==P);
const Square kb = new_state.kingSquare<BLACK>(), kw = new_state.kingSquare<WHITE>();
const BoardMask mb = new_state.changedEffects(BLACK), mw = new_state.changedEffects(WHITE);
const bool king_move = last_move.ptype() == KING;
if ((king_move && altP == BLACK) || mb.anyInRange(Board_Mask_Table5x3_Center.mask(kw)) || mw.anyInRange(Board_Mask_Table5x3_Center.mask(kw)))
{
progressOne<WHITE>(new_state,progresses[WHITE],defenses[BLACK]);
}
if ((king_move && altP == WHITE) || mw.anyInRange(Board_Mask_Table5x3_Center.mask(kb)) || mb.anyInRange(Board_Mask_Table5x3_Center.mask(kb)))
{
progressOne<BLACK>(new_state,progresses[BLACK],defenses[WHITE]);
}
const Ptype captured = last_move.capturePtype();
if (last_move.isDrop())
{
const int count =
new_state.countPiecesOnStand(P, last_move.ptype()) + 1;
const int value =
stand_weight[Ptype_Table.getIndexMin(last_move.ptype()) + count - 1];
stand_progresses[altP] -= value;
}
else if (captured != PTYPE_EMPTY)
{
Ptype ptype = unpromote(captured);
const int count = new_state.countPiecesOnStand(P, ptype);
const int value =
stand_weight[(Ptype_Table.getIndexMin(ptype) + count - 1)];
stand_progresses[altP] += value;
}
if (king_move)
{
updatePieceKingRelativeBonus(new_state);
}
else
{
const CArray<Square,2> kings = {{
new_state.kingSquare(BLACK),
new_state.kingSquare(WHITE),
}};
if (!last_move.isDrop())
{
const int index_attack =
indexRelative<P>(kings[altP],
last_move.oldPtype(), last_move.from());
const int index_defense =
indexRelative<P>(kings[P],
last_move.oldPtype(), last_move.from()) + 2142;
king_relative_attack[P] -=
king_relative_weight[index_attack];
king_relative_defense[P] -=
king_relative_weight[index_defense];
}
{
const int index_attack =
indexRelative<P>(kings[altP],
last_move.ptype(), last_move.to());
const int index_defense =
indexRelative<P>(kings[P],
last_move.ptype(), last_move.to()) + 2142;
king_relative_attack[P] +=
king_relative_weight[index_attack];
king_relative_defense[P] +=
king_relative_weight[index_defense];
}
if (captured != PTYPE_EMPTY)
{
const int index_attack =
indexRelative<altP>(kings[P],
captured, last_move.to());
const int index_defense =
indexRelative<altP>(kings[altP],
captured, last_move.to()) + 2142;
king_relative_attack[altP] -=
king_relative_weight[index_attack];
king_relative_defense[altP] -=
king_relative_weight[index_defense];
}
}
updateNonPawnAttackedPtypePair(new_state);
updatePawnFacing(new_state);
updatePromotion37(new_state);
updatePieceStand7(new_state);
}
template<osl::Player P>
void osl::progress::ml::NewProgress::updateSub(
const NumEffectState &new_state,
Move last_move)
{
const Player altP=alt(P);
assert(new_state.turn()==altP);
if (last_move.isPass())
return;
const Square kb = new_state.kingSquare<BLACK>(), kw = new_state.kingSquare<WHITE>();
const BoardMask mb = new_state.changedEffects(BLACK), mw = new_state.changedEffects(WHITE);
const bool king_move = last_move.ptype() == KING;
const Ptype captured = last_move.capturePtype();
if ((king_move && altP == BLACK) ||
mb.anyInRange(Board_Mask_Table5x5.mask(kw)) ||
mw.anyInRange(Board_Mask_Table5x5.mask(kw)))
{
updateAttack5x5PiecesAndState<WHITE>(new_state);
attack5x5_progresses[WHITE] =
attack5x5Value<WHITE>(new_state);
}
else if (altP == WHITE &&(last_move.isDrop() || captured != PTYPE_EMPTY))
{
attack5x5_progresses[WHITE] =
attack5x5Value<WHITE>(new_state);
}
if ((king_move && altP == WHITE) ||
mw.anyInRange(Board_Mask_Table5x5.mask(kb)) ||
mb.anyInRange(Board_Mask_Table5x5.mask(kb)))
{
updateAttack5x5PiecesAndState<BLACK>(new_state);
attack5x5_progresses[BLACK] =
attack5x5Value<BLACK>(new_state);
}
else if (altP == BLACK && (last_move.isDrop() || captured != PTYPE_EMPTY))
{
attack5x5_progresses[BLACK] =
attack5x5Value<BLACK>(new_state);
}
updateMain<P>(new_state, last_move);
}
osl::progress::ml::NewProgressDebugInfo osl::progress::ml::NewProgress::debugInfo() const
{
NewProgressDebugInfo info;
info.black_values[NewProgressDebugInfo::ATTACK_5X3] = progresses[0];
info.black_values[NewProgressDebugInfo::DEFENSE_5X3] = defenses[0];
info.black_values[NewProgressDebugInfo::ATTACK5X5] = attack5x5_progresses[0];
info.black_values[NewProgressDebugInfo::STAND] = stand_progresses[0];
info.black_values[NewProgressDebugInfo::EFFECT5X5] = effect_progresses[0];
info.black_values[NewProgressDebugInfo::KING_RELATIVE_ATTACK] = king_relative_attack[0];
info.black_values[NewProgressDebugInfo::KING_RELATIVE_DEFENSE] = king_relative_defense[0];
info.black_values[NewProgressDebugInfo::NON_PAWN_ATTACKED_PAIR] = non_pawn_ptype_attacked_pair[0];
info.white_values[NewProgressDebugInfo::ATTACK_5X3] = progresses[1];
info.white_values[NewProgressDebugInfo::DEFENSE_5X3] = defenses[1];
info.white_values[NewProgressDebugInfo::ATTACK5X5] = attack5x5_progresses[1];
info.white_values[NewProgressDebugInfo::STAND] = stand_progresses[1];
info.white_values[NewProgressDebugInfo::EFFECT5X5] = effect_progresses[1];
info.white_values[NewProgressDebugInfo::KING_RELATIVE_ATTACK] = king_relative_attack[1];
info.white_values[NewProgressDebugInfo::KING_RELATIVE_DEFENSE] = king_relative_defense[1];
info.white_values[NewProgressDebugInfo::NON_PAWN_ATTACKED_PAIR] = non_pawn_ptype_attacked_pair[1];
return info;
}
namespace osl
{
namespace progress
{
namespace ml
{
template void osl::progress::ml::NewProgress::updateSub<osl::BLACK>(const NumEffectState &new_state,Move last_move);
template void osl::progress::ml::NewProgress::updateSub<osl::WHITE>(const NumEffectState &new_state,Move last_move);
}
}
}
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
additionalEffect.h
centering5x3.h
osl::CArray
Definition container.h:20
osl::FixedCapacityVector::size
size_t size() const
Definition container.h:243
osl::FixedCapacityVector::push_back
void push_back(const T &e)
Definition container.h:204
osl::Move
圧縮していない moveの表現 .
Definition basic_type.h:1052
osl::Move::ptype
Ptype ptype() const
Definition basic_type.h:1155
osl::Move::player
Player player() const
Definition basic_type.h:1195
osl::Move::isDrop
bool isDrop() const
Definition basic_type.h:1150
osl::Move::isPass
bool isPass() const
Definition basic_type.h:1092
osl::Move::capturePtype
Ptype capturePtype() const
Definition basic_type.h:1180
osl::Move::oldPtype
Ptype oldPtype() const
移動前のPtype, i.e., 成る手だった場合成る前
Definition basic_type.h:1174
osl::Move::to
const Square to() const
Definition basic_type.h:1132
osl::Move::from
const Square from() const
Definition basic_type.h:1125
osl::NumEffectState
利きを持つ局面
Definition numEffectState.h:34
osl::NumEffectState::effectSetAt
const NumBitmapEffect effectSetAt(Square sq) const
Definition numEffectState.h:258
osl::NumEffectState::changedEffects
const BoardMask changedEffects(Player pl) const
Definition numEffectState.h:144
osl::NumEffectState::effectedMask
const PieceMask effectedMask(Player pl) const
pl からの利きが(1つ以上)ある駒一覧
Definition numEffectState.h:130
osl::NumEffectState::countEffect
int countEffect(Player player, Square target) const
利きの数を数える.
Definition numEffectState.h:266
osl::NumEffectState::findCheapAttack
const Piece findCheapAttack(Player P, Square square) const
Definition numEffectState.h:560
osl::NumEffectState::promotedPieces
const PieceMask promotedPieces() const
Definition numEffectState.h:64
osl::NumEffectState::piecesOnBoard
const PieceMask & piecesOnBoard(Player p) const
Definition numEffectState.h:63
osl::NumEffectState::hasEffectByPtypeStrict
bool hasEffectByPtypeStrict(Player attack, Square target) const
target に ptype の利きがあるか?
Definition numEffectState.h:363
osl::PieceMask
駒番号のビットセット.
Definition pieceMask.h:21
osl::PieceMask::getMask
const mask_t getMask(int num) const
Definition pieceMask.h:59
osl::PieceMask::clearBit
void clearBit()
unpromote(PTYPE) の駒のbit を消す
Definition pieceMask.h:74
osl::PieceMask::orMask
void orMask(int index, mask_t val)
Definition pieceMask.h:42
osl::PieceMask::any
bool any() const
Definition pieceMask.h:57
osl::PieceMask::selectBit
const mask_t selectBit() const
unpromote(PTYPE) の駒のbit だけ取り出す
Definition pieceMask.h:66
osl::PieceMask::reset
void reset(int num)
Definition pieceMask.h:54
osl::PieceStand::order
static const CArray< Ptype, 7 > order
持駒の表示で良く使われる順番.
Definition bits/pieceStand.h:41
osl::PieceVector
Definition container.h:305
osl::Piece
駒.
Definition basic_type.h:788
osl::Piece::ptype
Ptype ptype() const
Definition basic_type.h:821
osl::Piece::square
const Square square() const
Definition basic_type.h:832
osl::Piece::owner
Player owner() const
Definition basic_type.h:963
osl::Piece::number
int number() const
Definition basic_type.h:828
osl::Piece::isOnBoard
bool isOnBoard() const
Definition basic_type.h:985
osl::Piece::SIZE
static const int SIZE
Definition basic_type.h:794
osl::SimpleState::hasPieceOnStand
bool hasPieceOnStand(Player player, Ptype ptype) const
Definition simpleState.h:191
osl::SimpleState::kingPiece
const Piece kingPiece() const
Definition simpleState.h:83
osl::SimpleState::turn
Player turn() const
Definition simpleState.h:220
osl::SimpleState::pieceOf
const Piece pieceOf(int num) const
Definition simpleState.h:76
osl::SimpleState::kingSquare
Square kingSquare() const
Definition simpleState.h:94
osl::SimpleState::countPiecesOnStand
int countPiecesOnStand(Player pl, Ptype ptype) const
持駒の枚数を数える
Definition simpleState.h:182
osl::Square
Definition basic_type.h:532
osl::Square::y
int y() const
将棋としてのY座標を返す.
Definition basic_type.h:567
osl::Square::rotate180
const Square rotate180() const
Definition basic_type.h:613
osl::Square::x
int x() const
将棋としてのX座標を返す.
Definition basic_type.h:563
osl::container::BoardMask
11 x 12
Definition boardMask.h:21
osl::container::BoardMask::anyInRange
bool anyInRange(const BoardMask &mask) const
Definition boardMask.h:57
osl::container::PieceMask64::takeOneBit
int takeOneBit()
Definition pieceMask64.h:82
osl::container::PieceMask64::countBit
int countBit() const
Definition pieceMask64.h:78
osl::effect::NumBitmapEffect
現在の定義 (2005/3/4以降)
Definition numBitmapEffect.h:29
osl::eval::ml::NonPawnAttackedPtypePair
Definition minorPiece.h:1348
osl::eval::ml::NonPawnAttackedPtypePair::index2
static int index2(int i0, int i1)
Definition minorPiece.h:1367
osl::eval::ml::Promotion37
Definition minorPiece.h:1724
osl::misc::GeneralMask::any
bool any() const
Definition mask.h:298
osl::misc::GeneralMask::takeOneBit
int takeOneBit()
non-zeroのmaskのsetされているビットをLSBから探し，その番号を返す 副作用としてmaskの対応するビットをクリアする
Definition mask.h:265
osl::progress::ml::NewProgress::ProgressScale
@ ProgressScale
Definition progress.h:78
osl::progress::ml::NewProgress::updateMain
void updateMain(const NumEffectState &new_state, Move last_move)
Definition progress.cc:590
osl::progress::ml::NewProgress::attack5x5_x_weight
static CArray< int, 5625 > attack5x5_x_weight
Definition progress.h:83
osl::progress::ml::NewProgress::index5x5x
static int index5x5x(int rook, int bishop, int gold, int silver, int promoted, int king_x)
Definition progress.h:152
osl::progress::ml::NewProgress::indexRelative
static int indexRelative(const Square king, const Ptype ptype, const Square pos)
Definition progress.h:201
osl::progress::ml::NewProgress::updatePawnFacing
void updatePawnFacing(const NumEffectState &state)
Definition progress.cc:476
osl::progress::ml::NewProgress::promotion37One
void promotion37One(const NumEffectState &state, int rank)
Definition progress.cc:492
osl::progress::ml::NewProgress::updateAttack5x5PiecesAndState
void updateAttack5x5PiecesAndState(const NumEffectState &state)
Definition progress.cc:336
osl::progress::ml::NewProgress::effectstate_weight
static CArray< int, 75 > effectstate_weight
Definition progress.h:85
osl::progress::ml::NewProgress::setUp
static bool setUp()
Definition progress.cc:283
osl::progress::ml::NewProgress::progressOne
static void progressOne(const NumEffectState &state, int &attack, int &defense)
Definition progress.cc:296
osl::progress::ml::NewProgress::index5x5y
static int index5x5y(int rook, int bishop, int gold, int silver, int promoted, int king_y)
Definition progress.h:159
osl::progress::ml::NewProgress::updateSub
void updateSub(const NumEffectState &new_state, Move last_move)
Definition progress.cc:684
osl::progress::ml::NewProgress::promotion37_weight
static CArray< int, 16 > promotion37_weight
Definition progress.h:91
osl::progress::ml::NewProgress::updateAttack5x5Pieces
void updateAttack5x5Pieces(PieceMask, const NumEffectState &)
Definition progress.cc:367
osl::progress::ml::NewProgress::pawn_facing_weight
static CArray< int, 10 > pawn_facing_weight
Definition progress.h:90
osl::progress::ml::NewProgress::max_progress
static int max_progress
Definition progress.h:93
osl::progress::ml::NewProgress::indexPerEffectX
static int indexPerEffectX(Square king, Square target, int count)
Definition progress.h:187
osl::progress::ml::NewProgress::defense_relative
static CArray< int, 81 *15 *10 > defense_relative
Definition progress.h:87
osl::progress::ml::NewProgress::NewProgress
NewProgress(const NumEffectState &state)
Definition progress.cc:546
osl::progress::ml::NewProgress::defaultFilename
static std::string defaultFilename()
Definition progress.cc:288
osl::progress::ml::NewProgress::indexY
static int indexY(Square king, Square target)
Definition progress.h:138
osl::progress::ml::NewProgress::attack5x5Value
int attack5x5Value(const NumEffectState &state) const
Definition progress.cc:386
osl::progress::ml::NewProgress::setUp
static bool setUp(const char *filename)
Definition progress.cc:54
osl::progress::ml::NewProgress::indexPerEffectY
static int indexPerEffectY(Square king, Square target, int count)
Definition progress.h:177
osl::progress::ml::NewProgress::updateNonPawnAttackedPtypePairOne
void updateNonPawnAttackedPtypePairOne(const NumEffectState &state)
Definition progress.cc:436
osl::progress::ml::NewProgress::indexX
static int indexX(Square king, Square target)
Definition progress.h:121
osl::progress::ml::NewProgress::index
static int index(Square king, Square target)
Definition progress.h:113
osl::progress::ml::NewProgress::piecestand7_weight
static CArray< int, 56 > piecestand7_weight
Definition progress.h:92
osl::progress::ml::NewProgress::updatePromotion37
void updatePromotion37(const NumEffectState &state)
Definition progress.cc:523
osl::progress::ml::NewProgress::attacked_ptype_pair_weight
static CArray< int, 262144 > attacked_ptype_pair_weight
Definition progress.h:89
osl::progress::ml::NewProgress::updatePieceKingRelativeBonus
void updatePieceKingRelativeBonus(const NumEffectState &state)
Definition progress.cc:410
osl::progress::ml::NewProgress::updatePieceStand7
void updatePieceStand7(const NumEffectState &state)
Definition progress.cc:532
osl::progress::ml::NewProgress::indexPerEffect
static int indexPerEffect(Square king, Square target, int count)
Definition progress.h:167
osl::progress::ml::NewProgress::attack5x5_weight
static CArray< int, 1125 > attack5x5_weight
Definition progress.h:82
osl::progress::ml::NewProgress::attack_relative
static CArray< int, 81 *15 *10 > attack_relative
Definition progress.h:86
osl::progress::ml::NewProgress::stand_weight
static CArray< int, Piece::SIZE > stand_weight
Definition progress.h:81
osl::progress::ml::NewProgress::updateNonPawnAttackedPtypePair
void updateNonPawnAttackedPtypePair(const NumEffectState &state)
Definition progress.cc:469
osl::progress::ml::NewProgress::initialized_flag
static bool initialized_flag
Definition progress.h:80
osl::progress::ml::NewProgress::king_relative_weight
static CArray< int, 4284 > king_relative_weight
Definition progress.h:88
osl::progress::ml::NewProgress::attack5x5_y_weight
static CArray< int, 10125 > attack5x5_y_weight
Definition progress.h:84
osl::progress::ml::NewProgress::debugInfo
NewProgressDebugInfo debugInfo() const
Definition progress.cc:726
midgame.h
minorPiece.h
osl::effect
Definition effectedNumTable.h:8
osl::misc::mask_t
GeneralMask< mask_int_t > mask_t
Definition mask.h:351
osl::progress::ml
Definition progress.cc:756
osl::progress::ml::operator==
bool operator==(const NewProgressData &l, const NewProgressData &r)
Definition progress.cc:12
osl::progress
Definition progress.cc:754
osl
Definition additionalEffect.h:6
osl::Ptype
Ptype
駒の種類を4ビットでコード化する
Definition basic_type.h:84
osl::PTYPE_MAX
@ PTYPE_MAX
Definition basic_type.h:105
osl::ROOK
@ ROOK
Definition basic_type.h:100
osl::BISHOP
@ BISHOP
Definition basic_type.h:99
osl::PAWN
@ PAWN
Definition basic_type.h:95
osl::KING
@ KING
Definition basic_type.h:93
osl::PTYPE_EMPTY
@ PTYPE_EMPTY
Definition basic_type.h:85
osl::SILVER
@ SILVER
Definition basic_type.h:98
osl::PTYPE_BASIC_MIN
@ PTYPE_BASIC_MIN
Definition basic_type.h:103
osl::GOLD
@ GOLD
Definition basic_type.h:94
osl::Ptype_Table
const PtypeTable Ptype_Table
Definition tables.cc:97
osl::PTYPE_SIZE
const int PTYPE_SIZE
Definition basic_type.h:107
osl::indexToPlayer
constexpr Player indexToPlayer(int n)
Definition basic_type.h:19
osl::Board_Mask_Table5x5
const BoardMaskTable5x5 Board_Mask_Table5x5
Definition tables.cc:119
osl::unpromote
Ptype unpromote(Ptype ptype)
ptypeがpromote後の型の時に，promote前の型を返す． promoteしていない型の時はそのまま返す
Definition basic_type.h:157
osl::isPromoted
bool isPromoted(Ptype ptype)
ptypeがpromote後の型かどうかのチェック
Definition basic_type.h:137
osl::MultiInt
QuadInt MultiInt
Definition midgame.h:13
osl::sign
constexpr int sign(Player player)
Definition basic_type.h:23
osl::Player
Player
Definition basic_type.h:8
osl::WHITE
@ WHITE
Definition basic_type.h:10
osl::BLACK
@ BLACK
Definition basic_type.h:9
osl::isPiece
constexpr bool isPiece(Ptype ptype)
ptypeが空白やEDGEでないかのチェック
Definition basic_type.h:120
osl::Board_Mask_Table5x3_Center
const BoardMaskTable5x3Center Board_Mask_Table5x3_Center
Definition tables.cc:121
osl::alt
constexpr Player alt(Player player)
Definition basic_type.h:13
osl::captured
PtypeO captured(PtypeO ptypeO)
unpromoteすると共に，ownerを反転する．
Definition basic_type.h:264
oslConfig.h
progress.h
osl::AdditionalEffect::hasEffect
static bool hasEffect(const NumEffectState &, Square target, Player attack)
target に attack の追加利きが一つでもあるか． 相手の影利きが先にある場合は対象としない．
Definition additionalEffect.cc:5
osl::Centering5x3::adjustCenter
static const Square adjustCenter(Square src)
Definition centering5x3.h:23
osl::OslConfig::home
static const std::string & home(const std::string &initialize_if_first_invocation="")
compile時に指定されたディレクトリを返す.
Definition oslConfig.cc:239
osl::PtypeFuns
Definition ptypeTraits.h:311
osl::eval::ml::Weights
Definition weights.h:18
osl::eval::ml::Weights::dimension
size_t dimension() const
Definition weights.h:29
osl::eval::ml::Weights::resetDimension
void resetDimension(size_t new_dim)
Definition weights.cc:26
osl::progress::ml::NewProgressData
Definition progress.h:66
osl::progress::ml::NewProgressData::effect_progresses
CArray< int, 2 > effect_progresses
Definition progress.h:70
osl::progress::ml::NewProgressData::bishop
CArray< int, 2 > bishop
Definition progress.h:71
osl::progress::ml::NewProgressData::promotion37
int promotion37
Definition progress.h:73
osl::progress::ml::NewProgressData::gold
CArray< int, 2 > gold
Definition progress.h:71
osl::progress::ml::NewProgressData::progresses
CArray< int, 2 > progresses
Definition progress.h:69
osl::progress::ml::NewProgressData::non_pawn_ptype_attacked_pair_eval
CArray< MultiInt, 2 > non_pawn_ptype_attacked_pair_eval
Definition progress.h:67
osl::progress::ml::NewProgressData::rook
CArray< int, 2 > rook
Definition progress.h:71
osl::progress::ml::NewProgressData::piecestand7
int piecestand7
Definition progress.h:73
osl::progress::ml::NewProgressData::pawn_facing
int pawn_facing
Definition progress.h:73
osl::progress::ml::NewProgressData::non_pawn_ptype_attacked_pair
CArray< int, 2 > non_pawn_ptype_attacked_pair
Definition progress.h:72
osl::progress::ml::NewProgressData::king_relative_defense
CArray< int, 2 > king_relative_defense
Definition progress.h:72
osl::progress::ml::NewProgressData::promoted
CArray< int, 2 > promoted
Definition progress.h:71
osl::progress::ml::NewProgressData::attack5x5_progresses
CArray< int, 2 > attack5x5_progresses
Definition progress.h:69
osl::progress::ml::NewProgressData::king_relative_attack
CArray< int, 2 > king_relative_attack
Definition progress.h:72
osl::progress::ml::NewProgressData::promotion37_eval
MultiInt promotion37_eval
Definition progress.h:68
osl::progress::ml::NewProgressData::defenses
CArray< int, 2 > defenses
Definition progress.h:70
osl::progress::ml::NewProgressData::silver
CArray< int, 2 > silver
Definition progress.h:71
osl::progress::ml::NewProgressData::stand_progresses
CArray< int, 2 > stand_progresses
Definition progress.h:69
osl::progress::ml::NewProgressDebugInfo
Definition progress.h:48
osl::progress::ml::NewProgressDebugInfo::black_values
CArray< int, FEATURE_LIMIT > black_values
Definition progress.h:61
osl::progress::ml::NewProgressDebugInfo::DEFENSE_5X3
@ DEFENSE_5X3
Definition progress.h:52
osl::progress::ml::NewProgressDebugInfo::ATTACK_5X3
@ ATTACK_5X3
Definition progress.h:51
osl::progress::ml::NewProgressDebugInfo::KING_RELATIVE_DEFENSE
@ KING_RELATIVE_DEFENSE
Definition progress.h:57
osl::progress::ml::NewProgressDebugInfo::ATTACK5X5
@ ATTACK5X5
Definition progress.h:53
osl::progress::ml::NewProgressDebugInfo::NON_PAWN_ATTACKED_PAIR
@ NON_PAWN_ATTACKED_PAIR
Definition progress.h:58
osl::progress::ml::NewProgressDebugInfo::EFFECT5X5
@ EFFECT5X5
Definition progress.h:55
osl::progress::ml::NewProgressDebugInfo::KING_RELATIVE_ATTACK
@ KING_RELATIVE_ATTACK
Definition progress.h:56
osl::progress::ml::NewProgressDebugInfo::STAND
@ STAND
Definition progress.h:54
osl::progress::ml::NewProgressDebugInfo::white_values
CArray< int, FEATURE_LIMIT > white_values
Definition progress.h:62
weights.h