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.
12 #include "piecesprite.h"
13 #include "crazyhouse_p.h"
14 #include "xchess/animator.impl.h"
16 typedef CrazyhousePiece DummyPiece
;
17 typedef CrazyhouseMove DummyMove
;
21 class DummyPosition
: public CrazyhousePosition
{
23 friend class MoveSerializer
<DummyPosition
>;
24 typedef DummyMove Move
;
25 typedef DummyPiece Piece
;
26 typedef CrazyhousePosition Base
;
27 typedef std::map
<DummyPiece
, int> Pool
;
30 DummyPosition(const OptList
& l
);
31 DummyPosition(const DummyPosition
&);
32 DummyPosition(const ChessPosition
&);
33 DummyPosition(DummyPiece::Color turn
, bool wk
, bool wq
,
34 bool bk
, bool bq
, const Point
& ep
);
35 virtual DummyPosition
* clone() const;
38 virtual bool pseudolegal(Move
&) const;
39 virtual bool testMove(Move
&) const;
40 virtual void move(const Move
&);
41 virtual void executeCaptureOn(const Point
& point
) {
42 this->CrazyhousePosition::Base::executeCaptureOn(point
);
45 virtual bool operator==(const DummyPosition
& other
) const;
47 static Move
getVerboseMove(Color turn
, const VerboseNotation
& m
) {
48 Move retv
= ChessPosition::getVerboseMove(turn
, m
);
49 if(retv
.from
== Point::invalid())
50 retv
.m_drop
= DummyPiece(turn
, static_cast<ChessPiece::Type
>(m
.type
) );
52 retv
.m_drop
= DummyPiece(INVALID_COLOR
, INVALID_TYPE
);
57 DummyPosition::DummyPosition() {
60 DummyPosition::DummyPosition(const OptList
&) {
63 DummyPosition::DummyPosition(const DummyPosition
& other
)
67 DummyPosition::DummyPosition(const ChessPosition
& other
)
71 DummyPosition::DummyPosition(DummyPiece::Color turn
, bool wk
, bool wq
,
72 bool bk
, bool bq
, const Point
& ep
)
73 : Base(turn
, wk
, wq
, bk
, bq
, ep
) {
76 DummyPosition
* DummyPosition::clone() const {
77 return new DummyPosition(*this);
80 bool DummyPosition::pseudolegal(Move
& move
) const {
81 if (move
.m_drop
.valid())
82 return valid(move
.to
);
84 return valid(move
.from
) && valid(move
.to
);
87 bool DummyPosition::testMove(Move
& move
) const {
88 if (move
.status
== Move::Untested
)
89 move
.status
= pseudolegal(move
) ? Move::Legal
: Move::Illegal
;
90 return move
.status
== Move::Legal
;
93 void DummyPosition::move(const Move
& move
) {
94 if (move
.m_drop
.valid()) {
95 basicDropPiece(new Piece(move
.m_drop
), move
.to
);
96 if(--m_pool
[move
.m_drop
] <= 0)
97 m_pool
.erase(move
.m_drop
);
100 executeCaptureOn(move
.to
);
101 basicMovePiece(move
);
106 bool DummyPosition::operator==(const DummyPosition
& pos
) const {
107 return pool() == pos
.pool() && Base::operator==(pos
);
116 #include "highlevel.h"
117 #include "moveserializer.impl.h"
120 class MoveSerializer
<DummyPosition
> : public AbstractMoveSerializer
{
121 const DummyMove
& m_move
;
122 const DummyPosition
& m_ref
;
124 MoveSerializer(const DummyMove
& m
, const DummyPosition
& r
)
125 : m_move(m
), m_ref(r
) { }
127 DecoratedMove
toDecoratedMove() const {
128 return DecoratedMove() << SAN();
131 virtual QString
SAN() const {
132 if(m_move
.m_drop
.valid())
133 return CrazyhousePiece::typeSymbol(m_move
.m_drop
.type()) + "@" + m_move
.to
.toString(8);
135 QString res
= m_move
.from
.toString(m_ref
.size().y
) + m_move
.to
.toString(m_ref
.size().y
);
136 if (m_move
.m_type
== DummyMove::Promotion
)
137 res
= res
+ "=" + m_move
.promotionSymbol();
138 if(m_ref
.m_board
.valid(m_move
.from
) && m_ref
.m_board
[m_move
.from
]
139 && m_ref
.get(m_move
.from
)->type() != PAWN
)
140 res
= DummyPiece::typeSymbol(m_ref
.get(m_move
.from
)->type()) + res
;
146 class DummyVariantInfo
{
148 typedef DummyPosition Position
;
149 typedef Position::Move Move
;
150 typedef Position::Piece Piece
;
151 typedef SimpleAnimator
<DummyVariantInfo
> Animator
;
152 static const bool m_simple_moves
= false;
153 static void forallPieces(PieceFunction
& f
);
154 static int moveListLayout(){ return 0; }
155 static const char *m_name
;
156 static const char *m_theme_proxy
;
157 static OptList
positionOptions() { return OptList(); }
160 const char *DummyVariantInfo::m_name
= "Dummy";
161 const char *DummyVariantInfo::m_theme_proxy
= "Chess";
163 VariantInfo
* DummyVariant::static_dummy_variant
= 0;
165 void DummyVariantInfo::forallPieces(PieceFunction
& f
) {
166 return ChessVariant::forallPieces(f
);
169 VariantInfo
* DummyVariant::info() {
170 if (!static_dummy_variant
)
171 static_dummy_variant
= new WrappedVariantInfo
<DummyVariantInfo
>;
172 return static_dummy_variant
;