Initial porting to the new component API.
[tagua/yd.git] / src / entities / examinationentity.cpp
blobf906e79e7b35f1490bfd6d32d8d1267ba51db44c
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>
12 #include <core/variant.h>
14 #include "examinationentity.h"
15 #include "game.h"
16 #include "icsconnection.h"
17 #include "positioninfo.h"
18 #include "pgnparser.h"
19 #include "icsapi.h"
21 #include <iostream>
23 ExaminationEntity::ExaminationEntity(Variant* variant, const boost::shared_ptr<Game>& game,
24 int game_number, const boost::shared_ptr<ICSConnection>& connection,
25 AgentGroup* group)
26 : UserEntity(game)
27 , m_variant(variant)
28 , m_game_number(game_number)
29 , m_connection(connection)
30 , m_dispatcher(group, this) {
31 Q_ASSERT(m_icsapi);
34 QString ExaminationEntity::save() const {
35 return m_game->pgn();
38 void ExaminationEntity::loadPGN(const PGN& pgn) {
39 m_game->load(pgn);
42 bool ExaminationEntity::testMove(Move&) const {
43 return false;
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");
58 return true;
61 bool ExaminationEntity::gotoLast() {
62 m_connection->sendText("forward 99999");
63 return true;
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));
70 return true;
72 else if (steps.second == 0) {
73 m_connection->sendText(QString("back %1").arg(steps.first));
74 return true;
76 else return false;
79 bool ExaminationEntity::forward() {
80 m_connection->sendText("forward");
81 return true;
84 bool ExaminationEntity::back() {
85 m_connection->sendText("back");
86 return true;
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;