new 4475edb243ed4627f4c5f2c470ca40b3def034d4
[tagua/yd.git] / src / entities / examinationentity.cpp
bloba8d8fe8514eb2185ad0ac8684490da7f556cf767
1 /*
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.
9 */
11 #include <core/state.h>
13 #include "examinationentity.h"
14 #include "game.h"
15 #include "icsconnection.h"
16 #include "positioninfo.h"
17 #include "pgnparser.h"
18 #include "icsapi.h"
20 #include <iostream>
22 ExaminationEntity::ExaminationEntity(Components* components, const boost::shared_ptr<Game>& game,
23 int game_number, const boost::shared_ptr<ICSConnection>& connection,
24 AgentGroup* group)
25 : UserEntity(game)
26 , m_components(components)
27 , m_game_number(game_number)
28 , m_connection(connection)
29 , m_dispatcher(group, this) {
30 Q_ASSERT(m_icsapi);
33 QString ExaminationEntity::save() const {
34 return m_game->pgn();
37 void ExaminationEntity::loadPGN(const PGN& pgn) {
38 m_game->load(pgn);
41 bool ExaminationEntity::testMove(Move&) const {
42 return false;
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");
57 return true;
60 bool ExaminationEntity::gotoLast() {
61 m_connection->sendText("forward 99999");
62 return true;
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));
69 return true;
71 else if (steps.second == 0) {
72 m_connection->sendText(QString("back %1").arg(steps.first));
73 return true;
75 else return false;
78 bool ExaminationEntity::forward() {
79 m_connection->sendText("forward");
80 return true;
83 bool ExaminationEntity::back() {
84 m_connection->sendText("back");
85 return true;
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;