2 Copyright (c) 2007 Paolo Capriotti <p.capriotti@gmail.com>
3 (c) 2007 Maurizio Monge <maurizio.monge@kdemail.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
11 #ifndef CORE__DEFAULTPOOL_H
12 #define CORE__DEFAULTPOOL_H
23 * @brief Convenience IPool implementation for shogi-like games.
25 * A DefaultPool holds pieces of the same color. It doesn't
26 * actually contains pieces, but creates them on the fly whenever it
29 * Pieces are maintained using an association type -> number of pieces
30 * of that type. Indexes are computed as if all pieces where ordered by
33 class TAGUA_EXPORT DefaultPool
: public IPool
{
35 * @brief Wrapper of an IType pointer, used to sort types by index.
41 bool operator<(const Key
& other
) const;
43 typedef QMap
<Key
, int> Data
;
45 const IColor
* m_owner
;
47 DefaultPool(const IColor
* owner
);
48 virtual ~DefaultPool();
50 virtual IPool
* clone() const;
51 virtual bool equals(const IPool
* other
) const;
52 virtual bool empty() const;
53 virtual int size() const;
54 virtual int insert(int index
, Piece
& piece
);
55 virtual Piece
get(int index
);
56 virtual Piece
get(int index
) const;
57 virtual Piece
take(int index
);
58 virtual bool take(Piece
& piece
);
61 * @return The common color of the pieces.
63 virtual const IColor
* color() const;
66 * @return The number of pieces of the given type.
68 virtual int count(IType
* type
) const;
71 * Add a piece of the given type to the pool.
72 * @return The new number of pieces of the given type.
74 virtual int add(IType
* type
);
77 * Remove a piece of the given type from the pool.
78 * @return The new number of pieces of the given type.
80 virtual int remove(IType
* type
);
83 #endif // CORE__DEFAULTPOOL_H