6 template <typename Position
>
7 struct PlayerPoolType
{
8 typedef std::map
<typename
Position::Piece::Type
, int> type
;
11 template <typename Position
, typename PP
>
12 class PoolReferenceBase
{
14 typedef typename
Position::Piece Piece
;
15 typedef typename
Piece::Color Color
;
16 typedef typename
Piece::Type Type
;
18 typedef std::map
<Color
, PP
> Pool
;
23 PoolReferenceBase(PP
* p
, Color color
)
31 template <typename Position
>
32 class PoolReference
: public PoolReferenceBase
<Position
,
33 typename PlayerPoolType
<Position
>::type
> {
35 typedef typename PlayerPoolType
<Position
>::type PlayerPool
;
36 typedef PoolReferenceBase
<Position
, PlayerPool
> Base
;
37 typedef typename
Base::Piece Piece
;
38 typedef typename
Base::Type Type
;
39 typedef typename
Base::Color Color
;
41 PoolReference(PlayerPool
* p
, Color color
)
42 : PoolReferenceBase
<Position
, PlayerPool
>(p
, color
) { }
44 int insert(int idx
, const Piece
& p
);
48 template <typename Position
>
49 class PoolConstReference
: public PoolReferenceBase
<Position
,
50 const typename PlayerPoolType
<Position
>::type
> {
51 typedef const typename PlayerPoolType
<Position
>::type PlayerPool
;
52 typedef typename
Position::Piece::Color Color
;
54 PoolConstReference(PlayerPool
* p
, Color color
)
55 : PoolReferenceBase
<Position
, const PlayerPool
>(p
, color
) { }
58 template <typename Position
, typename PP
>
59 int PoolReferenceBase
<Position
, PP
>::size() {
64 for (typename
PP::const_iterator i
= m_p_pool
->begin(); i
!= m_p_pool
->end(); ++i
)
69 template <typename Position
, typename PP
>
70 typename PoolReferenceBase
<Position
, PP
>::Piece PoolReferenceBase
<Position
, PP
>::get(int idx
) {
75 for (typename
PP::const_iterator i
= m_p_pool
->begin(); i
!= m_p_pool
->end(); ++i
) {
76 if (idx
< fill
+ i
->second
)
77 return Piece(m_color
, i
->first
);
83 template <typename Position
>
84 int PoolReference
<Position
>::insert(int idx
, const Piece
& p
) {
85 if (this->m_color
!= p
.color()) {
86 ERROR("Inserting a piece in the wrong pool?");
91 for (typename
PlayerPool::iterator i
= this->m_p_pool
->begin();
92 (i
!= this->m_p_pool
->end()) && i
->first
< p
.type();
97 int nump
= ++(*this->m_p_pool
)[p
.type()];
101 if (idx
>= fill
+ nump
)
102 return fill
+ nump
- 1;
107 template <typename Position
>
108 typename PoolReference
<Position
>::Piece PoolReference
<Position
>::take(int idx
) {
113 for(typename
PlayerPool::iterator i
= this->m_p_pool
->begin();
114 i
!= this->m_p_pool
->end();
116 if(idx
< fill
+ i
->second
) {
119 this->m_p_pool
->erase(i
);
120 return Piece(this->m_color
, t
);
127 #endif // XCHESS__POOL_H