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.
14 #include <boost/enable_shared_from_this.hpp>
17 #include "entitytoken.h"
24 class ActionCollection
;
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
34 class Controller
: public boost::enable_shared_from_this
<Controller
> {
37 ActionCollection
* m_variant_actions
;
38 virtual boost::shared_ptr
<UserEntity
> entity() const = 0;
40 Controller(ChessTable
* view
);
41 virtual ~Controller();
44 * Variant specific actions.
46 ActionCollection
* variantActions() const;
49 * Variant associated to the controller.
51 virtual QString
variant() const = 0;
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
58 virtual boost::shared_ptr
<Controller
> end() { return shared_from_this(); }
61 * Detach from resources without disposing them.
63 virtual void detach() { }
66 * Clear board. Undefined for almost all controllers.
67 * @return Whether the action has been successfully executed.
69 virtual bool clearBoard() { return false; }
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; }
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; }
85 * Get a FEN string representing the current position on the board.
87 virtual QString
fen() { return ""; }
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(); }
96 * Change turn. Used for example in edit position mode.
98 virtual void setTurn(int) { }
101 * Forward a movelist undo call.
106 * Forward a movelist redo call.
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.
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();
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
&) { }