Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
include
osl
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/misc/loki.h
"
7
#include "
osl/square.h
"
8
9
namespace
osl
10
{
16
template
<
int
W
id
th,
int
W
id
th2>
17
class
Offset32Base
18
{
19
enum
{
20
MIN
= -(Width*32+Width),
21
MAX
= (Width*32+Width),
22
};
23
public
:
24
static
const
unsigned
int
SIZE
=(
MAX
-
MIN
+1);
25
private
:
26
int
offset32
;
27
explicit
Offset32Base
(
int
o) :
offset32
(o)
28
{
29
}
30
public
:
31
Offset32Base
(
Square
to,
Square
from)
32
:
offset32
(to.indexForOffset32()-from.indexForOffset32())
33
{
34
assert((to.
x
()-from.
x
() >= -Width) && (to.
x
()-from.
x
() <= Width)
35
&& (to.
y
()-from.
y
() >= -Width) && (to.
y
()-from.
y
() <= Width));
36
assert(
MIN
<=
offset32
&&
offset32
<=
MAX
);
37
}
38
Offset32Base
(
int
dx
,
int
dy
) :
offset32
(dx*32+dy) {
39
assert(-Width2<=dx && dx<=Width2 && -Width2<=dy && dy<=Width2);
40
}
41
unsigned
int
index
()
const
42
{
43
return
offset32
-
MIN
;
44
}
45
bool
isValid
()
const
46
{
47
return
MIN
<=
offset32
&&
offset32
<=
MAX
;
48
}
49
private
:
50
const
Offset32Base
blackOffset32
(Int2Type<BLACK>)
const
{
return
*
this
; }
51
const
Offset32Base
blackOffset32
(Int2Type<WHITE>)
const
{
return
Offset32Base
(-
offset32
); }
52
public
:
56
template
<Player P>
57
const
Offset32Base
blackOffset32
()
const
{
return
blackOffset32
(Int2Type<P>()); }
58
59
const
Offset32Base
operator-
()
const
{
return
Offset32Base
(-
offset32
); }
60
private
:
61
// these functions are *intentionally* unimplemented for the moment.
62
// don't forget the fact that x or y can be negative.
63
int
dx
(
Offset32Base
offset32
);
64
int
dy
(
Offset32Base
offset32
);
65
};
66
67
typedef
Offset32Base<8,9>
Offset32
;
68
typedef
Offset32Base<10,10>
Offset32Wide
;
69
}
// namespace osl
70
71
72
#endif
/* OSL_OFFSET32_H */
73
// ;;; Local Variables:
74
// ;;; mode:c++
75
// ;;; c-basic-offset:2
76
// ;;; End:
Generated on Sun Jul 21 2013 13:37:25 by
1.8.4