ptypeTable.h
Go to the documentation of this file.
/* ptypeTable.h
*/
#ifndef OSL_PTYPETABLE_H
#define OSL_PTYPETABLE_H
#include "osl/basic_type.h"
#include "osl/bits/ptypeTraits.h"
#include "osl/bits/effectContent.h"
#include "osl/container.h"
#include "osl/bits/offset32.h"
#include "osl/bits/mask.h"
namespace osl
{
class PtypeTable
{
private:
CArray<mask_t, PTYPE_SIZE> numMaskLows;
CArray<int, PTYPE_SIZE> numIndices;
CArray<const char *, PTYPE_SIZE> names;
CArray<const char *, PTYPE_SIZE> csaNames;
CArray<bool, PTYPE_SIZE> betterToPromote;
CArray<int, PTYPE_SIZE> moveMasks;
CArray<int, PTYPE_SIZE> indexMins;
CArray<int, PTYPE_SIZE> indexLimits;
CArray2d<int, 2, PTYPE_SIZE> canDropLimit;
// これらの2次元配列は2^nにそろえておいた方が速い．
CArray2d<EffectContent,PTYPEO_SIZE,Offset32::SIZE> effectTable;
CArray2d<EffectContent,PTYPEO_SIZE,Offset32::SIZE> effectTableNotLongU;
CArray2d<unsigned int, 2, SHORT_DIRECTION_SIZE> shortMoveMask;
template<Ptype T> void initPtypeSub(Int2Type<false> isBasic);
template<Ptype T> void initPtypeSub(Int2Type<true> isBasic);
template<Ptype T> void initPtype();
public:
PtypeTable();
private:
void init();
public:
unsigned int getShortMoveMask(Player p,PtypeO ptypeo,Direction dir) const
{
return shortMoveMask[playerToIndex(p)][static_cast<int>(dir)] &
(1<<(ptypeo-PTYPEO_MIN));
}
mask_t getMaskLow(Ptype ptype) const
{
return numMaskLows[ptype];
}
int getIndex(Ptype) const { return 0; }
bool hasLongMove(Ptype ptype) const
{
return getIndexMin(unpromote(ptype))>=32;
}
bool isBetterToPromote(Ptype ptype) const
{
return betterToPromote[ptype];
}
int getCanDropLimit(Player player,Ptype ptype) const
{
assert(isValid(ptype) && !isPromoted(ptype));
return canDropLimit[playerToIndex(player)][ptype];
}
bool canDropTo(Player pl, Ptype ptype, Square pos) const
{
if (pl == BLACK)
return pos.y() >= getCanDropLimit(BLACK,ptype);
else
return pos.y() <= getCanDropLimit(WHITE,ptype);
}
const char *getName(Ptype ptype) const
{
return names[ptype];
}
const char *getCsaName(Ptype ptype) const
{
return csaNames[ptype];
}
int getMoveMask(Ptype ptype) const
{
return moveMasks[ptype];
}
int getIndexMin(Ptype ptype) const
{
assert(isBasic(ptype));
return indexMins[ptype];
}
int getIndexLimit(Ptype ptype) const
{
assert(isBasic(ptype));
return indexLimits[ptype];
}
static int getKingIndex(Player p)
{
assert(isValid(p));
if (p==BLACK)
return KingTraits<BLACK>::index;
else
return KingTraits<WHITE>::index;
}
const EffectContent getEffect(PtypeO ptypeo,Square from, Square to) const
{
assert(from.isOnBoard() && to.isOnBoard());
return getEffect(ptypeo,Offset32(to,from));
}
const EffectContent& getEffect(PtypeO ptypeo,Offset32 offset32) const
{
assert(isValidPtypeO(ptypeo));
return effectTable[ptypeo-PTYPEO_MIN][offset32.index()];
}
private:
EffectContent& effect(PtypeO ptypeo,Offset32 offset32)
{
assert(isValidPtypeO(ptypeo));
const int i1 = ptypeo-PTYPEO_MIN;
const int i2 = offset32.index();
return effectTable[i1][i2];
}
public:
const EffectContent
getEffectNotLongU(PtypeO ptypeo, Square from, Square to) const
{
assert(isValidPtypeO(ptypeo));
assert(from.isOnBoard() && to.isOnBoard());
Offset32 offset32=Offset32(to,from);
return effectTableNotLongU[ptypeo-PTYPEO_MIN][offset32.index()];
}
bool hasUnblockableEffect(PtypeO attacker, Square from, Square to) const
{
const EffectContent effect = getEffect(attacker, from, to);
return effect.hasUnblockableEffect();
}
};
extern const PtypeTable Ptype_Table;
} // namespace osl
#endif /* OSL_PTYPETABLE_H */
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
basic_type.h
osl::CArray
Definition container.h:20
osl::EffectContent
Definition effectContent.h:11
osl::Offset32Base::index
unsigned int index() const
Definition offset32.h:40
osl::PtypeTable::getIndex
int getIndex(Ptype) const
Definition ptypeTable.h:50
osl::PtypeTable::getEffect
const EffectContent & getEffect(PtypeO ptypeo, Offset32 offset32) const
Definition ptypeTable.h:117
osl::PtypeTable::hasLongMove
bool hasLongMove(Ptype ptype) const
遅くて良い?
Definition ptypeTable.h:54
osl::PtypeTable::getKingIndex
static int getKingIndex(Player p)
Definition ptypeTable.h:98
osl::PtypeTable::numMaskLows
CArray< mask_t, PTYPE_SIZE > numMaskLows
Definition ptypeTable.h:18
osl::PtypeTable::getCsaName
const char * getCsaName(Ptype ptype) const
Definition ptypeTable.h:80
osl::PtypeTable::effectTableNotLongU
CArray2d< EffectContent, PTYPEO_SIZE, Offset32::SIZE > effectTableNotLongU
Definition ptypeTable.h:30
osl::PtypeTable::getIndexLimit
int getIndexLimit(Ptype ptype) const
Definition ptypeTable.h:93
osl::PtypeTable::init
void init()
Definition ptypeTable.cc:53
osl::PtypeTable::getCanDropLimit
int getCanDropLimit(Player player, Ptype ptype) const
Definition ptypeTable.h:62
osl::PtypeTable::moveMasks
CArray< int, PTYPE_SIZE > moveMasks
Definition ptypeTable.h:23
osl::PtypeTable::initPtypeSub
void initPtypeSub(Int2Type< false > isBasic)
Definition ptypeTable.cc:39
osl::PtypeTable::numIndices
CArray< int, PTYPE_SIZE > numIndices
Definition ptypeTable.h:19
osl::PtypeTable::getEffect
const EffectContent getEffect(PtypeO ptypeo, Square from, Square to) const
fromにいるptypeoがtoに利きを持つか?
Definition ptypeTable.h:112
osl::PtypeTable::canDropLimit
CArray2d< int, 2, PTYPE_SIZE > canDropLimit
Definition ptypeTable.h:27
osl::PtypeTable::getMaskLow
mask_t getMaskLow(Ptype ptype) const
Definition ptypeTable.h:46
osl::PtypeTable::isBetterToPromote
bool isBetterToPromote(Ptype ptype) const
Definition ptypeTable.h:58
osl::PtypeTable::getEffectNotLongU
const EffectContent getEffectNotLongU(PtypeO ptypeo, Square from, Square to) const
ptypeo が，自分から offset のところに効きを持つか?
Definition ptypeTable.h:133
osl::PtypeTable::effect
EffectContent & effect(PtypeO ptypeo, Offset32 offset32)
Definition ptypeTable.h:123
osl::PtypeTable::PtypeTable
PtypeTable()
Definition ptypeTable.cc:6
osl::PtypeTable::canDropTo
bool canDropTo(Player pl, Ptype ptype, Square pos) const
Definition ptypeTable.h:68
osl::PtypeTable::names
CArray< const char *, PTYPE_SIZE > names
Definition ptypeTable.h:20
osl::PtypeTable::getName
const char * getName(Ptype ptype) const
Definition ptypeTable.h:76
osl::PtypeTable::hasUnblockableEffect
bool hasUnblockableEffect(PtypeO attacker, Square from, Square to) const
Definition ptypeTable.h:140
osl::PtypeTable::getShortMoveMask
unsigned int getShortMoveMask(Player p, PtypeO ptypeo, Direction dir) const
Definition ptypeTable.h:41
osl::PtypeTable::betterToPromote
CArray< bool, PTYPE_SIZE > betterToPromote
Definition ptypeTable.h:22
osl::PtypeTable::getIndexMin
int getIndexMin(Ptype ptype) const
Definition ptypeTable.h:88
osl::PtypeTable::indexMins
CArray< int, PTYPE_SIZE > indexMins
Definition ptypeTable.h:24
osl::PtypeTable::effectTable
CArray2d< EffectContent, PTYPEO_SIZE, Offset32::SIZE > effectTable
Definition ptypeTable.h:29
osl::PtypeTable::shortMoveMask
CArray2d< unsigned int, 2, SHORT_DIRECTION_SIZE > shortMoveMask
Definition ptypeTable.h:31
osl::PtypeTable::csaNames
CArray< const char *, PTYPE_SIZE > csaNames
Definition ptypeTable.h:21
osl::PtypeTable::initPtype
void initPtype()
Definition ptypeTable.cc:48
osl::PtypeTable::indexLimits
CArray< int, PTYPE_SIZE > indexLimits
Definition ptypeTable.h:25
osl::PtypeTable::getMoveMask
int getMoveMask(Ptype ptype) const
Definition ptypeTable.h:84
osl::Square
Definition basic_type.h:532
osl::Square::y
int y() const
将棋としてのY座標を返す.
Definition basic_type.h:567
osl::Square::isOnBoard
bool isOnBoard() const
盤面上を表すかどうかの判定． 1<=x() && x()<=9 && 1<=y() && y()<=9 Squareの内部表現に依存する．
Definition basic_type.h:583
container.h
effectContent.h
mask.h
osl::misc::mask_t
GeneralMask< mask_int_t > mask_t
Definition mask.h:351
osl
Definition additionalEffect.h:6
osl::Ptype
Ptype
駒の種類を4ビットでコード化する
Definition basic_type.h:84
osl::Ptype_Table
const PtypeTable Ptype_Table
Definition tables.cc:97
osl::CArray2d
CArray< CArray< T, Capacity2 >, Capacity1 > CArray2d
Definition container.h:95
osl::isValidPtypeO
bool isValidPtypeO(int ptypeO)
Definition basic_type.cc:30
osl::unpromote
Ptype unpromote(Ptype ptype)
ptypeがpromote後の型の時に，promote前の型を返す． promoteしていない型の時はそのまま返す
Definition basic_type.h:157
osl::playerToIndex
constexpr int playerToIndex(Player player)
Definition basic_type.h:16
osl::isValid
bool isValid(Player player)
cast等で作られたplayerが正しいかどうかを返す
Definition basic_type.cc:9
osl::Direction
Direction
Definition basic_type.h:310
osl::isPromoted
bool isPromoted(Ptype ptype)
ptypeがpromote後の型かどうかのチェック
Definition basic_type.h:137
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::PtypeO
PtypeO
Player + Ptype [-15, 15] PtypeO の O は Owner の O.
Definition basic_type.h:199
osl::PTYPEO_MIN
@ PTYPEO_MIN
Definition basic_type.h:200
osl::isBasic
bool isBasic(Ptype ptype)
ptypeが基本型(promoteしていない)かのチェック
Definition basic_type.h:128
offset32.h
ptypeTraits.h
osl::KingTraits::index
static const int index
Definition ptypeTraits.h:358
osl::misc::Int2Type
Definition basic_type.h:69