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"
17 #include "enginenotifier.h"
20 using namespace boost
;
22 QRegExp
GNUShogiEngine::m_move_pattern("[0-9]*\\. \\.\\.\\. ([^ ]*) .*");
24 GNUShogiEngine::GNUShogiEngine(const QString
& path
, const QStringList
& arguments
)
25 : Engine(path
, arguments
)
26 , m_analysing(false) {
27 // set default features
28 m_features
.ping
= false;
29 m_features
.setboard
= false;
30 m_features
.playother
= false;
31 m_features
.san
= false;
32 m_features
.usermove
= false;
33 m_features
.time
= true;
34 m_features
.draw
= true;
35 m_features
.sigint
= true;
36 m_features
.sigterm
= true;
37 m_features
.reuse
= true;
38 m_features
.analyze
= false;
39 m_features
.colors
= true;
40 m_features
.ics
= false;
41 m_features
.name
= false;
42 m_features
.pause
= false;
44 m_features
.myname
= QFileInfo(m_path
).baseName();
46 connect(this, SIGNAL(receivedCommand(const QString
&)),
47 this, SLOT(processCommand(const QString
&)));
50 GNUShogiEngine::~GNUShogiEngine() {
51 std::cout
<< "[debug] destroying engine" << std::endl
;
56 void GNUShogiEngine::initializeEngine() {
57 // nothing special to do
60 void GNUShogiEngine::reset() {
61 sendCommand("new"); // start a new game
62 sendCommand("force"); // do not think
65 void GNUShogiEngine::play() {
66 sendCommand("go"); // start playing
69 void GNUShogiEngine::stop() {
71 if (m_features
.sigterm
)
75 void GNUShogiEngine::processCommand(const QString
& command
) {
76 //QStringList arg_list = command.split(QRegExp("\\s+"));
77 //QString cmd = arg_list.takeFirst();
79 if (m_move_pattern
.indexIn(command
) == 0) {
80 if (shared_ptr
<EngineNotifier
> notifier
= m_notifier
.lock())
81 notifier
->notifyEngineMove(m_move_pattern
.cap(1));
85 void GNUShogiEngine::sendMove(AbstractMove::Ptr move
, AbstractPosition::Ptr ref
) {
86 QString move_str
= move
->toString("simple", ref
);
87 sendCommand(move_str
);
90 void GNUShogiEngine::backUp(AbstractPosition::Ptr
) {
94 void GNUShogiEngine::startAnalysis() {
96 sendCommand("analyze");
100 void GNUShogiEngine::stopAnalysis() {
105 void GNUShogiEngine::setBoard(AbstractPosition::Ptr
, int, int) {
107 if (m_features
.setboard
) {
108 sendCommand(QString("setboard %1").arg(pos
->fen(halfmove
, fullmove
)));
111 // this is pretty meaningless for generic variants
112 if (pos
->turn() != 0) {
119 Point size
= pos
->size();
120 for (int i
= 0; i
< size
.x
; i
++) {
121 for (int j
= 0; j
< size
.y
; j
++) {
123 AbstractPiece::Ptr piece
= pos
->get(p
);
124 if (piece
) sendCommand(QString("%1%2")
126 .arg(p
.toString(8)));