From 2902dd8ca09fb6137fa4ef565c3b1f79d795de7c Mon Sep 17 00:00:00 2001
From: Paolo Capriotti
Date: Sat, 15 Dec 2007 13:33:58 +0100
Subject: [PATCH] Add Crazyhouse stub using a state delegator.
---
src/core/delegators/defaultstate.h | 3 +++
src/core/delegators/state.h | 7 +++---
src/variants/CMakeLists.txt | 2 ++
src/variants/crazyhouse/CMakeLists.txt | 19 +++++++++++++++
src/variants/crazyhouse/crazyhouse.cpp | 30 ++++++++++++++++++++++++
src/variants/crazyhouse/state.cpp | 17 ++++++++++++++
src/variants/crazyhouse/state.h | 25 ++++++++++++++++++++
src/variants/crazyhouse/statefactory.cpp | 27 +++++++++++++++++++++
src/variants/crazyhouse/statefactory.h | 29 +++++++++++++++++++++++
src/variants/crazyhouse/tagua-crazyhouse.desktop | 21 +++++++++++++++++
10 files changed, 177 insertions(+), 3 deletions(-)
create mode 100644 src/variants/crazyhouse/CMakeLists.txt
create mode 100644 src/variants/crazyhouse/crazyhouse.cpp
create mode 100644 src/variants/crazyhouse/state.cpp
create mode 100644 src/variants/crazyhouse/state.h
create mode 100644 src/variants/crazyhouse/statefactory.cpp
create mode 100644 src/variants/crazyhouse/statefactory.h
create mode 100644 src/variants/crazyhouse/tagua-crazyhouse.desktop
diff --git a/src/core/delegators/defaultstate.h b/src/core/delegators/defaultstate.h
index e953ee2..2fd9e54 100644
--- a/src/core/delegators/defaultstate.h
+++ b/src/core/delegators/defaultstate.h
@@ -16,6 +16,7 @@
namespace Delegators {
class DefaultState : public IDefaultState {
+protected:
IDefaultState* m_state;
public:
DefaultState(IDefaultState* state) : m_state(state) { }
@@ -29,4 +30,6 @@ public:
virtual Point captureSquare(const Move& move) const { return m_state->captureSquare(move); }
};
+}
+
#endif // DELEGATORS__DEFAULTSTATE_H
diff --git a/src/core/delegators/state.h b/src/core/delegators/state.h
index 1f97691..2f133bf 100644
--- a/src/core/delegators/state.h
+++ b/src/core/delegators/state.h
@@ -13,7 +13,7 @@
#include "../state.h"
#define STATE_DELEGATORS \
- virtual IState* clone() const { return state->clone(); } \
+ virtual IState* clone() const { return m_state->clone(); } \
virtual void setup() { m_state->setup(); } \
virtual const Board* board() const { return m_state->board(); } \
virtual Board* board() { return m_state->board(); } \
@@ -25,11 +25,12 @@
virtual TaguaObject flags() const { return m_state->flags(); } \
virtual const IColor* opponent(const IColor* color) const { return m_state->opponent(color); } \
virtual void advanceTurn() { m_state->advanceTurn(); } \
- virtual int rank(int n, const IColor* turn) { return m_state->rank(n, turn); }
+ virtual int rank(int n, const IColor* turn) const { return m_state->rank(n, turn); }
namespace Delegators {
class State : public IState {
+protected:
IState* m_state;
public:
State(IState* state) : m_state(state) { }
@@ -38,6 +39,6 @@ public:
STATE_DELEGATORS
};
-};
+}
#endif // DELEGATORS__STATE_H
diff --git a/src/variants/CMakeLists.txt b/src/variants/CMakeLists.txt
index 8e2f248..f45132e 100644
--- a/src/variants/CMakeLists.txt
+++ b/src/variants/CMakeLists.txt
@@ -1,2 +1,4 @@
add_subdirectory(chess)
add_subdirectory(chess5x5)
+add_subdirectory(crazyhouse)
+
diff --git a/src/variants/crazyhouse/CMakeLists.txt b/src/variants/crazyhouse/CMakeLists.txt
new file mode 100644
index 0000000..8c15098
--- /dev/null
+++ b/src/variants/crazyhouse/CMakeLists.txt
@@ -0,0 +1,19 @@
+set(taguacrazyhouse_SRCS
+ crazyhouse.cpp
+ state.cpp
+ statefactory.cpp
+)
+
+# we don't need taguachess includes!
+include_directories(${CMAKE_SOURCE_DIR}/src/)
+
+kde4_add_plugin(taguacrazyhouse ${taguacrazyhouse_SRCS})
+
+# we don't need to link to taguachess!
+target_link_libraries(taguacrazyhouse
+ taguacore
+ ${KDE4_KDECORE_LIBS}
+)
+
+install(TARGETS taguacrazyhouse DESTINATION ${PLUGIN_INSTALL_DIR})
+install(FILES tagua-crazyhouse.desktop DESTINATION ${SERVICES_INSTALL_DIR})
diff --git a/src/variants/crazyhouse/crazyhouse.cpp b/src/variants/crazyhouse/crazyhouse.cpp
new file mode 100644
index 0000000..9f62227
--- /dev/null
+++ b/src/variants/crazyhouse/crazyhouse.cpp
@@ -0,0 +1,30 @@
+/*
+ Copyright (c) 2007 Paolo Capriotti
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+*/
+
+#include
+#include
+
+#include "statefactory.h"
+
+using namespace Crazyhouse;
+
+extern "C" KDE_EXPORT Repository*
+taguacrazyhouse_initrepo(IVariantLoader* loader) {
+ Repository* repo = new Repository;
+ Repository* chess = loader->getRepository("chess");
+ if (!chess) return 0;
+ repo->setProxy(chess);
+
+ IStateFactory* chess_state_factory =
+ requestInterface(chess->getComponent("state_factory"));
+ repo->addComponent("state_factory", new StateFactory(chess_state_factory));
+
+ return repo;
+}
+
diff --git a/src/variants/crazyhouse/state.cpp b/src/variants/crazyhouse/state.cpp
new file mode 100644
index 0000000..39f3c0d
--- /dev/null
+++ b/src/variants/crazyhouse/state.cpp
@@ -0,0 +1,17 @@
+/*
+ Copyright (c) 2007 Paolo Capriotti
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+*/
+
+#include "state.h"
+
+namespace Crazyhouse {
+
+State::State(IDefaultState* state)
+: Delegators::DefaultState(state) { }
+
+} // namespace Crazyhouse
diff --git a/src/variants/crazyhouse/state.h b/src/variants/crazyhouse/state.h
new file mode 100644
index 0000000..59f88fc
--- /dev/null
+++ b/src/variants/crazyhouse/state.h
@@ -0,0 +1,25 @@
+/*
+ Copyright (c) 2007 Paolo Capriotti
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+*/
+
+#ifndef CRAZYHOUSE__STATE_H
+#define CRAZYHOUSE__STATE_H
+
+#include
+
+namespace Crazyhouse {
+
+class State : public Delegators::DefaultState {
+public:
+ State(IDefaultState* state);
+};
+
+} // namespace Crazyhouse
+
+#endif // CRAZYHOUSE__STATE_H
+
diff --git a/src/variants/crazyhouse/statefactory.cpp b/src/variants/crazyhouse/statefactory.cpp
new file mode 100644
index 0000000..8950005
--- /dev/null
+++ b/src/variants/crazyhouse/statefactory.cpp
@@ -0,0 +1,27 @@
+/*
+ Copyright (c) 2007 Paolo Capriotti
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+*/
+
+#include
+
+#include "statefactory.h"
+#include "state.h"
+
+namespace Crazyhouse {
+
+StateFactory::StateFactory(IStateFactory* factory)
+: m_factory(factory) { }
+
+IState* StateFactory::createState() const {
+ IState* state_ = m_factory->createState();
+ TAGUA_CAST(state, IDefaultState, 0);
+
+ return new State(state);
+}
+
+} // namespace Crazyhouse
diff --git a/src/variants/crazyhouse/statefactory.h b/src/variants/crazyhouse/statefactory.h
new file mode 100644
index 0000000..30527fc
--- /dev/null
+++ b/src/variants/crazyhouse/statefactory.h
@@ -0,0 +1,29 @@
+/*
+ Copyright (c) 2007 Paolo Capriotti
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+*/
+
+#ifndef CRAZYHOUSE__STATEFACTORY_H
+#define CRAZYHOUSE__STATEFACTORY_H
+
+#include
+#include
+
+namespace Crazyhouse {
+
+class StateFactory : public Component, public IStateFactory {
+ IStateFactory* m_factory;
+public:
+ StateFactory(IStateFactory* factory);
+
+ virtual IState* createState() const;
+};
+
+} // namespace Crazyhouse
+
+#endif // CRAZYHOUSE__STATEFACTORY_H
+
diff --git a/src/variants/crazyhouse/tagua-crazyhouse.desktop b/src/variants/crazyhouse/tagua-crazyhouse.desktop
new file mode 100644
index 0000000..b7e7675
--- /dev/null
+++ b/src/variants/crazyhouse/tagua-crazyhouse.desktop
@@ -0,0 +1,21 @@
+[Desktop Entry]
+Encoding=UTF-8
+Name=Crazyhouse
+Comment=The game of Crazyhouse
+Icon=tagua
+Type=Service
+ServiceTypes=Tagua/Variant
+
+X-KDE-Library=taguacrazyhouse
+X-KDE-PluginInfo-Author=Paolo Capriotti
+X-KDE-PluginInfo-Email=p.capriotti@gmail.com
+X-KDE-PluginInfo-Name=crazyhouse
+X-KDE-PluginInfo-Version=0.0.1
+X-KDE-PluginInfo-Website=http://www.tagua-project.org
+X-KDE-PluginInfo-Depends=chess
+X-KDE-PluginInfo-License=GPL
+X-KDE-PluginInfo-EnabledByDefault=true
+
+X-Tagua-Proxy=Chess
+X-Tagua-Hidden=false
+
--
2.11.4.GIT