boardTable.cc
Go to the documentation of this file.
/* directionTable.cc
*/
#include "osl/bits/boardTable.h"
#include "osl/bits/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:
boardTable.h
osl::BoardTable::getOffset
const Offset getOffset(Direction dir) const
Definition boardTable.h:47
osl::BoardTable::short_offsets
CArray< Offset, Offset32::SIZE > short_offsets
Definition boardTable.h:18
osl::BoardTable::setKnightDirections
void setKnightDirections()
Definition boardTable.cc:36
osl::BoardTable::short_offsets_not_knight
CArray< Offset, Offset32::SIZE > short_offsets_not_knight
Definition boardTable.h:19
osl::BoardTable::space_counts
CArray< int, Offset32Wide::SIZE > space_counts
Definition boardTable.h:21
osl::BoardTable::directions
CArray< Direction, Offset32::SIZE > directions
Definition boardTable.h:14
osl::BoardTable::BoardTable
BoardTable()
Definition boardTable.cc:65
osl::BoardTable::short8Offset
CArray< signed char, Offset::ONBOARD_OFFSET_SIZE > short8Offset
Definition boardTable.h:16
osl::BoardTable::init
void init()
Definition boardTable.cc:45
osl::BoardTable::short8Dir
CArray< unsigned char, Offset::ONBOARD_OFFSET_SIZE > short8Dir
Definition boardTable.h:17
osl::BoardTable::setDirections
void setDirections()
Definition boardTable.cc:7
osl::Offset32Base::index
unsigned int index() const
Definition offset32.h:40
osl::Offset
座標の差分
Definition basic_type.h:430
osl::Offset::intValue
int intValue() const
Definition basic_type.h:448
osl::Offset::ONBOARD_OFFSET_MIN
@ ONBOARD_OFFSET_MIN
Definition basic_type.h:434
directionTraits.h
osl::Offset32Wide
Offset32Base< 10, 10 > Offset32Wide
Definition offset32.h:64
osl::longToShort
constexpr Direction longToShort(Direction d)
Definition basic_type.h:380
osl::DIRECTION_INVALID_VALUE
@ DIRECTION_INVALID_VALUE
Definition basic_type.h:338
osl::UL
@ UL
Definition basic_type.h:313
osl::Offset32
Offset32Base< 8, 9 > Offset32
Definition offset32.h:63
osl::BLACK
@ BLACK
Definition basic_type.h:9
osl::DirectionTraits::blackDx
static const int blackDx
Definition directionTraits.h:229
osl::DirectionTraits::blackDy
static const int blackDy
Definition directionTraits.h:230