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>
12 #include <core/variant.h>
14 #include "examinationentity.h"
16 #include "icsconnection.h"
17 #include "positioninfo.h"
18 #include "pgnparser.h"
23 ExaminationEntity::ExaminationEntity(Variant
* variant
, const boost::shared_ptr
<Game
>& game
,
24 int game_number
, const boost::shared_ptr
<ICSConnection
>& connection
,
28 , m_game_number(game_number
)
29 , m_connection(connection
)
30 , m_dispatcher(group
, this) {
34 QString
ExaminationEntity::save() const {
38 void ExaminationEntity::loadPGN(const PGN
& pgn
) {
42 bool ExaminationEntity::testMove(Move
&) const {
46 bool ExaminationEntity::testPremove(const Move
&) const { return false; }
47 void ExaminationEntity::executeMove(const Move
&) { }
48 void ExaminationEntity::addPremove(const Move
&) { }
49 void ExaminationEntity::cancelPremove() { }
51 InteractionType
ExaminationEntity::validTurn(const Point
&) const { return NoAction
; }
52 InteractionType
ExaminationEntity::validTurn(const IColor
*) const { return NoAction
; }
53 bool ExaminationEntity::movable(const Point
&) const { return false; }
54 bool ExaminationEntity::jump(const Index
&) { return true; }
56 bool ExaminationEntity::gotoFirst() {
57 m_connection
->sendText("back 99999");
61 bool ExaminationEntity::gotoLast() {
62 m_connection
->sendText("forward 99999");
66 bool ExaminationEntity::goTo(const Index
& index
) {
67 std::pair
<int, int> steps
= m_game
->index().stepsTo(index
);
68 if (steps
.first
== 0) {
69 m_connection
->sendText(QString("forward %1").arg(steps
.second
));
72 else if (steps
.second
== 0) {
73 m_connection
->sendText(QString("back %1").arg(steps
.first
));
79 bool ExaminationEntity::forward() {
80 m_connection
->sendText("forward");
84 bool ExaminationEntity::back() {
85 m_connection
->sendText("back");
89 bool ExaminationEntity::undo() { return true; }
90 bool ExaminationEntity::redo() { return true; }
91 bool ExaminationEntity::truncate() { return true; }
92 bool ExaminationEntity::promoteVariation() { return true; }
94 void ExaminationEntity::notifyStyle12(const PositionInfo
& style12
, bool /*is_starting*/) {
95 m_dispatcher
.clockUpdate(style12
.whiteTime
, style12
.blackTime
);
97 if (style12
.index() > 0) {
98 Move last_move
= m_icsapi
->parseVerbose(style12
.lastMove
, style12
.position
);
99 m_game
->insert(last_move
, style12
.position
, style12
.index());
102 m_game
->goTo(style12
.index());
104 void ExaminationEntity::notifyPool(const class PoolInfo
&) { /*TODO */ }
105 void ExaminationEntity::notifyMoveList(int, const StatePtr
&, const PGN
&){ /* TODO */ }
106 void ExaminationEntity::notifyMove(const Index
&) { }
107 void ExaminationEntity::notifyBack() { }
108 void ExaminationEntity::notifyForward() { }
109 void ExaminationEntity::notifyGotoFirst() { }
110 void ExaminationEntity::notifyGotoLast() { }
112 bool ExaminationEntity::attach() {
113 return m_game
->lastMainlineIndex() == 0;