My Project
offset32.h
Go to the documentation of this file.
1 /* offset32.h
2  */
3 #ifndef OSL_OFFSET32_H
4 #define OSL_OFFSET32_H
5 
6 #include "osl/basic_type.h"
7 
8 namespace osl
9 {
15  template <int Width, int Width2>
17  {
18  enum {
19  MIN = -(Width*32+Width),
20  MAX = (Width*32+Width),
21  };
22  public:
23  static const unsigned int SIZE=(MAX-MIN+1);
24  private:
25  int offset32;
26  explicit Offset32Base(int o) : offset32(o)
27  {
28  }
29  public:
31  : offset32(to.indexForOffset32()-from.indexForOffset32())
32  {
33  assert((to.x()-from.x() >= -Width) && (to.x()-from.x() <= Width)
34  && (to.y()-from.y() >= -Width) && (to.y()-from.y() <= Width));
35  assert(MIN<=offset32 && offset32<=MAX);
36  }
37  Offset32Base(int dx,int dy) : offset32(dx*32+dy) {
38  assert(-Width2<=dx && dx<=Width2 && -Width2<=dy && dy<=Width2);
39  }
40  unsigned int index() const
41  {
42  return offset32 - MIN;
43  }
44  bool isValid() const
45  {
46  return MIN <=offset32 && offset32 <= MAX;
47  }
51  template<Player P>
52  const Offset32Base blackOffset32() const {
53  return P == BLACK ? *this : Offset32Base(-offset32);
54  }
55  const Offset32Base operator-() const { return Offset32Base(-offset32); }
56  private:
57  // these functions are *intentionally* unimplemented for the moment.
58  // don't forget the fact that x or y can be negative.
61  };
62 
65 } // namespace osl
66 
67 
68 #endif /* OSL_OFFSET32_H */
69 // ;;; Local Variables:
70 // ;;; mode:c++
71 // ;;; c-basic-offset:2
72 // ;;; End:
osl::Offset32Wide
Offset32Base< 10, 10 > Offset32Wide
Definition: offset32.h:64
osl::Square
Definition: basic_type.h:532
osl::Offset32
Offset32Base< 8, 9 > Offset32
Definition: offset32.h:63
osl::Offset32Base::isValid
bool isValid() const
Definition: offset32.h:44
basic_type.h
osl::Offset32Base::dx
int dx(Offset32Base offset32)
osl::Offset32Base::MIN
@ MIN
Definition: offset32.h:19
osl::Offset32Base::blackOffset32
const Offset32Base blackOffset32() const
Player P からみた offset を黒番のものに変更する
Definition: offset32.h:52
osl::Offset32Base::Offset32Base
Offset32Base(Square to, Square from)
Definition: offset32.h:30
osl::Offset32Base::MAX
@ MAX
Definition: offset32.h:20
osl::Offset32Base
差が uniqになるような座標の差分.
Definition: offset32.h:17
osl::Offset32Base::Offset32Base
Offset32Base(int dx, int dy)
Definition: offset32.h:37
osl::Square::x
int x() const
将棋としてのX座標を返す.
Definition: basic_type.h:563
osl::Square::y
int y() const
将棋としてのY座標を返す.
Definition: basic_type.h:567
osl::Offset32Base::index
unsigned int index() const
Definition: offset32.h:40
osl::BLACK
@ BLACK
Definition: basic_type.h:9
osl::Offset32Base::dy
int dy(Offset32Base offset32)
osl::Offset32Base::SIZE
static const unsigned int SIZE
Definition: offset32.h:23
osl::Offset32Base::Offset32Base
Offset32Base(int o)
Definition: offset32.h:26
osl::Offset32Base::offset32
int offset32
Definition: offset32.h:25
osl
Definition: additionalEffect.h:6
osl::Offset32Base::operator-
const Offset32Base operator-() const
Definition: offset32.h:55