ptypeTable.cc
Go to the documentation of this file.
1 /* ptypeTable.cc
2  */
3 #include "osl/bits/ptypeTable.h"
4 #include "osl/bits/boardTable.h"
5 
7 {
8  init();
9 
10  {
11  // guard
12  assert(&effect(newPtypeO(WHITE,ROOK), Offset32(2,8))
13  == &getEffect(newPtypeO(WHITE,ROOK), Offset32(2,8)));
15  Offset32(Square(7,1),Square(8,1)))
17  }
18 }
19 
20 template<osl::Ptype T>
22 {
23  initPtypeSub<T>(Int2Type<false>());
24  numMaskLows[static_cast<int>(T)]=mask_t::makeDirect(PtypeFuns<T>::indexMask);
25  numIndices[static_cast<int>(T)]=PtypeFuns<T>::indexNum;
26  if(canPromote(T)){
27  numMaskLows[static_cast<int>(promote(T))]=mask_t::makeDirect(PtypeFuns<T>::indexMask);
28  numIndices[static_cast<int>(promote(T))]=PtypeFuns<T>::indexNum;
29  }
31  canDropLimit[0][static_cast<int>(T)]=PtypeTraits<T>::dropBlackFromY;
34  indexMins[static_cast<int>(T)]=PtypeTraits<T>::indexMin;
35  indexLimits[static_cast<int>(T)]=PtypeTraits<T>::indexLimit;
36 }
37 
38 template<osl::Ptype T>
40 {
41  names[static_cast<int>(T)]=PtypeTraits<T>::name();
42  csaNames[static_cast<int>(T)]=PtypeTraits<T>::csaName();
43  moveMasks[static_cast<int>(T)]=PtypeTraits<T>::moveMask;
45 }
46 
47 template<osl::Ptype T>
49 {
50  initPtypeSub<T>(Int2Type<PtypeTraits<T>::isBasic>());
51 }
52 
54 {
55  numMaskLows.fill();
56  numIndices.fill();
57 
58  initPtype<PTYPE_EMPTY>();
59  initPtype<PTYPE_EDGE>();
60  initPtype<PPAWN>();
61  initPtype<PLANCE>();
62  initPtype<PKNIGHT>();
63  initPtype<PSILVER>();
64  initPtype<PBISHOP>();
65  initPtype<PROOK>();
66  initPtype<GOLD>();
67  initPtype<KING>();
68  initPtype<PAWN>();
69  initPtype<LANCE>();
70  initPtype<KNIGHT>();
71  initPtype<SILVER>();
72  initPtype<BISHOP>();
73  initPtype<ROOK>();
74  effectTable.fill();
75  effectTableNotLongU.fill();
76  shortMoveMask.fill();
77  static_assert(sizeof(EffectContent) == 4, "size");
78  assert(&effect(newPtypeO(WHITE,ROOK), Offset32(2,8))
79  == &getEffect(newPtypeO(WHITE,ROOK), Offset32(2,8)));
80  assert(! getEffect(newPtypeO(BLACK,ROOK), Offset32(-1,8)).hasEffect());
81 
82  for(int ptype=PTYPE_MIN;ptype<=PTYPE_MAX;ptype++){
83  for(int j=DIRECTION_MIN;j<=DIRECTION_MAX;j++){
84  Direction dir=static_cast<Direction>(j);
85 
86  if((moveMasks[ptype]&(1<<dir))!=0){
87  int dx=Board_Table.getDxForBlack(dir);
88  int dy=Board_Table.getDyForBlack(dir);
89  Offset32 offset32=Offset32(dx,dy);
90  Offset offset=newOffset(dx,dy);
91  if(isLong(dir)){
92  shortMoveMask[0][dir-10]|=1<<(ptype-PTYPEO_MIN);
93  shortMoveMask[1][dir-10]|=1<<(ptype-16-PTYPEO_MIN);
94 
95  effectTable[ptype-PTYPEO_MIN][offset32.index()]=EffectContent::DIRECT(offset);
96  effectTable[ptype-16-PTYPEO_MIN][(-offset32).index()]=EffectContent::DIRECT(-offset);
97 
98  for(int i=2;i<9;i++){
99  offset32=Offset32(dx*i,dy*i);
100  effectTable[ptype-PTYPEO_MIN][offset32.index()]=EffectContent(offset);
101  effectTable[ptype-16-PTYPEO_MIN][(-offset32).index()]=EffectContent(-offset);
102 
103  if(static_cast<int>(dir)!=LONG_U){
104  effectTableNotLongU[ptype-PTYPEO_MIN][offset32.index()]=effectTable[ptype-PTYPEO_MIN][offset32.index()];
105  effectTableNotLongU[ptype-16-PTYPEO_MIN][(-offset32).index()]=effectTable[ptype-16-PTYPEO_MIN][(-offset32).index()];
106  }
107  }
108  }
109  else{
110  shortMoveMask[0][dir]|=1<<(ptype-PTYPEO_MIN);
111  shortMoveMask[1][dir]|=1<<(ptype-16-PTYPEO_MIN);
112  effectTable[ptype-PTYPEO_MIN][offset32.index()]=EffectContent::DIRECT();
113  effectTable[ptype-16-PTYPEO_MIN][(-offset32).index()]=EffectContent::DIRECT();
114 
115  assert(! getEffect(newPtypeO(BLACK,ROOK),Offset32(-1,8)).hasEffect());
116  }
117  }
118  }
119  }
120 }
121 
122 /* ------------------------------------------------------------------------- */
123 // ;;; Local Variables:
124 // ;;; mode:c++
125 // ;;; c-basic-offset:2
126 // ;;; End:
static const EffectContent DIRECT()
Definition: effectContent.h:24
座標の差分
Definition: basic_type.h:429
CArray< int, PTYPE_SIZE > indexLimits
Definition: ptypeTable.h:25
差が uniqになるような座標の差分.
Definition: offset32.h:16
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
Ptype promote(Ptype ptype)
promote可能なptypeに対して,promote後の型を返す promote不可のptypeを与えてはいけない. ...
Definition: basic_type.h:173
PtypeO newPtypeO(Player player, Ptype ptype)
Definition: basic_type.h:211
static int reverseY(int y)
Definition: basic_type.h:652
CArray< mask_t, PTYPE_SIZE > numMaskLows
Definition: ptypeTable.h:18
CArray2d< EffectContent, PTYPEO_SIZE, Offset32::SIZE > effectTableNotLongU
Definition: ptypeTable.h:30
CArray2d< int, 2, PTYPE_SIZE > canDropLimit
Definition: ptypeTable.h:27
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
unsigned int index() const
Definition: offset32.h:40
bool canPromote(Ptype ptype)
ptypeがpromote可能な型かどうかのチェック promote済みの場合はfalseを返す
Definition: basic_type.h:147
CArray< const char *, PTYPE_SIZE > names
Definition: ptypeTable.h:20
CArray2d< EffectContent, PTYPEO_SIZE, Offset32::SIZE > effectTable
Definition: ptypeTable.h:29
EffectContent & effect(PtypeO ptypeo, Offset32 offset32)
Definition: ptypeTable.h:123
int getDxForBlack(Direction dir) const
Definition: boardTable.h:40
Offset newOffset(int dx, int dy)
Definition: basic_type.h:508
Direction
Definition: basic_type.h:310
void fill(const T_simple &value=T_simple())
Definition: container.h:67
constexpr bool isLong(Direction d)
Definition: basic_type.h:350
int getDyForBlack(Direction dir) const
Definition: boardTable.h:43
CArray< int, PTYPE_SIZE > numIndices
Definition: ptypeTable.h:19
CArray< int, PTYPE_SIZE > indexMins
Definition: ptypeTable.h:24
void initPtypeSub(Int2Type< false > isBasic)
Definition: ptypeTable.cc:39
const BoardTable Board_Table
Definition: tables.cc:95