2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@gmail.com>
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 virtual boost::shared_ptr
<UserEntity
> entity() const = 0;
39 Controller(ChessTable
* view
);
40 virtual ~Controller();
43 * Variant specific actions.
45 virtual ActionCollection
* variantActions() const = 0;
48 * Variant associated to the controller.
50 virtual QString
variant() const = 0;
53 * Terminate activity, create another controller and delegate everything to it.
54 * @return The delegate controller, or simply @b this if controller does not need
57 virtual boost::shared_ptr
<Controller
> end() { return shared_from_this(); }
60 * Detach from resources without disposing them.
62 virtual void detach() { }
65 * Clear board. Undefined for almost all controllers.
66 * @return Whether the action has been successfully executed.
68 virtual bool clearBoard() { return false; }
71 * Set starting position on the board. Undefined for almost all controllers.
72 * @return Whether the action has been successfully executed.
74 virtual bool setStartingPosition() { return false; }
77 * Set a position on the board. Undefined for almost all controllers.
78 * @param fen The position to be set, in FEN notation.
79 * @return Whether the action has been successfully executed.
81 virtual bool setFEN(const QString
&) { return false; }
84 * Get a FEN string representing the current position on the board.
86 virtual QString
fen() { return ""; }
89 * @return current position, or a null shared_ptr if no current position
90 * concept is defined for this controller.
92 virtual PositionPtr
currentPosition() const { return PositionPtr(); }
95 * Change turn. Used for example in edit position mode.
97 virtual void setTurn(int) { }
100 * Forward a movelist undo call.
105 * Forward a movelist redo call.
110 * Forward a movelist truncate call.
112 virtual bool truncate();
115 * Forward a movelist promote variation call.
117 virtual bool promoteVariation();
120 * Navigate back in history.
125 * Navigate forward in history.
127 virtual bool forward();
130 * Warp to the beginning of the history.
132 virtual void gotoFirst();
135 * Warp to the end of the history.
137 virtual void gotoLast();
142 virtual QString
save();
145 * Load game from a PGN.
147 virtual void loadPGN(const PGN
&);
150 * Create a CTRL Action.
151 * @sa UI::createCtrlAction
153 virtual void createCtrlAction() { }
156 * Destroy a CTRL Action.
157 * @sa UI::createCtrlAction.
159 virtual void destroyCtrlAction() { };
162 * Let an engine play as player @a side.
163 * @return a token which uniquely identifies the engine entity
164 * and can be used to remove it from the entity list.
166 virtual EntityToken
addPlayingEngine(int /*side*/, const boost::shared_ptr
<Engine
>&) { return EntityToken(); }
169 * Remove an entity from the controller list.
171 virtual void removeEntity(const EntityToken
&) { }