boardTable.cc Source File

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
boardTable.cc
Go to the documentation of this file.
1 /* directionTable.cc
2 */
3 #include "osl/boardTable.h"
4 #include "osl/directionTraits.h"
5
6 template <osl::Direction Dir>
7 void osl::BoardTable::setDirections(){
8 const int blackDx=DirectionTraits<Dir>::blackDx;
9 const int blackDy=DirectionTraits<Dir>::blackDy;
10 Offset offset=Offset(blackDx,blackDy);
11 #ifndef MINIMAL
12 space_counts[Offset32Wide(0,0).index()]=0;
13 #endif
14 for(int i=1;i<=8;i++){
15 int dx=i*blackDx;
16 int dy=i*blackDy;
17 Offset32 offset32(dx,dy);
18 directions[offset32.index()]=Dir;
19 short_offsets[offset32.index()]=offset;
20 short_offsets_not_knight[offset32.index()]=offset;
21 short8Dir[Offset(dx,dy).intValue()-Offset::ONBOARD_OFFSET_MIN]=
22 longToShort(Dir);
23 short8Offset[Offset(dx,dy).intValue()-Offset::ONBOARD_OFFSET_MIN]=
24 offset.intValue();
25 }
26 #ifndef MINIMAL
27 for(int i=1;i<=10;i++){
28 int dx=i*blackDx;
29 int dy=i*blackDy;
30 Offset32Wide offset32w(dx,dy);
31 space_counts[offset32w.index()]=i-1;
32 }
33 #endif
34 }
35 template <osl::Direction Dir>
36 void osl::BoardTable::setKnightDirections(){
37 int dx=DirectionTraits<Dir>::blackDx;
38 int dy=DirectionTraits<Dir>::blackDy;
39 Offset32 offset32=Offset32(dx,dy);
40 Offset offset=Offset(dx,dy);
41 short_offsets[offset32.index()]=offset;
42 short_offsets[(-offset32).index()]= -offset;
43 }
44
45 void osl::BoardTable::init(){
46 short8Dir.fill(DIRECTION_INVALID_VALUE);
47 short8Offset.fill();
48 directions.fill();
49 short_offsets_not_knight.fill();
50 #ifndef MINIMAL
51 space_counts.fill(-1);
52 #endif
53 setDirections<LONG_UL>();
54 setDirections<LONG_U>();
55 setDirections<LONG_UR>();
56 setDirections<LONG_L>();
57 setDirections<LONG_R>();
58 setDirections<LONG_DL>();
59 setDirections<LONG_D>();
60 setDirections<LONG_DR>();
61 setKnightDirections<UUL>();
62 setKnightDirections<UUR>();
63 }
64
65 osl::BoardTable::BoardTable(){
66 init();
67 assert(! getOffset(BLACK, UL).zero());
68 }
69
70 /* ------------------------------------------------------------------------- */
71 // ;;; Local Variables:
72 // ;;; mode:c++
73 // ;;; c-basic-offset:2
74 // ;;; End: