File: boardTable.cc

package info (click to toggle)
libosl 0.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 273,976 kB
  • sloc: cpp: 129,625; ansic: 7,145; ruby: 1,290; makefile: 558; perl: 413; sh: 35
file content (74 lines) | stat: -rw-r--r-- 2,009 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* directionTable.cc
 */
#include "osl/boardTable.h"
#include "osl/directionTraits.h"

template <osl::Direction Dir>
void osl::BoardTable::setDirections(){
  const int blackDx=DirectionTraits<Dir>::blackDx;
  const int blackDy=DirectionTraits<Dir>::blackDy;
  Offset offset=Offset(blackDx,blackDy);
#ifndef MINIMAL
  space_counts[Offset32Wide(0,0).index()]=0;
#endif
  for(int i=1;i<=8;i++){
    int dx=i*blackDx;
    int dy=i*blackDy;
    Offset32 offset32(dx,dy);
    directions[offset32.index()]=Dir;
    short_offsets[offset32.index()]=offset;
    short_offsets_not_knight[offset32.index()]=offset;
    short8Dir[Offset(dx,dy).intValue()-Offset::ONBOARD_OFFSET_MIN]=
      longToShort(Dir);
    short8Offset[Offset(dx,dy).intValue()-Offset::ONBOARD_OFFSET_MIN]=
      offset.intValue();
  }
#ifndef MINIMAL
  for(int i=1;i<=10;i++){
    int dx=i*blackDx;
    int dy=i*blackDy;
    Offset32Wide offset32w(dx,dy);
    space_counts[offset32w.index()]=i-1;
  }
#endif
}
template <osl::Direction Dir>
void osl::BoardTable::setKnightDirections(){
  int dx=DirectionTraits<Dir>::blackDx;
  int dy=DirectionTraits<Dir>::blackDy;
  Offset32 offset32=Offset32(dx,dy);
  Offset offset=Offset(dx,dy);
  short_offsets[offset32.index()]=offset;
  short_offsets[(-offset32).index()]= -offset;
}

void osl::BoardTable::init(){
  short8Dir.fill(DIRECTION_INVALID_VALUE);
  short8Offset.fill();
  directions.fill();
  short_offsets_not_knight.fill();
#ifndef MINIMAL
  space_counts.fill(-1);
#endif
  setDirections<LONG_UL>();
  setDirections<LONG_U>();
  setDirections<LONG_UR>();
  setDirections<LONG_L>();
  setDirections<LONG_R>();
  setDirections<LONG_DL>();
  setDirections<LONG_D>();
  setDirections<LONG_DR>();
  setKnightDirections<UUL>();
  setKnightDirections<UUR>();
}

osl::BoardTable::BoardTable(){
  init();
  assert(! getOffset(BLACK, UL).zero());
}

/* ------------------------------------------------------------------------- */
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End: