2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@sns.it>
3 (c) 2006 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 CRAZYHOUSE_P_H
12 #define CRAZYHOUSE_P_H
16 #include "xchess/pool.h"
18 class CrazyhousePiece
: public ChessPiece
{
22 CrazyhousePiece(ChessPiece::Color
= INVALID_COLOR
, ChessPiece::Type
= INVALID_TYPE
,
23 bool promoted
= false);
24 CrazyhousePiece(const CrazyhousePiece
&);
25 CrazyhousePiece(const ChessPiece
&);
27 inline bool promoted() const { return m_promoted
; }
28 inline void setPromoted(bool value
) { m_promoted
= value
; }
30 bool operator<(const CrazyhousePiece
& p
) const {
31 return m_promoted
!= p
.m_promoted
?
32 m_promoted
< p
.m_promoted
:
33 this->ChessPiece::operator<(p
);
37 class CrazyhouseMove
: public ChessMove
{
38 CrazyhousePiece m_drop
;
42 CrazyhouseMove(const ChessMove
& move
);
43 CrazyhouseMove(const Point
& from
, const Point
& to
, PieceType promotionType
= INVALID_TYPE
);
44 CrazyhouseMove(const CrazyhousePiece
& p
, const Point
& to
);
45 CrazyhouseMove(int pool
, int m_pool_index
, const Point
& to
);
46 CrazyhouseMove(const CrazyhouseMove
&);
48 QString
toString(int xsize
, int ysize
) const {
50 return CrazyhousePiece::typeSymbol(m_drop
.type()) + "@" + to
.toString(ysize
);
51 return ChessMove::toString(xsize
, ysize
);
53 static CrazyhouseMove
createDropMove(int pool
, int m_pool_index
, const Point
& to
) {
54 return CrazyhouseMove(pool
, m_pool_index
, to
);
57 CrazyhousePiece
drop() const { return m_drop
; }
58 void setDrop(const CrazyhousePiece
& piece
) { m_drop
= piece
; }
59 int pool() const { return m_pool
; }
60 int poolIndex() const { return m_pool_index
; }
63 class CrazyhousePosition
: public Position
<CrazyhouseMove
, CrazyhousePiece
, Grid
<CrazyhousePiece
> > {
65 typedef CrazyhouseMove Move
;
66 typedef CrazyhousePiece Piece
;
67 typedef Position
<Move
, Piece
, Grid
<Piece
> > Base
;
68 typedef PoolReference
<CrazyhousePosition
> PoolReference
;
69 typedef PoolConstReference
<CrazyhousePosition
> PoolConstReference
;
70 typedef PoolReference::Pool Pool
;
71 typedef PoolReference::PlayerPool PlayerPool
;
74 CrazyhousePosition(const OptList
& l
);
75 CrazyhousePosition(const CrazyhousePosition
&);
76 CrazyhousePosition(const ChessPosition
&);
77 CrazyhousePosition(CrazyhousePiece::Color turn
, bool wk
, bool wq
,
78 bool bk
, bool bq
, const Point
& ep
);
79 virtual CrazyhousePosition
* clone() const;
84 virtual CrazyhousePiece::Color
moveTurn(const Move
&) const;
85 virtual bool pseudolegal(Move
&) const;
86 virtual void move(const Move
&);
87 virtual void executeCaptureOn(const Point
& point
);
88 virtual boost::shared_ptr
<AbstractGenerator
<Move
> > createLegalGenerator() const;
90 virtual Move
getMove(const AlgebraicNotation
& san
, bool& ok
) const;
92 virtual bool operator==(const CrazyhousePosition
& other
) const;
94 static Move
getVerboseMove(Color turn
, const VerboseNotation
& m
) {
95 Move retv
= ChessPosition::getVerboseMove(turn
, m
);
96 if(retv
.from
== Point::invalid())
97 retv
.setDrop(CrazyhousePiece(turn
, static_cast<ChessPiece::Type
>(m
.type
)));
99 retv
.setDrop(CrazyhousePiece(INVALID_COLOR
, INVALID_TYPE
));
105 PoolReference
pool(int index
);
106 PoolConstReference
pool(int index
) const;
108 PlayerPool
& rawPool(Piece::Color color
);
109 const PlayerPool
& rawPool(Piece::Color color
) const;
111 void setRawPool(const Pool
& p
) { m_pool
= p
; }
112 Pool
& rawPool() { return m_pool
; }
113 const Pool
& rawPool() const { return m_pool
; }
116 template <typename MoveTest
>
117 class MoveGenerator
<CrazyhousePosition
, MoveTest
>
118 : public Generator
<CrazyhousePosition
, MoveTest
> {
119 typedef Generator
<CrazyhousePosition
, MoveTest
> Base
;
124 MoveGenerator(const CrazyhousePosition
& pos
)
127 std::vector
<CrazyhouseMove
>& generate() {
129 return Base::generate();
133 void generateDrops() {
134 const CrazyhousePosition::PlayerPool
& pp
= m_pos
.rawPool()[m_pos
.turn()];
135 for (CrazyhousePosition::PlayerPool::const_iterator it
= pp
.begin();
136 it
!= pp
.end(); ++it
) {
137 for (Point to
= m_pos
.first();
139 to
= m_pos
.next(to
)) {
140 CrazyhouseMove
move(CrazyhousePiece(m_pos
.turn(),it
->first
), to
);
141 if (m_test(move
)) m_moves
.push_back(move
);
148 class MoveSerializer
<CrazyhousePosition
> : public MoveSerializerBase
<CrazyhousePosition
> {
149 typedef CrazyhousePosition Position
;
150 typedef CrazyhouseMove Move
;
151 typedef CrazyhousePiece Piece
;
152 typedef MoveSerializerBase
<Position
> Base
;
154 MoveSerializer(const Move
& move
, const Position
& ref
)
155 : MoveSerializerBase
<Position
>(move
, ref
) { }
157 QString
SAN() const {
160 return QString("%1@%2")
161 .arg(CrazyhousePiece::typeSymbol(m_move
.drop().type()))
162 .arg(m_move
.to
.toString(m_ref
.size().y
)) + checkSuffix();
169 #endif // CRAZYHOUSE_P_H