additionalEffect.cc
Go to the documentation of this file.
#include "osl/additionalEffect.h"
#include "osl/bits/additionalOrShadow.h"
bool osl::effect_util::
AdditionalEffect::hasEffect(const NumEffectState& state, Square target,
Player attack)
{
PieceMask direct = state.effectSetAt(target) & state.piecesOnBoard(attack);
PieceMask mask;
mask.setAll();
mask.clearBit<KNIGHT>();
direct &= (state.promotedPieces() | mask);
while (direct.any()) {
const int num = direct.takeOneBit();
const Square p = state.pieceOf(num).square();
const Direction d=Board_Table.getShort8<BLACK>(p,target);
const int num1=state.longEffectNumTable()[num][d];
if(!Piece::isEmptyNum(num1) && state.pieceOf(num1).owner()==attack) return true;
}
return false;
}
template <int count_max>
int osl::effect_util::
AdditionalEffect::count(const NumEffectState& state, Square target,
Player attack)
{
PieceVector direct_pieces;
state.findEffect(attack, target, direct_pieces);
return AdditionalOrShadow::count<count_max>
(direct_pieces, state, target, attack);
}
bool osl::effect_util::
AdditionalEffect::hasEffectStable(const NumEffectState& state, Square target,
Player attack)
{
return count<1>(state, target, attack);
}
int osl::effect_util::
AdditionalEffect::count2(const NumEffectState& state, Square target,
Player attack)
{
return count<2>(state, target, attack);
}
void osl::effect_util::
AdditionalEffect::find(const NumEffectState& state, Square target,
const PieceVector& direct_effects,
PieceVector& black, PieceVector& white)
{
for (Piece p: direct_effects)
{
const Square from = p.square();
const Offset32 diff32 = Offset32(from, target);
const Offset step = Board_Table.getShortOffsetNotKnight(diff32);
if (step.zero())
continue;
// 利きが8方向の場合
Piece candidate=state.nextPiece(from, step);
if (! candidate.isPiece())
continue;
const Offset32 diff_reverse = Offset32(target,candidate.square());
for (; candidate.isPiece();
candidate=state.nextPiece(candidate.square(), step))
{
const EffectContent effect
= Ptype_Table.getEffect(candidate.ptypeO(), diff_reverse);
if (! effect.hasEffect())
break;
if (candidate.owner() == BLACK)
black.push_back(candidate);
else
white.push_back(candidate);
}
}
}
void osl::effect_util::
AdditionalEffect::find(const NumEffectState& state, Square target,
PieceVector& black, PieceVector& white)
{
PieceVector direct_pieces;
state.findEffect(BLACK, target, direct_pieces);
find(state, target, direct_pieces, black, white);
direct_pieces.clear();
state.findEffect(WHITE, target, direct_pieces);
find(state, target, direct_pieces, black, white);
}
void osl::effect_util::
AdditionalEffect::count(const NumEffectState& state, Square target,
int& black, int& white)
{
PieceVector black_pieces, white_pieces;
find(state, target, black_pieces, white_pieces);
black = black_pieces.size();
white = white_pieces.size();
}
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
additionalEffect.h
additionalOrShadow.h
osl::EffectContent
Definition effectContent.h:11
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::FixedCapacityVector::clear
void clear()
Definition container.h:215
osl::NumEffectState
利きを持つ局面
Definition numEffectState.h:34
osl::NumEffectState::effectSetAt
const NumBitmapEffect effectSetAt(Square sq) const
Definition numEffectState.h:258
osl::NumEffectState::longEffectNumTable
const EffectedNumTable & longEffectNumTable() const
Definition numEffectState.h:124
osl::NumEffectState::promotedPieces
const PieceMask promotedPieces() const
Definition numEffectState.h:64
osl::NumEffectState::findEffect
void findEffect(Player P, Square target, PieceVector &out) const
target に利きのあるPieceをoutに格納する
Definition numEffectState.cc:1119
osl::NumEffectState::piecesOnBoard
const PieceMask & piecesOnBoard(Player p) const
Definition numEffectState.h:63
osl::Offset
座標の差分
Definition basic_type.h:430
osl::Offset::zero
bool zero() const
Definition basic_type.h:502
osl::PieceMask
駒番号のビットセット.
Definition pieceMask.h:21
osl::PieceMask::clearBit
void clearBit()
unpromote(PTYPE) の駒のbit を消す
Definition pieceMask.h:74
osl::PieceMask::any
bool any() const
Definition pieceMask.h:57
osl::PieceVector
Definition container.h:305
osl::Piece
駒.
Definition basic_type.h:788
osl::Piece::ptypeO
PtypeO ptypeO() const
Definition basic_type.h:824
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::isPiece
bool isPiece() const
Definition basic_type.h:953
osl::Piece::isEmptyNum
static bool isEmptyNum(int num)
Definition basic_type.h:916
osl::SimpleState::nextPiece
Piece nextPiece(Square cur, Offset diff) const
diff方向にあるPiece を求める.
Definition simpleState.h:208
osl::SimpleState::pieceOf
const Piece pieceOf(int num) const
Definition simpleState.h:76
osl::Square
Definition basic_type.h:532
osl::Square::square
unsigned int square
Definition basic_type.h:533
osl::container::PieceMask64::takeOneBit
int takeOneBit()
Definition pieceMask64.h:82
osl::container::PieceMask64::setAll
void setAll()
Definition pieceMask64.h:28
osl::effect
Definition effectedNumTable.h:8
osl::KNIGHT
@ KNIGHT
Definition basic_type.h:97
osl::Ptype_Table
const PtypeTable Ptype_Table
Definition tables.cc:97
osl::Board_Table
const BoardTable Board_Table
Definition tables.cc:95
osl::Direction
Direction
Definition basic_type.h:310
osl::Offset32
Offset32Base< 8, 9 > Offset32
Definition offset32.h:63
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::effect_util::AdditionalEffect::hasEffectStable
static bool hasEffectStable(const NumEffectState &, Square target, Player attack)
Definition additionalEffect.cc:36
osl::effect_util::AdditionalEffect::count
static int count(const NumEffectState &, Square target, Player attack)
Definition additionalEffect.cc:26
osl::effect_util::AdditionalEffect::find
static void find(const NumEffectState &, Square target, const PieceVector &direct_effects, PieceVector &black, PieceVector &white)
Definition additionalEffect.cc:50
osl::effect_util::AdditionalEffect::hasEffect
static bool hasEffect(const NumEffectState &, Square target, Player attack)
target に attack の追加利きが一つでもあるか． 相手の影利きが先にある場合は対象としない．
Definition additionalEffect.cc:5
osl::effect_util::AdditionalEffect::count2
static int count2(const NumEffectState &, Square target, Player attack)
target に attack の追加利きを二つまで数える.
Definition additionalEffect.cc:43
osl::effect_util::AdditionalOrShadow::count
static int count(const PieceVector &direct_pieces, const NumEffectState &state, Square target, Player attack)
Definition additionalOrShadow.h:16