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:
Ptype unpromote(Ptype ptype)
ptypeがpromote後の型の時に,promote前の型を返す. promoteしていない型の時はそのまま返す ...
Definition: basic_type.h:157
bool hasUnblockableEffect() const
短い利きがある.長い利きの隣も含む
Definition: effectContent.h:38
GeneralMask< mask_int_t > mask_t
Definition: mask.h:351
int getMoveMask(Ptype ptype) const
Definition: ptypeTable.h:84
CArray< int, PTYPE_SIZE > indexLimits
Definition: ptypeTable.h:25
差が uniqになるような座標の差分.
Definition: offset32.h:16
int y() const
将棋としてのY座標を返す.
Definition: basic_type.h:567
CArray< int, PTYPE_SIZE > moveMasks
Definition: ptypeTable.h:23
void initPtype()
Definition: ptypeTable.cc:48
CArray< const char *, PTYPE_SIZE > csaNames
Definition: ptypeTable.h:21
CArray2d< unsigned int, 2, SHORT_DIRECTION_SIZE > shortMoveMask
Definition: ptypeTable.h:31
Offset32Base< 8, 9 > Offset32
Definition: offset32.h:63
bool isValidPtypeO(int ptypeO)
Definition: basic_type.cc:30
const char * getCsaName(Ptype ptype) const
Definition: ptypeTable.h:80
Ptype
駒の種類を4ビットでコード化する
Definition: basic_type.h:83
bool hasUnblockableEffect(PtypeO attacker, Square from, Square to) const
Definition: ptypeTable.h:140
const PtypeTable Ptype_Table
Definition: tables.cc:97
CArray< mask_t, PTYPE_SIZE > numMaskLows
Definition: ptypeTable.h:18
bool isOnBoard() const
盤面上を表すかどうかの判定. 1<=x() && x()<=9 && 1<=y() && y()<=9 Squareの内部表現に依存する. ...
Definition: basic_type.h:583
CArray2d< EffectContent, PTYPEO_SIZE, Offset32::SIZE > effectTableNotLongU
Definition: ptypeTable.h:30
CArray2d< int, 2, PTYPE_SIZE > canDropLimit
Definition: ptypeTable.h:27
bool hasLongMove(Ptype ptype) const
遅くて良い?
Definition: ptypeTable.h:54
bool canDropTo(Player pl, Ptype ptype, Square pos) const
Definition: ptypeTable.h:68
const EffectContent getEffect(PtypeO ptypeo, Square from, Square to) const
fromにいるptypeoがtoに利きを持つか?
Definition: ptypeTable.h:112
CArray< bool, PTYPE_SIZE > betterToPromote
Definition: ptypeTable.h:22
bool isValid(Player player)
cast等で作られたplayerが正しいかどうかを返す
Definition: basic_type.cc:9
bool isBasic(Ptype ptype)
ptypeが基本型(promoteしていない)かのチェック
Definition: basic_type.h:128
constexpr int playerToIndex(Player player)
Definition: basic_type.h:16
static int getKingIndex(Player p)
Definition: ptypeTable.h:98
unsigned int index() const
Definition: offset32.h:40
mask_t getMaskLow(Ptype ptype) const
Definition: ptypeTable.h:46
const EffectContent getEffectNotLongU(PtypeO ptypeo, Square from, Square to) const
ptypeo が,自分から offset のところに効きを持つか? U除く
Definition: ptypeTable.h:133
CArray< const char *, PTYPE_SIZE > names
Definition: ptypeTable.h:20
int getIndexLimit(Ptype ptype) const
Definition: ptypeTable.h:93
CArray2d< EffectContent, PTYPEO_SIZE, Offset32::SIZE > effectTable
Definition: ptypeTable.h:29
PtypeO
Player + Ptype [-15, 15] PtypeO の O は Owner の O.
Definition: basic_type.h:199
EffectContent & effect(PtypeO ptypeo, Offset32 offset32)
Definition: ptypeTable.h:123
int getIndex(Ptype) const
Definition: ptypeTable.h:50
Direction
Definition: basic_type.h:310
unsigned int getShortMoveMask(Player p, PtypeO ptypeo, Direction dir) const
Definition: ptypeTable.h:41
bool isPromoted(Ptype ptype)
ptypeがpromote後の型かどうかのチェック
Definition: basic_type.h:137
CArray< int, PTYPE_SIZE > numIndices
Definition: ptypeTable.h:19
const EffectContent & getEffect(PtypeO ptypeo, Offset32 offset32) const
Definition: ptypeTable.h:117
Player
Definition: basic_type.h:8
const char * getName(Ptype ptype) const
Definition: ptypeTable.h:76
int getCanDropLimit(Player player, Ptype ptype) const
Definition: ptypeTable.h:62
int getIndexMin(Ptype ptype) const
Definition: ptypeTable.h:88
CArray< int, PTYPE_SIZE > indexMins
Definition: ptypeTable.h:24
void initPtypeSub(Int2Type< false > isBasic)
Definition: ptypeTable.cc:39
bool isBetterToPromote(Ptype ptype) const
Definition: ptypeTable.h:58