Removed all promotion stuff from controllers and UI.
[tagua/yd.git] / src / controllers / abstract.h
blobbc97701a7e75cde344011f09d58580f850513411
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 #ifndef CONTROLLER_H
12 #define CONTROLLER_H
14 #include <boost/enable_shared_from_this.hpp>
15 #include <qstring.h>
16 #include "common.h"
17 #include "entitytoken.h"
18 #include "fwd.h"
20 class ChessTable;
21 class UserEntity;
22 class Engine;
23 class PGN;
24 class ActionCollection;
26 /**
27 * @b Controller is the base abstract class for all controllers in Tagua.
28 * Tagua can be used in different modes, such as game editing or position editing.
29 * Each mode corresponds to a concrete subclass of Controller, and defines its behaviour
30 * in response to user events (history navigation, move executions...).
31 * By default, events are routed to the user entity returned by the virtual function
32 * entity.
34 class Controller : public boost::enable_shared_from_this<Controller> {
35 protected:
36 ChessTable* m_view;
37 ActionCollection* m_variant_actions;
38 virtual boost::shared_ptr<UserEntity> entity() const = 0;
39 public:
40 Controller(ChessTable* view);
41 virtual ~Controller();
43 /**
44 * Variant specific actions.
46 ActionCollection* variantActions() const;
48 /**
49 * Variant associated to the controller.
51 virtual QString variant() const = 0;
53 /**
54 * Terminate activity, create another controller and delegate everything to it.
55 * @return The delegate controller, or simply @b this if controller does not need
56 * to be terminated.
58 virtual boost::shared_ptr<Controller> end() { return shared_from_this(); }
60 /**
61 * Detach from resources without disposing them.
63 virtual void detach() { }
65 /**
66 * Clear board. Undefined for almost all controllers.
67 * @return Whether the action has been successfully executed.
69 virtual bool clearBoard() { return false; }
71 /**
72 * Set starting position on the board. Undefined for almost all controllers.
73 * @return Whether the action has been successfully executed.
75 virtual bool setStartingPosition() { return false; }
77 /**
78 * Set a position on the board. Undefined for almost all controllers.
79 * @param fen The position to be set, in FEN notation.
80 * @return Whether the action has been successfully executed.
82 virtual bool setFEN(const QString&) { return false; }
84 /**
85 * Get a FEN string representing the current position on the board.
87 virtual QString fen() { return ""; }
89 /**
90 * @return current position, or a null shared_ptr if no current position
91 * concept is defined for this controller.
93 virtual PositionPtr currentPosition() const { return PositionPtr(); }
95 /**
96 * Change turn. Used for example in edit position mode.
98 virtual void setTurn(int) { }
101 * Forward a movelist undo call.
103 virtual bool undo();
106 * Forward a movelist redo call.
108 virtual bool redo();
111 * Forward a movelist truncate call.
113 virtual bool truncate();
116 * Forward a movelist promote variation call.
118 virtual bool promoteVariation();
121 * Navigate back in history.
123 virtual bool back();
126 * Navigate forward in history.
128 virtual bool forward();
131 * Warp to the beginning of the history.
133 virtual void gotoFirst();
136 * Warp to the end of the history.
138 virtual void gotoLast();
141 * Save game.
143 virtual QString save();
146 * Load game from a PGN.
148 virtual void loadPGN(const PGN&);
151 * Create a CTRL Action.
152 * @sa UI::createCtrlAction
154 virtual void createCtrlAction() { }
157 * Destroy a CTRL Action.
158 * @sa UI::createCtrlAction.
160 virtual void destroyCtrlAction() { };
163 * Let an engine play as player @a side.
164 * @return a token which uniquely identifies the engine entity
165 * and can be used to remove it from the entity list.
167 virtual EntityToken addPlayingEngine(int /*side*/, const boost::shared_ptr<Engine>&) { return EntityToken(); }
170 * Remove an entity from the controller list.
172 virtual void removeEntity(const EntityToken&) { }
176 #endif