ptypeTable.cc Source File

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ptypeTable.cc
Go to the documentation of this file.
1 /* ptypeTable.cc
2 */
3 #include "osl/ptypeTable.h"
4 #include "osl/boardTable.h"
5
6 osl::PtypeTable::PtypeTable()
7 {
8 init();
9
10 {
11 // guard
12 assert(&effect(newPtypeO(WHITE,ROOK), Offset32(2,8))
13 == &getEffect(newPtypeO(WHITE,ROOK), Offset32(2,8)));
14 assert(getEffect(newPtypeO(BLACK,PPAWN),
15 Offset32(Square(7,1),Square(8,1)))
16 == EffectContent::DIRECT());
17 }
18 }
19
20 template<osl::Ptype T>
21 void osl::PtypeTable::initPtypeSub(Int2Type<true> /*is_basic*/)
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;
33 canDropLimit[1][static_cast<int>(T)]=Square::reverseY(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>
39 void osl::PtypeTable::initPtypeSub(Int2Type<false> /*is_basic*/)
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;
44 betterToPromote[static_cast<int>(T)]=PtypeTraits<T>::betterToPromote;
45 }
46
47 template<osl::Ptype T>
48 void osl::PtypeTable::initPtype()
49 {
50 initPtypeSub<T>(Int2Type<PtypeTraits<T>::isBasic>());
51 }
52
53 void osl::PtypeTable::init()
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 BOOST_STATIC_ASSERT(sizeof(EffectContent) == 4);
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: