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.
11 #include "examinationentity.h"
13 #include "icsconnection.h"
14 #include "positioninfo.h"
15 #include "algebraicnotation.h"
16 #include "pgnparser.h"
17 #include "variants/xchess/piecetype.h"
21 ExaminationEntity::ExaminationEntity(VariantInfo
* variant
, const boost::shared_ptr
<Game
>& game
,
22 int game_number
, const boost::shared_ptr
<ICSConnection
>& connection
,
24 : UserEntity(game
, QUEEN
)
26 , m_game_number(game_number
)
27 , m_connection(connection
)
28 , m_dispatcher(group
, this) { }
30 QString
ExaminationEntity::save() const {
34 void ExaminationEntity::loadPGN(const PGN
& pgn
) {
38 AbstractMove::Ptr
ExaminationEntity::testMove(const NormalUserMove
&) const {
39 return AbstractMove::Ptr();
41 AbstractMove::Ptr
ExaminationEntity::testMove(const DropUserMove
&) const {
42 return AbstractMove::Ptr();
45 bool ExaminationEntity::testPremove(const NormalUserMove
&) const { return false; }
46 bool ExaminationEntity::testPremove(const DropUserMove
&) const { return false; }
47 void ExaminationEntity::executeMove(boost::shared_ptr
<AbstractMove
>) { }
48 void ExaminationEntity::addPremove(const NormalUserMove
&) { }
49 void ExaminationEntity::addPremove(const DropUserMove
&) { }
50 void ExaminationEntity::cancelPremove() { }
51 InteractionType
ExaminationEntity::validTurn(const Point
&) const { return NoAction
; }
52 InteractionType
ExaminationEntity::validTurn(int) 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 std::cout
<< "[entity] forward" << std::endl
;
81 m_connection
->sendText("forward");
85 bool ExaminationEntity::back() {
86 m_connection
->sendText("back");
90 bool ExaminationEntity::undo() { return true; }
91 bool ExaminationEntity::redo() { return true; }
92 bool ExaminationEntity::truncate() { return true; }
93 bool ExaminationEntity::promoteVariation() { return true; }
95 void ExaminationEntity::notifyStyle12(const PositionInfo
& style12
, bool /*is_starting*/) {
96 m_dispatcher
.clockUpdate(style12
.whiteTime
, style12
.blackTime
);
98 if (style12
.index() > 0) {
99 AbstractMove::Ptr last_move
= m_variant
->getVerboseMove(
100 style12
.position
->previousTurn(),
101 VerboseNotation(style12
.lastMove
, style12
.position
->size().y
));
102 m_game
->insert(last_move
, style12
.position
, style12
.index());
105 m_game
->goTo(style12
.index());
107 void ExaminationEntity::notifyPool(const class PoolInfo
&) { /*TODO */ }
108 void ExaminationEntity::notifyMoveList(int, AbstractPosition::Ptr
, const PGN
&){ /* TODO */ }
109 void ExaminationEntity::notifyMove(const Index
&) { }
110 void ExaminationEntity::notifyBack() { }
111 void ExaminationEntity::notifyForward() { }
112 void ExaminationEntity::notifyGotoFirst() { }
113 void ExaminationEntity::notifyGotoLast() { }
115 bool ExaminationEntity::attach() {
116 return m_game
->lastMainlineIndex() == 0;