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 #ifndef GAMEBASEDRULES_H
15 #define GAMEBASEDRULES_H
27 virtual ~TurnTest() { }
28 virtual bool operator()(int turn
) const = 0;
31 class FreeTurnTest
: public TurnTest
{
33 virtual bool operator()(int) const { return true; }
36 class NoTurnTest
: public TurnTest
{
38 virtual bool operator()(int) const { return false; }
41 class OneTurnTest
: public TurnTest
{
46 virtual bool operator()(int turn
) const {
47 return turn
== m_turn
;
51 class UserEntity
: public Entity
54 boost::shared_ptr
<TurnTest
> m_turn_test
;
58 UserEntity(const GamePtr
& game
, int);
59 virtual void setTurnTest(const boost::shared_ptr
<TurnTest
>& test
) { m_turn_test
= test
; }
60 virtual void enableEditingTools(bool value
);
63 void changePromotionType(int type
) { m_promotion
= type
; }
64 void setPromotion(NormalUserMove
& move
) { move
.promotionType
= m_promotion
; }
65 int promotionType() const { return m_promotion
; }
68 * Return a PGN for the game.
70 virtual QString
save() const = 0;
73 * Load the content of a PGN inside the game.
75 virtual void loadPGN(const PGN
& pgn
) = 0;
77 virtual AbstractMove::Ptr
testMove(const NormalUserMove
& m
) const = 0;
78 virtual AbstractMove::Ptr
testMove(const DropUserMove
& m
) const = 0;
79 virtual bool testPremove(const NormalUserMove
& m
) const = 0;
80 virtual bool testPremove(const DropUserMove
&) const = 0;
81 virtual void executeMove(AbstractMove::Ptr move
) = 0;
82 virtual void addPremove(const NormalUserMove
& m
) = 0;
83 virtual void addPremove(const DropUserMove
& m
) = 0;
84 virtual void cancelPremove() = 0;
85 virtual void handleRightClick(const Point
&) const;
87 virtual InteractionType
validTurn(const Point
&) const = 0;
88 virtual InteractionType
validTurn(int) const = 0;
89 virtual bool movable(const Point
&) const = 0;
90 virtual bool oneClickMoves() const { return false; }
93 * Jump to the end of the game.
95 virtual bool gotoFirst() = 0;
98 * Jump to the beginning of the game.
100 virtual bool gotoLast() = 0;
103 * Jump to an arbitrary index.
105 virtual bool goTo(const Index
& index
) = 0;
108 * Go forward one move in the game.
110 virtual bool forward() = 0;
113 * Go back one move in the game.
115 virtual bool back() = 0;
118 * Undo the last editing action.
120 virtual bool undo() = 0;
123 * Redo the last editing action.
125 virtual bool redo() = 0;
128 * Remove the current position.
130 virtual bool truncate() = 0;
133 * Promote the current variation to mainline.
135 virtual bool promoteVariation() = 0;
139 * @sa AbstractPosition::moveHint
141 virtual AbstractPiece::Ptr
moveHint(AbstractMove::Ptr
) const { return AbstractPiece::Ptr(); }
143 virtual bool canDetach() const;
147 #endif // GAMEBASEDRULES_H
150 #endif // USERENTITY_H