Continued refactor work.
[tagua.git] / src / variants / king4pawns.cpp_
blob538457f3b5561b9510fd56b2d63812a5ed44d620
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 "king4pawns.h"
12 #include "kboard.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 King4PawnsPosition : public ChessPosition {
20   int m_move_ordinal;
21 public:
22   King4PawnsPosition();
23   King4PawnsPosition(const OptList& l);
24   King4PawnsPosition(const ChessPosition&);
25   King4PawnsPosition(Piece::Color turn, bool wk, bool wq,
26                      bool bk, bool bq, const Point& ep);
27   virtual King4PawnsPosition* clone() const { return new King4PawnsPosition(*this); }
29 #define SET_PIECE(i,j, color, type) m_board[Point(i,j)] = Piece(color, type)
30   virtual void setup() {
31     // 4 pawns
32     for (int i = 2; i <= 5; i++)
33       SET_PIECE(i, 6, WHITE, PAWN);
35     // 1 king
36     SET_PIECE(4,7, WHITE, KING);
38     // all black's army
39     for (int i = 0; i < 8; i++)
40       SET_PIECE(i, 1, BLACK, PAWN);
42     SET_PIECE(0,0, BLACK, ROOK);
43     SET_PIECE(1,0, BLACK, KNIGHT);
44     SET_PIECE(2,0, BLACK, BISHOP);
45     SET_PIECE(3,0, BLACK, QUEEN);
46     SET_PIECE(4,0, BLACK, KING);
47     SET_PIECE(5,0, BLACK, BISHOP);
48     SET_PIECE(6,0, BLACK, KNIGHT);
49     SET_PIECE(7,0, BLACK, ROOK);
50   }
51 #undef SET_PIECE
53   virtual void switchTurn() {
54     if (turn() == WHITE && m_move_ordinal == 0)
55       m_move_ordinal++;
56     else {
57       ChessPosition::switchTurn();
58       m_move_ordinal = 0;
59     }
60   }
62   virtual void setTurn(Piece::Color turn) {
63     ChessPosition::setTurn(turn);
64     m_move_ordinal = 0;
65   }
67   virtual bool testMove(Move& move) const {
68     return pseudolegal(move);
69   }
72 King4PawnsPosition::King4PawnsPosition()
73 : m_move_ordinal(0) { }
74 King4PawnsPosition::King4PawnsPosition(const OptList&)
75 : m_move_ordinal(0) { }
76 King4PawnsPosition::King4PawnsPosition(const ChessPosition& other)
77 : ChessPosition(other)
78 , m_move_ordinal(0) { }
79 King4PawnsPosition::King4PawnsPosition(Piece::Color turn, bool wk, bool wq,
80                                        bool bk, bool bq, const Point& ep)
81 : ChessPosition(turn, wk, wq, bk, bq, ep)
82 , m_move_ordinal(0) { }
84 class King4PawnsVariantInfo {
85 public:
86   typedef King4PawnsPosition Position;
87   typedef Position::Piece Piece;
88   typedef Position::Move Move;
89   typedef SimpleAnimator<King4PawnsVariantInfo> Animator;
90   static const bool m_simple_moves = false;
91   static void forallPieces(PieceFunction& f);
92   static int moveListLayout(){ return 2; }
93   static const char *m_name;
94   static const char *m_theme_proxy;
95   static OptList positionOptions() { return OptList(); }
98 const char *King4PawnsVariantInfo::m_name = "King4Pawns";
99 const char *King4PawnsVariantInfo::m_theme_proxy = "Chess";
101 void King4PawnsVariantInfo::forallPieces(PieceFunction& f) {
102   ChessVariant::forallPieces(f);
105 VariantInfo* King4PawnsVariant::static_variant_info = 0;
107 VariantInfo* King4PawnsVariant::info() {
108   if (!static_variant_info)
109     static_variant_info = new WrappedVariantInfo<King4PawnsVariantInfo>;
110   return static_variant_info;