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 <core/moveserializer.h>
17 #include "components.h"
19 #include "enginenotifier.h"
22 using namespace boost
;
24 QRegExp
GNUShogiEngine::m_move_pattern("[0-9]*\\. \\.\\.\\. ([^ ]*) .*");
26 GNUShogiEngine::GNUShogiEngine(Components
* components
,
28 const QStringList
& arguments
)
29 : Engine(path
, arguments
)
30 , m_analysing(false) {
31 // set default features
32 m_features
.ping
= false;
33 m_features
.setboard
= false;
34 m_features
.playother
= false;
35 m_features
.san
= false;
36 m_features
.usermove
= false;
37 m_features
.time
= true;
38 m_features
.draw
= true;
39 m_features
.sigint
= true;
40 m_features
.sigterm
= true;
41 m_features
.reuse
= true;
42 m_features
.analyze
= false;
43 m_features
.colors
= true;
44 m_features
.ics
= false;
45 m_features
.name
= false;
46 m_features
.pause
= false;
48 m_features
.myname
= QFileInfo(m_path
).baseName();
50 connect(this, SIGNAL(receivedCommand(const QString
&)),
51 this, SLOT(processCommand(const QString
&)));
53 m_serializer
= components
->moveSerializer("simple");
56 GNUShogiEngine::~GNUShogiEngine() {
57 kDebug() << "[debug] destroying engine";
62 void GNUShogiEngine::initializeEngine() {
63 // nothing special to do
66 void GNUShogiEngine::reset() {
67 sendCommand("new"); // start a new game
68 sendCommand("force"); // do not think
71 void GNUShogiEngine::play() {
72 sendCommand("go"); // start playing
75 void GNUShogiEngine::stop() {
77 if (m_features
.sigterm
)
81 void GNUShogiEngine::processCommand(const QString
& command
) {
82 //QStringList arg_list = command.split(QRegExp("\\s+"));
83 //QString cmd = arg_list.takeFirst();
85 if (m_move_pattern
.indexIn(command
) == 0) {
86 if (shared_ptr
<EngineNotifier
> notifier
= m_notifier
.lock())
87 notifier
->notifyEngineMove(m_move_pattern
.cap(1));
91 void GNUShogiEngine::sendMove(const Move
& move
, const StatePtr
& ref
) {
92 QString move_str
= m_serializer
->serialize(move
, ref
.get());
93 sendCommand(move_str
);
96 void GNUShogiEngine::backUp(const StatePtr
&) {
100 void GNUShogiEngine::startAnalysis() {
102 sendCommand("analyze");
106 void GNUShogiEngine::stopAnalysis() {
111 void GNUShogiEngine::setBoard(const StatePtr
&) {
113 if (m_features
.setboard
) {
114 sendCommand(QString("setboard %1").arg(pos
->fen(halfmove
, fullmove
)));
117 // this is pretty meaningless for generic variants
118 if (pos
->turn() != 0) {
125 Point size
= pos
->size();
126 for (int i
= 0; i
< size
.x
; i
++) {
127 for (int j
= 0; j
< size
.y
; j
++) {
129 AbstractPiece::Ptr piece
= pos
->get(p
);
130 if (piece
) sendCommand(QString("%1%2")
132 .arg(p
.toString(8)));