Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
include
osl
player.h
Go to the documentation of this file.
1
#ifndef OSL_PLAYER_H
2
#define OSL_PLAYER_H
3
#include <boost/static_assert.hpp>
4
#include <cassert>
5
#include <iosfwd>
6
namespace
osl{
7
enum
Player
{
8
BLACK
=0,
9
WHITE
= -1
10
};
11
12
inline
Player
alt
(
Player
player){
13
return
static_cast<
Player
>
(-1-
static_cast<
int
>
(player));
14
}
15
inline
int
playerToIndex
(
Player
player){
16
return
-
static_cast<
int
>
(player);
17
}
18
inline
Player
indexToPlayer
(
int
n) {
19
assert(n == 0 || n == 1);
20
return
static_cast<
Player
>
(-n);
21
}
22
inline
int
playerToMul
(
Player
player){
23
int
ret=1+(
static_cast<
int
>
(player)<<1);
24
assert(ret==1 || ret== -1);
25
return
ret;
26
}
27
inline
int
playerToSign
(
Player
player)
28
{
29
return
playerToMul
(player);
30
}
31
inline
int
playerToMask
(
Player
player){
32
return
static_cast<
int
>
(player);
33
}
34
35
// These codes are intentionally DECLARED and NOT IMPLEMENTED.
36
// you will get link error here if you write code such as "value += v * piece.owner() == BLACK ? 1.0 : -1.0;"
37
int
operator+
(
Player
,
int
);
int
operator+
(
int
,
Player
);
38
int
operator-
(
Player
,
int
);
int
operator-
(
int
,
Player
);
39
int
operator*
(
Player
,
int
);
int
operator*
(
int
,
Player
);
40
int
operator/
(
Player
,
int
);
int
operator/
(
int
,
Player
);
41
45
bool
isValid
(
Player
player);
46
47
template
<Player P>
48
struct
PlayerTraits
;
49
50
template
<>
51
struct
PlayerTraits
<
BLACK
>{
52
static
const
int
offsetMul=1;
53
static
const
int
index=0;
54
static
const
int
mask=0;
55
static
const
Player
opponent=
WHITE
;
56
};
57
58
template
<>
59
struct
PlayerTraits
<
WHITE
>{
60
static
const
int
offsetMul=-1;
61
static
const
int
index=1;
62
static
const
int
mask= -1;
63
static
const
Player
opponent=
BLACK
;
64
};
65
66
std::ostream&
operator<<
(std::ostream& os,
Player
player);
67
}
68
#endif
/* OSL_PLAYER_H */
69
// ;;; Local Variables:
70
// ;;; mode:c++
71
// ;;; c-basic-offset:2
72
// ;;; coding:utf-8
73
// ;;; End:
Generated on Sun Jul 21 2013 13:37:26 by
1.8.4