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.
11 #include <core/state.h>
13 #include "examinationentity.h"
15 #include "icsconnection.h"
16 #include "positioninfo.h"
17 #include "pgnparser.h"
22 ExaminationEntity::ExaminationEntity(Components
* components
, const boost::shared_ptr
<Game
>& game
,
23 int game_number
, const boost::shared_ptr
<ICSConnection
>& connection
,
26 , m_components(components
)
27 , m_game_number(game_number
)
28 , m_connection(connection
)
29 , m_dispatcher(group
, this) {
33 QString
ExaminationEntity::save() const {
37 void ExaminationEntity::loadPGN(const PGN
& pgn
) {
41 bool ExaminationEntity::testMove(Move
&) const {
45 bool ExaminationEntity::testPremove(const Move
&) const { return false; }
46 void ExaminationEntity::executeMove(const Move
&) { }
47 void ExaminationEntity::addPremove(const Move
&) { }
48 void ExaminationEntity::cancelPremove() { }
50 InteractionType
ExaminationEntity::validTurn(const Point
&) const { return NoAction
; }
51 InteractionType
ExaminationEntity::validTurn(const IColor
*) const { return NoAction
; }
52 bool ExaminationEntity::movable(const Point
&) const { return false; }
53 bool ExaminationEntity::jump(const Index
&) { return true; }
55 bool ExaminationEntity::gotoFirst() {
56 m_connection
->sendText("back 99999");
60 bool ExaminationEntity::gotoLast() {
61 m_connection
->sendText("forward 99999");
65 bool ExaminationEntity::goTo(const Index
& index
) {
66 std::pair
<int, int> steps
= m_game
->index().stepsTo(index
);
67 if (steps
.first
== 0) {
68 m_connection
->sendText(QString("forward %1").arg(steps
.second
));
71 else if (steps
.second
== 0) {
72 m_connection
->sendText(QString("back %1").arg(steps
.first
));
78 bool ExaminationEntity::forward() {
79 m_connection
->sendText("forward");
83 bool ExaminationEntity::back() {
84 m_connection
->sendText("back");
88 bool ExaminationEntity::undo() { return true; }
89 bool ExaminationEntity::redo() { return true; }
90 bool ExaminationEntity::truncate() { return true; }
91 bool ExaminationEntity::promoteVariation() { return true; }
93 void ExaminationEntity::notifyStyle12(const PositionInfo
& style12
, bool /*is_starting*/) {
94 m_dispatcher
.clockUpdate(style12
.whiteTime
, style12
.blackTime
);
96 if (style12
.index() > 0) {
97 Move last_move
= m_icsapi
->parseVerbose(style12
.lastMove
, style12
.position
);
98 m_game
->insert(last_move
, style12
.position
, style12
.index());
101 m_game
->goTo(style12
.index());
103 void ExaminationEntity::notifyPool(const class PoolInfo
&) { /*TODO */ }
104 void ExaminationEntity::notifyMoveList(int, const StatePtr
&, const PGN
&){ /* TODO */ }
105 void ExaminationEntity::notifyMove(const Index
&) { }
106 void ExaminationEntity::notifyBack() { }
107 void ExaminationEntity::notifyForward() { }
108 void ExaminationEntity::notifyGotoFirst() { }
109 void ExaminationEntity::notifyGotoLast() { }
111 bool ExaminationEntity::attach() {
112 return m_game
->lastMainlineIndex() == 0;