sendOffSquare.cc
Go to the documentation of this file.
/* sendOffSquare.cc
*/
#include "osl/effect_util/sendOffSquare.h"
#include "osl/bits/ptypeTable.h"
#include "osl/oslConfig.h"
osl::effect_util::SendOffSquare::Table osl::effect_util::SendOffSquare::table;
static osl::SetUpRegister _initializer([](){
osl::effect_util::SendOffSquare::init();
});
void osl::effect_util::SendOffSquare::
Table::init()
{
normal[0] = Offset( 1, 1);
normal[1] = Offset( 1, 0);
normal[2] = Offset( 1,-1);
normal[3] = Offset( 0, 1);
normal[4] = Offset( 0,-1);
normal[5] = Offset(-1, 1);
normal[6] = Offset(-1, 0);
normal[7] = Offset(-1,-1);
const Square center(5,5);
const PtypeO king = newPtypeO(BLACK, KING);
for (int i=0; i<8; ++i)
{
const Offset king_square = normal[i];
for (int j=0; j<8; ++j)
{
const Offset target = normal[j];
if (i==j)
continue;
const int dx = king_square.dx() - target.dx();
const int dy = king_square.dy() - target.dy();
const EffectContent effect
= Ptype_Table.getEffect(king, Offset32(dx, dy));
if (! effect.hasEffect())
{
reverse[i].push_back(j);
}
}
}
for (int i=0; i<256; ++i)
{
unsigned int val = i;
while (val)
{
const int j = misc::BitOp::takeOneBit(val);
for (int p: reverse[j])
{
if (! reverse_all[i].isMember(p))
reverse_all[i].push_back(p);
}
}
}
}
template <osl::Player Attack>
osl::effect_util::SendOffSquare::SendOff8
#if (defined __GNUC__) && (! defined GPSONE) && (! defined GPSUSIONE)
__attribute__ ((used))
#endif
osl::effect_util::
SendOffSquare::find(const NumEffectState& state, Square king_square,
Square8& out)
{
assert(out.empty());
int flags=0;
for (int i=0; i<8; ++i)
{
testSquare<Attack>(state, king_square+table.normal[i], i, flags);
}
SendOff8 data = 0;
for (int i: table.reverse_all[flags])
{
const Square candidate = king_square + table.normal[i];
if (! state.pieceAt(candidate).isEdge()
&& state.countEffect(alt(Attack), candidate) == 1) {
out.push_back(candidate);
data |= (1<<i);
}
}
return data;
}
void osl::effect_util::
SendOffSquare::unpack(SendOff8 flags8, Square king_square,
Square8& out)
{
assert(out.empty());
unsigned int flags = flags8;
while (flags) {
const int i = misc::BitOp::takeOneBit(flags);
const Square candidate = king_square + table.normal[i];
out.push_back(candidate);
}
}
osl::effect_util::SendOffSquare::SendOff8 osl::effect_util::
SendOffSquare::find(Player attack, const NumEffectState& state,
Square king_square,
Square8& out)
{
if (attack == BLACK)
return find<BLACK>(state, king_square, out);
else
return find<WHITE>(state, king_square, out);
}
/* ------------------------------------------------------------------------- */
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
osl::EffectContent
Definition effectContent.h:11
osl::FixedCapacityVector::empty
bool empty() const
Definition container.h:244
osl::NumEffectState
利きを持つ局面
Definition numEffectState.h:34
osl::NumEffectState::countEffect
int countEffect(Player player, Square target) const
利きの数を数える.
Definition numEffectState.h:266
osl::Offset
座標の差分
Definition basic_type.h:430
osl::Offset::dx
int dx() const
Offsetから一般に dxは求まらないので, ここでの入力は12近傍のみとする
Definition basic_type.cc:119
osl::Offset::dy
int dy() const
Offsetから一般に dyは求まらないので, ここでの入力は12近傍のみとする
Definition basic_type.cc:146
osl::Piece::isEdge
bool isEdge() const
Definition basic_type.h:919
osl::SimpleState::pieceAt
const Piece pieceAt(Square sq) const
Definition simpleState.h:167
osl::Square
Definition basic_type.h:532
osl::effect
Definition effectedNumTable.h:8
osl::KING
@ KING
Definition basic_type.h:93
osl::Ptype_Table
const PtypeTable Ptype_Table
Definition tables.cc:97
osl::Offset32
Offset32Base< 8, 9 > Offset32
Definition offset32.h:63
osl::Player
Player
Definition basic_type.h:8
osl::BLACK
@ BLACK
Definition basic_type.h:9
osl::__attribute__
const PtypeO PTYPEO_EDGE __attribute__((unused))
osl::PtypeO
PtypeO
Player + Ptype [-15, 15] PtypeO の O は Owner の O.
Definition basic_type.h:199
osl::alt
constexpr Player alt(Player player)
Definition basic_type.h:13
osl::newPtypeO
PtypeO newPtypeO(Player player, Ptype ptype)
Definition basic_type.h:211
oslConfig.h
ptypeTable.h
_initializer
static osl::SetUpRegister _initializer([](){ osl::effect_util::SendOffSquare::init();})
sendOffSquare.h
osl::SetUpRegister
Definition oslConfig.h:128
osl::container::Square8
Definition square8.h:16
osl::container::Square8::push_back
void push_back(Square position)
Definition square8.h:18
osl::effect_util::SendOffSquare::Table
Definition sendOffSquare.h:37
osl::effect_util::SendOffSquare::Table::init
void init()
Definition sendOffSquare.cc:14
osl::effect_util::SendOffSquare::Table::reverse
CArray< Offset8, 8 > reverse
Definition sendOffSquare.h:39
osl::effect_util::SendOffSquare::Table::reverse_all
CArray< Offset8, 256 > reverse_all
Definition sendOffSquare.h:40
osl::effect_util::SendOffSquare::Table::normal
CArray< Offset, 8 > normal
Definition sendOffSquare.h:38
osl::effect_util::SendOffSquare::SendOff8
uint8_t SendOff8
Definition sendOffSquare.h:18
osl::effect_util::SendOffSquare::init
static void init()
Definition sendOffSquare.h:43
osl::effect_util::SendOffSquare::unpack
static void unpack(SendOff8, Square king, Square8 &out)
Definition sendOffSquare.cc:91
osl::effect_util::SendOffSquare::find
static SendOff8 find(const NumEffectState &state, Square king_position, Square8 &out)
osl::effect_util::SendOffSquare::testSquare
static void testSquare(const NumEffectState &state, Square candidate, int id, int &out)
Definition sendOffSquare.h:47
osl::effect_util::SendOffSquare::table
static Table table
Definition sendOffSquare.h:45
osl::misc::BitOp::takeOneBit
static int takeOneBit(Integer &mask)
Definition mask.h:148