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
8namespace 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:
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:
差が uniqになるような座標の差分.
Definition offset32.h:17
int dy(Offset32Base offset32)
Offset32Base(Square to, Square from)
Definition offset32.h:30
bool isValid() const
Definition offset32.h:44
const Offset32Base operator-() const
Definition offset32.h:55
int dx(Offset32Base offset32)
Offset32Base(int o)
Definition offset32.h:26
Offset32Base(int dx, int dy)
Definition offset32.h:37
static const unsigned int SIZE
Definition offset32.h:23
unsigned int index() const
Definition offset32.h:40
const Offset32Base blackOffset32() const
Player P からみた offset を黒番のものに変更する
Definition offset32.h:52
int y() const
将棋としてのY座標を返す.
Definition basic_type.h:567
int x() const
将棋としてのX座標を返す.
Definition basic_type.h:563
Offset32Base< 10, 10 > Offset32Wide
Definition offset32.h:64
Offset32Base< 8, 9 > Offset32
Definition offset32.h:63
@ BLACK
Definition basic_type.h:9