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 "gnushogiengine.h"
16 #include "enginenotifier.h"
19 using namespace boost
;
21 QRegExp
GNUShogiEngine::m_move_pattern("[0-9]*\\. \\.\\.\\. ([^ ]*) .*");
23 GNUShogiEngine::GNUShogiEngine(const QString
& path
, const QStringList
& arguments
)
24 : Engine(path
, arguments
)
25 , m_analysing(false) {
26 // set default features
27 m_features
.ping
= false;
28 m_features
.setboard
= false;
29 m_features
.playother
= false;
30 m_features
.san
= false;
31 m_features
.usermove
= false;
32 m_features
.time
= true;
33 m_features
.draw
= true;
34 m_features
.sigint
= true;
35 m_features
.sigterm
= true;
36 m_features
.reuse
= true;
37 m_features
.analyze
= false;
38 m_features
.colors
= true;
39 m_features
.ics
= false;
40 m_features
.name
= false;
41 m_features
.pause
= false;
43 m_features
.myname
= QFileInfo(m_path
).baseName();
45 connect(this, SIGNAL(receivedCommand(const QString
&)),
46 this, SLOT(processCommand(const QString
&)));
49 GNUShogiEngine::~GNUShogiEngine() {
50 kDebug() << "[debug] destroying engine";
55 void GNUShogiEngine::initializeEngine() {
56 // nothing special to do
59 void GNUShogiEngine::reset() {
60 sendCommand("new"); // start a new game
61 sendCommand("force"); // do not think
64 void GNUShogiEngine::play() {
65 sendCommand("go"); // start playing
68 void GNUShogiEngine::stop() {
70 if (m_features
.sigterm
)
74 void GNUShogiEngine::processCommand(const QString
& command
) {
75 //QStringList arg_list = command.split(QRegExp("\\s+"));
76 //QString cmd = arg_list.takeFirst();
78 if (m_move_pattern
.indexIn(command
) == 0) {
79 if (shared_ptr
<EngineNotifier
> notifier
= m_notifier
.lock())
80 notifier
->notifyEngineMove(m_move_pattern
.cap(1));
84 void GNUShogiEngine::sendMove(AbstractMove::Ptr move
, AbstractPosition::Ptr ref
) {
85 QString move_str
= move
->toString("simple", ref
);
86 sendCommand(move_str
);
89 void GNUShogiEngine::backUp(AbstractPosition::Ptr
) {
93 void GNUShogiEngine::startAnalysis() {
95 sendCommand("analyze");
99 void GNUShogiEngine::stopAnalysis() {
104 void GNUShogiEngine::setBoard(AbstractPosition::Ptr
, int, int) {
106 if (m_features
.setboard
) {
107 sendCommand(QString("setboard %1").arg(pos
->fen(halfmove
, fullmove
)));
110 // this is pretty meaningless for generic variants
111 if (pos
->turn() != 0) {
118 Point size
= pos
->size();
119 for (int i
= 0; i
< size
.x
; i
++) {
120 for (int j
= 0; j
< size
.y
; j
++) {
122 AbstractPiece::Ptr piece
= pos
->get(p
);
123 if (piece
) sendCommand(QString("%1%2")
125 .arg(p
.toString(8)));