offset32.h
Go to the documentation of this file.
/* offset32.h
*/
#ifndef OSL_OFFSET32_H
#define OSL_OFFSET32_H
#include "osl/basic_type.h"
namespace osl
{
template <int Width, int Width2>
class Offset32Base
{
enum {
MIN = -(Width*32+Width),
MAX = (Width*32+Width),
};
public:
static const unsigned int SIZE=(MAX-MIN+1);
private:
int offset32;
explicit Offset32Base(int o) : offset32(o)
{
}
public:
Offset32Base(Square to, Square from)
: offset32(to.indexForOffset32()-from.indexForOffset32())
{
assert((to.x()-from.x() >= -Width) && (to.x()-from.x() <= Width)
&& (to.y()-from.y() >= -Width) && (to.y()-from.y() <= Width));
assert(MIN<=offset32 && offset32<=MAX);
}
Offset32Base(int dx,int dy) : offset32(dx*32+dy) {
assert(-Width2<=dx && dx<=Width2 && -Width2<=dy && dy<=Width2);
}
unsigned int index() const
{
return offset32 - MIN;
}
bool isValid() const
{
return MIN <=offset32 && offset32 <= MAX;
}
template<Player P>
const Offset32Base blackOffset32() const {
return P == BLACK ? *this : Offset32Base(-offset32);
}
const Offset32Base operator-() const { return Offset32Base(-offset32); }
private:
// these functions are *intentionally* unimplemented for the moment.
// don't forget the fact that x or y can be negative.
int dx(Offset32Base offset32);
int dy(Offset32Base offset32);
};
typedef Offset32Base<8,9> Offset32;
typedef Offset32Base<10,10> Offset32Wide;
} // namespace osl
#endif /* OSL_OFFSET32_H */
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
basic_type.h
osl::Offset32Base
差が uniqになるような座標の差分.
Definition offset32.h:17
osl::Offset32Base< 8, 9 >::dy
int dy(Offset32Base offset32)
osl::Offset32Base< 8, 9 >::offset32
int offset32
Definition offset32.h:25
osl::Offset32Base::Offset32Base
Offset32Base(Square to, Square from)
Definition offset32.h:30
osl::Offset32Base::isValid
bool isValid() const
Definition offset32.h:44
osl::Offset32Base::operator-
const Offset32Base operator-() const
Definition offset32.h:55
osl::Offset32Base< 8, 9 >::dx
int dx(Offset32Base offset32)
osl::Offset32Base::Offset32Base
Offset32Base(int o)
Definition offset32.h:26
osl::Offset32Base::Offset32Base
Offset32Base(int dx, int dy)
Definition offset32.h:37
osl::Offset32Base< 8, 9 >::SIZE
static const unsigned int SIZE
Definition offset32.h:23
osl::Offset32Base::index
unsigned int index() const
Definition offset32.h:40
osl::Offset32Base::blackOffset32
const Offset32Base blackOffset32() const
Player P からみた offset を黒番のものに変更する
Definition offset32.h:52
osl::Offset32Base< 8, 9 >::MAX
@ MAX
Definition offset32.h:20
osl::Offset32Base< 8, 9 >::MIN
@ MIN
Definition offset32.h:19
osl::Square
Definition basic_type.h:532
osl::Square::y
int y() const
将棋としてのY座標を返す.
Definition basic_type.h:567
osl::Square::x
int x() const
将棋としてのX座標を返す.
Definition basic_type.h:563
osl
Definition additionalEffect.h:6
osl::Offset32Wide
Offset32Base< 10, 10 > Offset32Wide
Definition offset32.h:64
osl::Offset32
Offset32Base< 8, 9 > Offset32
Definition offset32.h:63
osl::BLACK
@ BLACK
Definition basic_type.h:9