ICSAPI::parseVerbose is now used instead of VariantInfo::getVerboseMove.
[tagua/yd.git] / src / variants / progressive.cpp_
blobec14b3943573141a1990cb5101ce036e2579c192
1 /*
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.
9 */
11 #include "variants/progressive.h"
12 #include "tagua.h"
13 #include "variants/chess.h"
14 #include "variants/xchess/position.h"
15 #include "moveserializer.impl.h"
16 #include "xchess/animator.impl.h"
17 #include "highlevel.h"
19 class ProgressivePosition : public ChessPosition {
20   int m_progression;
21   int m_move_ordinal;
22 public:
23   ProgressivePosition();
24   ProgressivePosition(const OptList& l);
25   ProgressivePosition(const ChessPosition&);
26   ProgressivePosition(Piece::Color turn, bool wk, bool wq,
27                      bool bk, bool bq, const Point& ep);
28   virtual ProgressivePosition* clone() const { return new ProgressivePosition(*this); }
30   virtual void switchTurn() {
31     m_move_ordinal++;
33     if(m_move_ordinal >= m_progression || check(Piece::oppositeColor(turn()))) {
34       m_progression++;
35       m_move_ordinal = 0;
36       ChessPosition::switchTurn();
37     }
38   }
40   virtual void setTurn(Piece::Color turn) {
41     ChessPosition::setTurn(turn);
42     m_progression = 1;
43     m_move_ordinal = 0;
44   }
47 ProgressivePosition::ProgressivePosition()
48 : m_progression(1)
49 , m_move_ordinal(0) { }
50 ProgressivePosition::ProgressivePosition(const OptList& /*l*/)
51 : m_progression(1)
52 , m_move_ordinal(0) { }
53 ProgressivePosition::ProgressivePosition(const ChessPosition& other)
54 : ChessPosition(other)
55 , m_progression(1)
56 , m_move_ordinal(0) { }
57 ProgressivePosition::ProgressivePosition(Piece::Color turn, bool wk, bool wq,
58                                        bool bk, bool bq, const Point& ep)
59 : ChessPosition(turn, wk, wq, bk, bq, ep)
60 , m_progression(1)
61 , m_move_ordinal(0) { }
63 class ProgressiveVariantInfo {
64 public:
65   typedef ProgressivePosition Position;
66   typedef Position::Piece Piece;
67   typedef Position::Move Move;
68   typedef SimpleAnimator<ProgressiveVariantInfo> Animator;
69   static const bool m_simple_moves = false;
70   static void forallPieces(PieceFunction& f);
71   static int moveListLayout(){ return 4; }
72   static const char *m_name;
73   static const char *m_theme_proxy;
74   static OptList positionOptions() { return OptList(); }
77 const char *ProgressiveVariantInfo::m_name = "Progressive";
78 const char *ProgressiveVariantInfo::m_theme_proxy = "Chess";
80 void ProgressiveVariantInfo::forallPieces(PieceFunction& f) {
81   ChessVariant::forallPieces(f);
84 VariantInfo* ProgressiveVariant::static_variant_info = 0;
86 VariantInfo* ProgressiveVariant::info() {
87   if (!static_variant_info)
88     static_variant_info = new WrappedVariantInfo<ProgressiveVariantInfo>;
89   return static_variant_info;