libertyEstimator.h
Go to the documentation of this file.
/* libertyEstimator.h
*/
#ifndef _LIBERTYESTIMATOR_H
#define _LIBERTYESTIMATOR_H
#include "osl/checkmate/proofNumberTable.h"
namespace osl
{
namespace checkmate
{
struct PureLibertyEstimator
{
template <class State>
static void attackH(Player attacker, const State& state,
King8Info info, Move move,
unsigned int& proof_number,
unsigned int& disproof_number)
{
const Player defender = alt(attacker);
const Square king_position = state.kingSquare(defender);
proof_number = Proof_Number_Table.countLiberty
(state, info.libertyCount(), move, king_position, info);
disproof_number = 1;
}
template <class State>
static void defenseH(Player /*attacker*/, const State&, Move /*move*/,
unsigned int& proof_number,
unsigned int& disproof_number)
{
proof_number = 1;
disproof_number = 1;
}
};
struct LibertyEstimator
{
template <class State>
static void attackH(Player attacker, const State&, King8Info, Move move,
unsigned int& proof_number, unsigned int& disproof_number);
template <class State>
static void defenseH(Player attacker, const State&, Move move,
unsigned int& proof_number, unsigned int& disproof_number);
};
} // namespace checkmate
} // namespace osl
template<typename State>
void osl::checkmate::LibertyEstimator::
attackH(Player attacker, const State& state, King8Info info, Move move,
unsigned int& proof_number, unsigned int& disproof_number)
{
const Player defender = alt(attacker);
PureLibertyEstimator::attackH
(attacker, state, info, move, proof_number, disproof_number);
// 功罪はあるが，速くなる問題の方が多そう
if (state.hasMultipleEffectAt(defender, move.to()))
++proof_number;
const Square from=move.from();
const Square to=move.to();
const int attack_support = state.countEffect(attacker,to);
const int defense_support = state.countEffect(defender,to);
if ((attack_support + (from.isPieceStand() ? 1 : 0)) > defense_support)
{
disproof_number=2;
}
else if (move.capturePtype()!=PTYPE_EMPTY)
{
Ptype capturePtype=unpromote(move.capturePtype());
if ((capturePtype == SILVER)
|| (capturePtype == GOLD))
{
disproof_number=2;
}
else
{
proof_number+=1;
disproof_number=1;
}
}
else
{
proof_number+=1;
disproof_number=1;
}
}
template<typename State>
void osl::checkmate::LibertyEstimator::
defenseH(Player attacker, const State& state, Move move,
unsigned int& proof_number, unsigned int& disproof_number)
{
if (move.capturePtype()!=PTYPE_EMPTY)
{
proof_number=2;
disproof_number=1;
return;
}
if (move.ptype()==KING)
{
proof_number=1;
disproof_number=1;
return;
}
const Square to = move.to();
if ((state.countEffect(attacker,to) + (move.isDrop() ? 1 : 0))
<= state.countEffect(alt(attacker),to))
{
proof_number=2;
disproof_number=1;
return;
}
proof_number=1;
disproof_number = 2;
}
#endif /* _LIBERTYESTIMATOR_H */
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
osl::Move
圧縮していない moveの表現 .
Definition basic_type.h:1052
osl::Move::ptype
Ptype ptype() const
Definition basic_type.h:1155
osl::Move::isDrop
bool isDrop() const
Definition basic_type.h:1150
osl::Move::capturePtype
Ptype capturePtype() const
Definition basic_type.h:1180
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::Square
Definition basic_type.h:532
osl::Square::isPieceStand
bool isPieceStand() const
Definition basic_type.h:576
osl::checkmate::King8Info
敵玉の8近傍の状態を表す.
Definition king8Info.h:29
osl::checkmate::King8Info::libertyCount
unsigned int libertyCount() const
libertyの数
Definition king8Info.h:82
osl::checkmate
Definition king8Info.h:12
osl::checkmate::Proof_Number_Table
ProofNumberTable Proof_Number_Table
Definition proofNumberTable.cc:10
osl
Definition additionalEffect.h:6
osl::Ptype
Ptype
駒の種類を4ビットでコード化する
Definition basic_type.h:84
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::GOLD
@ GOLD
Definition basic_type.h:94
osl::unpromote
Ptype unpromote(Ptype ptype)
ptypeがpromote後の型の時に，promote前の型を返す． promoteしていない型の時はそのまま返す
Definition basic_type.h:157
osl::Player
Player
Definition basic_type.h:8
osl::alt
constexpr Player alt(Player player)
Definition basic_type.h:13
proofNumberTable.h
osl::checkmate::LibertyEstimator
玉の動ける場所を基本としたHの推定.
Definition libertyEstimator.h:43
osl::checkmate::LibertyEstimator::attackH
static void attackH(Player attacker, const State &, King8Info, Move move, unsigned int &proof_number, unsigned int &disproof_number)
攻撃側の move に対する proof_number と disproof_number を予想する
Definition libertyEstimator.h:61
osl::checkmate::LibertyEstimator::defenseH
static void defenseH(Player attacker, const State &, Move move, unsigned int &proof_number, unsigned int &disproof_number)
防御側の move に対する proof_number と disproof_number を予想する
Definition libertyEstimator.h:105
osl::checkmate::PureLibertyEstimator
Definition libertyEstimator.h:13
osl::checkmate::PureLibertyEstimator::attackH
static void attackH(Player attacker, const State &state, King8Info info, Move move, unsigned int &proof_number, unsigned int &disproof_number)
Definition libertyEstimator.h:16
osl::checkmate::PureLibertyEstimator::defenseH
static void defenseH(Player, const State &, Move, unsigned int &proof_number, unsigned int &disproof_number)
Definition libertyEstimator.h:29