My Project
ptypeTable.h
Go to the documentation of this file.
1 /* ptypeTable.h
2  */
3 #ifndef OSL_PTYPETABLE_H
4 #define OSL_PTYPETABLE_H
5 
6 #include "osl/basic_type.h"
7 #include "osl/bits/ptypeTraits.h"
9 #include "osl/container.h"
10 #include "osl/bits/offset32.h"
11 #include "osl/bits/mask.h"
12 
13 namespace osl
14 {
15  class PtypeTable
16  {
17  private:
26 
28  // これらの2次元配列は2^nにそろえておいた方が速い.
32 
33  template<Ptype T> void initPtypeSub(Int2Type<false> isBasic);
34  template<Ptype T> void initPtypeSub(Int2Type<true> isBasic);
35  template<Ptype T> void initPtype();
36  public:
37  PtypeTable();
38  private:
39  void init();
40  public:
41  unsigned int getShortMoveMask(Player p,PtypeO ptypeo,Direction dir) const
42  {
43  return shortMoveMask[playerToIndex(p)][static_cast<int>(dir)] &
44  (1<<(ptypeo-PTYPEO_MIN));
45  }
46  mask_t getMaskLow(Ptype ptype) const
47  {
48  return numMaskLows[ptype];
49  }
50  int getIndex(Ptype) const { return 0; }
54  bool hasLongMove(Ptype ptype) const
55  {
56  return getIndexMin(unpromote(ptype))>=32;
57  }
58  bool isBetterToPromote(Ptype ptype) const
59  {
60  return betterToPromote[ptype];
61  }
62  int getCanDropLimit(Player player,Ptype ptype) const
63  {
64  assert(isValid(ptype) && !isPromoted(ptype));
65  return canDropLimit[playerToIndex(player)][ptype];
66  }
67 
68  bool canDropTo(Player pl, Ptype ptype, Square pos) const
69  {
70  if (pl == BLACK)
71  return pos.y() >= getCanDropLimit(BLACK,ptype);
72  else
73  return pos.y() <= getCanDropLimit(WHITE,ptype);
74  }
75 
76  const char *getName(Ptype ptype) const
77  {
78  return names[ptype];
79  }
80  const char *getCsaName(Ptype ptype) const
81  {
82  return csaNames[ptype];
83  }
84  int getMoveMask(Ptype ptype) const
85  {
86  return moveMasks[ptype];
87  }
88  int getIndexMin(Ptype ptype) const
89  {
90  assert(isBasic(ptype));
91  return indexMins[ptype];
92  }
93  int getIndexLimit(Ptype ptype) const
94  {
95  assert(isBasic(ptype));
96  return indexLimits[ptype];
97  }
98  static int getKingIndex(Player p)
99  {
100  assert(isValid(p));
101  if (p==BLACK)
103  else
105  }
112  const EffectContent getEffect(PtypeO ptypeo,Square from, Square to) const
113  {
114  assert(from.isOnBoard() && to.isOnBoard());
115  return getEffect(ptypeo,Offset32(to,from));
116  }
117  const EffectContent& getEffect(PtypeO ptypeo,Offset32 offset32) const
118  {
119  assert(isValidPtypeO(ptypeo));
120  return effectTable[ptypeo-PTYPEO_MIN][offset32.index()];
121  }
122  private:
124  {
125  assert(isValidPtypeO(ptypeo));
126  const int i1 = ptypeo-PTYPEO_MIN;
127  const int i2 = offset32.index();
128  return effectTable[i1][i2];
129  }
130  public:
132  const EffectContent
133  getEffectNotLongU(PtypeO ptypeo, Square from, Square to) const
134  {
135  assert(isValidPtypeO(ptypeo));
136  assert(from.isOnBoard() && to.isOnBoard());
137  Offset32 offset32=Offset32(to,from);
138  return effectTableNotLongU[ptypeo-PTYPEO_MIN][offset32.index()];
139  }
140  bool hasUnblockableEffect(PtypeO attacker, Square from, Square to) const
141  {
142  const EffectContent effect = getEffect(attacker, from, to);
143  return effect.hasUnblockableEffect();
144  }
145  };
146 
147  extern const PtypeTable Ptype_Table;
148 
149 } // namespace osl
150 
151 
152 #endif /* OSL_PTYPETABLE_H */
153 // ;;; Local Variables:
154 // ;;; mode:c++
155 // ;;; c-basic-offset:2
156 // ;;; End:
osl::PtypeTable::moveMasks
CArray< int, PTYPE_SIZE > moveMasks
Definition: ptypeTable.h:23
osl::Square
Definition: basic_type.h:532
osl::PtypeTable::getShortMoveMask
unsigned int getShortMoveMask(Player p, PtypeO ptypeo, Direction dir) const
Definition: ptypeTable.h:41
osl::PtypeTable::names
CArray< const char *, PTYPE_SIZE > names
Definition: ptypeTable.h:20
ptypeTraits.h
osl::WHITE
@ WHITE
Definition: basic_type.h:10
osl::PtypeTable::effectTableNotLongU
CArray2d< EffectContent, PTYPEO_SIZE, Offset32::SIZE > effectTableNotLongU
Definition: ptypeTable.h:30
osl::Square::isOnBoard
bool isOnBoard() const
盤面上を表すかどうかの判定. 1<=x() && x()<=9 && 1<=y() && y()<=9 Squareの内部表現に依存する.
Definition: basic_type.h:583
osl::PtypeTable::getEffect
const EffectContent getEffect(PtypeO ptypeo, Square from, Square to) const
fromにいるptypeoがtoに利きを持つか?
Definition: ptypeTable.h:112
osl::Offset32
Offset32Base< 8, 9 > Offset32
Definition: offset32.h:63
osl::isValidPtypeO
bool isValidPtypeO(int ptypeO)
Definition: basic_type.cc:30
osl::PtypeTable::canDropLimit
CArray2d< int, 2, PTYPE_SIZE > canDropLimit
Definition: ptypeTable.h:27
osl::PtypeTable::getKingIndex
static int getKingIndex(Player p)
Definition: ptypeTable.h:98
basic_type.h
osl::PtypeTable::hasLongMove
bool hasLongMove(Ptype ptype) const
遅くて良い?
Definition: ptypeTable.h:54
osl::PtypeTable::initPtypeSub
void initPtypeSub(Int2Type< false > isBasic)
Definition: ptypeTable.cc:39
osl::PtypeTable::isBetterToPromote
bool isBetterToPromote(Ptype ptype) const
Definition: ptypeTable.h:58
osl::PtypeTable::init
void init()
Definition: ptypeTable.cc:53
osl::PtypeTable::getMaskLow
mask_t getMaskLow(Ptype ptype) const
Definition: ptypeTable.h:46
osl::PtypeTable::getName
const char * getName(Ptype ptype) const
Definition: ptypeTable.h:76
osl::PtypeTable::getEffectNotLongU
const EffectContent getEffectNotLongU(PtypeO ptypeo, Square from, Square to) const
ptypeo が,自分から offset のところに効きを持つか? U除く
Definition: ptypeTable.h:133
effectContent.h
osl::misc::mask_t
GeneralMask< mask_int_t > mask_t
Definition: mask.h:351
osl::Ptype
Ptype
駒の種類を4ビットでコード化する
Definition: basic_type.h:84
osl::Ptype_Table
const PtypeTable Ptype_Table
Definition: tables.cc:97
osl::PtypeTable::getMoveMask
int getMoveMask(Ptype ptype) const
Definition: ptypeTable.h:84
osl::PtypeTable::getIndexLimit
int getIndexLimit(Ptype ptype) const
Definition: ptypeTable.h:93
osl::PtypeTable::effectTable
CArray2d< EffectContent, PTYPEO_SIZE, Offset32::SIZE > effectTable
Definition: ptypeTable.h:29
osl::PtypeTable::effect
EffectContent & effect(PtypeO ptypeo, Offset32 offset32)
Definition: ptypeTable.h:123
osl::PtypeTable::getIndexMin
int getIndexMin(Ptype ptype) const
Definition: ptypeTable.h:88
container.h
osl::PtypeTable::PtypeTable
PtypeTable()
Definition: ptypeTable.cc:6
osl::PtypeTable::getIndex
int getIndex(Ptype) const
Definition: ptypeTable.h:50
osl::isBasic
bool isBasic(Ptype ptype)
ptypeが基本型(promoteしていない)かのチェック
Definition: basic_type.h:128
osl::PtypeTable::getCanDropLimit
int getCanDropLimit(Player player, Ptype ptype) const
Definition: ptypeTable.h:62
mask.h
osl::Offset32Base
差が uniqになるような座標の差分.
Definition: offset32.h:17
osl::misc::Int2Type
Definition: basic_type.h:69
osl::isValid
bool isValid(Player player)
cast等で作られたplayerが正しいかどうかを返す
Definition: basic_type.cc:9
osl::PtypeTable::getEffect
const EffectContent & getEffect(PtypeO ptypeo, Offset32 offset32) const
Definition: ptypeTable.h:117
osl::PtypeO
PtypeO
Player + Ptype [-15, 15] PtypeO の O は Owner の O.
Definition: basic_type.h:199
osl::PtypeTable::csaNames
CArray< const char *, PTYPE_SIZE > csaNames
Definition: ptypeTable.h:21
osl::PtypeTable::shortMoveMask
CArray2d< unsigned int, 2, SHORT_DIRECTION_SIZE > shortMoveMask
Definition: ptypeTable.h:31
osl::Direction
Direction
Definition: basic_type.h:310
osl::playerToIndex
constexpr int playerToIndex(Player player)
Definition: basic_type.h:16
osl::EffectContent::hasUnblockableEffect
bool hasUnblockableEffect() const
短い利きがある.長い利きの隣も含む
Definition: effectContent.h:38
osl::PtypeTable::hasUnblockableEffect
bool hasUnblockableEffect(PtypeO attacker, Square from, Square to) const
Definition: ptypeTable.h:140
osl::Square::y
int y() const
将棋としてのY座標を返す.
Definition: basic_type.h:567
offset32.h
osl::isPromoted
bool isPromoted(Ptype ptype)
ptypeがpromote後の型かどうかのチェック
Definition: basic_type.h:137
osl::PTYPEO_MIN
@ PTYPEO_MIN
Definition: basic_type.h:200
osl::KingTraits
Definition: ptypeTraits.h:357
osl::PtypeTable::initPtype
void initPtype()
Definition: ptypeTable.cc:48
osl::Offset32Base::index
unsigned int index() const
Definition: offset32.h:40
osl::PtypeTable::canDropTo
bool canDropTo(Player pl, Ptype ptype, Square pos) const
Definition: ptypeTable.h:68
osl::PtypeTable::betterToPromote
CArray< bool, PTYPE_SIZE > betterToPromote
Definition: ptypeTable.h:22
osl::BLACK
@ BLACK
Definition: basic_type.h:9
osl::PtypeTable::indexMins
CArray< int, PTYPE_SIZE > indexMins
Definition: ptypeTable.h:24
osl::EffectContent
Definition: effectContent.h:11
osl::Player
Player
Definition: basic_type.h:8
osl::PtypeTable::indexLimits
CArray< int, PTYPE_SIZE > indexLimits
Definition: ptypeTable.h:25
osl::CArray< mask_t, PTYPE_SIZE >
osl::PtypeTable::getCsaName
const char * getCsaName(Ptype ptype) const
Definition: ptypeTable.h:80
osl::PtypeTable::numIndices
CArray< int, PTYPE_SIZE > numIndices
Definition: ptypeTable.h:19
osl::PtypeTable::numMaskLows
CArray< mask_t, PTYPE_SIZE > numMaskLows
Definition: ptypeTable.h:18
osl::PtypeTable
Definition: ptypeTable.h:16
osl::unpromote
Ptype unpromote(Ptype ptype)
ptypeがpromote後の型の時に,promote前の型を返す. promoteしていない型の時はそのまま返す
Definition: basic_type.h:157
osl
Definition: additionalEffect.h:6