Tentative Randomless-Entropy variant.mastermaster/entropy
authorYann Dirson <ydirson@altern.org>
Sun, 20 Apr 2008 19:52:43 +0000 (20 21:52 +0200)
committerYann Dirson <ydirson@altern.org>
Sun, 20 Apr 2008 19:52:43 +0000 (20 21:52 +0200)
16 files changed:
data/themes/squares/Default/theme_shogi.desktop
data/themes/squares/Default/theme_solid.desktop
debian/control
debian/tagua-variant-entropy.files [new file with mode: 0644]
src/variantfactories/builtinvariants.cpp
src/variants/CMakeLists.txt
src/variants/randomless-entropy/CMakeLists.txt [new file with mode: 0644]
src/variants/randomless-entropy/colors.cpp [new file with mode: 0644]
src/variants/randomless-entropy/colors.h [new file with mode: 0644]
src/variants/randomless-entropy/entropy.cpp [new file with mode: 0644]
src/variants/randomless-entropy/state.cpp [copied from src/variants/shogi/state.cpp with 51% similarity]
src/variants/randomless-entropy/state.h [new file with mode: 0644]
src/variants/randomless-entropy/stone.cpp [new file with mode: 0644]
src/variants/randomless-entropy/stone.h [new file with mode: 0644]
src/variants/randomless-entropy/tagua-randomlessentropy.desktop [new file with mode: 0644]
src/variants/shogi/state.cpp

index 85a8f42..799ad83 100644 (file)
@@ -4,4 +4,4 @@ Name=Shogi
 Type=Application
 Comment=Shogi-like squares
 X-Tagua-ThemeType=Squares
-X-Tagua-Variants=Shogi[default],LargeShogi[default],ToriShogi[default],Chess
+X-Tagua-Variants=Shogi[default],LargeShogi[default],ToriShogi[default],Chess,Entropy
index 3bafcfd..3f311f9 100644 (file)
@@ -4,4 +4,4 @@ Name=Custom Color
 Type=Application
 Comment=Squares with a solid custom color
 X-Tagua-ThemeType=Squares
-X-Tagua-Variants=Chess, Shogi, XiangQi
+X-Tagua-Variants=Chess, Shogi, XiangQi, Entropy
index b6b978d..ed01cf4 100644 (file)
@@ -76,3 +76,12 @@ Provides: tagua-variant
 Description: MiniShogi support for the tagua board-game frontend
  This package allows to play MiniShogi, a variant on a 5x5 board of
  the japanese Shogi chess-like game, from tagua.
+
+Package: tagua-variant-entropy
+Architecture: any
+Depends: tagua, tagua-variant-chess
+Provides: tagua-variant
+Description: Randomless-Entropy support for the tagua board-game frontend
+ This package allows to play Randomless-Entropy, a variant of Entropy
+ where Chaos does not randomly draws the next stone to place, but can
+ choose from all stones in the pool, from tagua.
diff --git a/debian/tagua-variant-entropy.files b/debian/tagua-variant-entropy.files
new file mode 100644 (file)
index 0000000..723dad9
--- /dev/null
@@ -0,0 +1,2 @@
+usr/lib/kde4/tagua*entropy.so
+usr/share/kde4/services/tagua-*entropy.desktop
index 7a0ec62..7109d56 100644 (file)
@@ -8,6 +8,7 @@ extern "C" Repository* taguachess5x5_initrepo(IVariantLoader*);
 extern "C" Repository* taguacrazyhouse_initrepo(IVariantLoader*);
 extern "C" Repository* taguashogi_initrepo(IVariantLoader*);
 extern "C" Repository* taguaminishogi_initrepo(IVariantLoader*);
+extern "C" Repository* taguarandomlessentropy_initrepo(IVariantLoader*);
 
 // FIXME: a KDE plugin willing to reuse a builtin one crashes
 
@@ -24,6 +25,7 @@ static const struct builtin {
   { "Crazyhouse", taguacrazyhouse_initrepo, "Chess" },
   { "Shogi", taguashogi_initrepo, "Shogi" },
   { "MiniShogi", taguaminishogi_initrepo, "Shogi" },
+  { "Randomless Entropy", taguarandomlessentropy_initrepo, "Entropy" },
 };
 
 static const struct builtin* const get_builtin(QString name) {
index ec5288f..8627d88 100644 (file)
@@ -5,6 +5,8 @@ add_subdirectory(crazyhouse)
 add_subdirectory(shogi)
 add_subdirectory(minishogi)
 
+add_subdirectory(randomless-entropy)
+
 if(MONOLITH)
 kde4_add_library(taguavariants SHARED dummy.cpp)
 target_link_libraries(taguavariants
@@ -13,6 +15,7 @@ target_link_libraries(taguavariants
   taguacrazyhouse
   taguashogi
   taguaminishogi
+  taguarandomlessentropy
 )
 install(TARGETS taguavariants DESTINATION ${LIB_INSTALL_DIR})
 endif(MONOLITH)
diff --git a/src/variants/randomless-entropy/CMakeLists.txt b/src/variants/randomless-entropy/CMakeLists.txt
new file mode 100644 (file)
index 0000000..c0fc9c6
--- /dev/null
@@ -0,0 +1,27 @@
+set(taguarandomlessentropy_SRCS
+  entropy.cpp
+
+  stone.cpp
+
+#  behaviour.cpp
+  colors.cpp
+#  moveserializer.cpp
+  state.cpp
+#  validator.cpp
+)
+
+include_directories(${CMAKE_SOURCE_DIR}/src/)
+
+if(MONOLITH)
+kde4_add_library(taguarandomlessentropy SHARED ${taguarandomlessentropy_SRCS})
+else(MONOLITH)
+kde4_add_plugin(taguarandomlessentropy ${taguarandomlessentropy_SRCS})
+endif(MONOLITH)
+
+target_link_libraries(taguarandomlessentropy
+  taguacore
+  ${KDE4_KDECORE_LIBS}
+)
+
+install(TARGETS taguarandomlessentropy DESTINATION ${PLUGIN_INSTALL_DIR})
+install(FILES tagua-randomlessentropy.desktop DESTINATION ${SERVICES_INSTALL_DIR})
diff --git a/src/variants/randomless-entropy/colors.cpp b/src/variants/randomless-entropy/colors.cpp
new file mode 100644 (file)
index 0000000..c82d1c5
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+  Copyright (c) 2007 Paolo Capriotti <p.capriotti@gmail.com>
+            (c) 2007 Maurizio Monge <maurizio.monge@kdemail.net>
+
+  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 "colors.h"
+
+namespace RandomlessEntropy {
+
+// Chaos = Black
+// Order = White
+
+IColor* COLORS[] = { Black::self(), White::self() };
+
+}
diff --git a/src/variants/randomless-entropy/colors.h b/src/variants/randomless-entropy/colors.h
new file mode 100644 (file)
index 0000000..2561f16
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+  Copyright (c) 2007 Paolo Capriotti <p.capriotti@gmail.com>
+            (c) 2007 Maurizio Monge <maurizio.monge@kdemail.net>
+
+  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 RANDOMLESSENTROPY__COLORS_H
+#define RANDOMLESSENTROPY__COLORS_H
+
+#include <core/color.h>
+
+namespace RandomlessEntropy {
+
+extern IColor* COLORS[2];
+
+}
+
+#endif // RANDOMLESSENTROPY__COLORS_H
diff --git a/src/variants/randomless-entropy/entropy.cpp b/src/variants/randomless-entropy/entropy.cpp
new file mode 100644 (file)
index 0000000..8748b5a
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+  Copyright (c) 2007 Paolo Capriotti <p.capriotti@gmail.com>
+            (c) 2007 Maurizio Monge <maurizio.monge@kdemail.net>
+
+  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 <core/defaultpolicy.h>
+#include <core/repository.h>
+#include <core/variantloader.h>
+
+//#include "behaviour.h"
+#include "colors.h"
+//#include "moveserializer.h"
+#include "state.h"
+#include "stone.h"
+//#include "validator.h"
+
+#include <KDebug>
+
+using namespace RandomlessEntropy;
+
+namespace RandomlessEntropy {
+  const unsigned gamesize = 3;
+}
+
+extern "C" KDE_EXPORT Repository* taguarandomlessentropy_initrepo(IVariantLoader* loader) {
+  Repository* repo = new Repository;
+  Repository* chess = loader->getRepository("chess");
+  if (!chess) {
+    kError() << "Could not load chess variant";
+    return 0;
+  }
+
+  repo->addComponent("player/0", dynamic_cast<Component*>(COLORS[0]));
+  repo->addComponent("player/1", dynamic_cast<Component*>(COLORS[1]));
+  
+  // FIXME
+  repo->addComponent("type/stone0", Stone::color(0));
+  repo->addComponent("type/stone1", Stone::color(1));
+  repo->addComponent("type/stone2", Stone::color(2));
+
+  IState* chess_state = requestInterface<IState>(chess->getComponent("state"));
+  const IBehaviour* behaviour = chess_state->behaviour();
+  repo->addComponent("state", new State(behaviour, Point(gamesize, gamesize)));
+
+  repo->addComponent("validator", chess->getComponent("validator")); // FIXME
+  repo->addComponent("animator_factory", chess->getComponent("animator_factory"));
+  repo->addComponent("namer", chess->getComponent("namer"));
+  repo->addComponent("policy", new DefaultPolicy); // FIXME ?
+  
+#if 1                                            // FIXME
+  // set move serializers
+  Repository::ComponentMap serializers = chess->listComponents("move_serializer");
+  for (Repository::ComponentMap::const_iterator it = serializers.begin(),
+       end = serializers.end(); it != end; ++it) {
+    repo->addComponent("move_serializer/" + it.key(), it.value());
+  }
+#else
+  repo->addComponent("move_serializer/simple", 
+                    new MoveSerializer("simple", validator));
+#endif
+
+  return repo;
+}
similarity index 51%
copy from src/variants/shogi/state.cpp
copy to src/variants/randomless-entropy/state.cpp
index 4745428..93dc97c 100644 (file)
@@ -16,9 +16,9 @@
 #include <core/defaultpool.h>
 
 #include "colors.h"
-#include "types.h"
+#include "stone.h"
 
-namespace Shogi {
+namespace RandomlessEntropy {
 
 State::State(const IBehaviour* behaviour, 
              const Point& size)
@@ -26,8 +26,8 @@ State::State(const IBehaviour* behaviour,
 , m_behaviour(behaviour)
 , m_delegator(this) {
   DefaultPoolCollection* c = new DefaultPoolCollection;
-  for (int i = 0; i < 2; i++)
-    c->addPool(COLORS[i], new DefaultPool(COLORS[i]));
+  // only Chaos/Black has a pool
+  c->addPool(Black::self(), new DefaultPool(Black::self()));
   m_pools = c;
 }
 
@@ -35,7 +35,6 @@ State::State(const State& other)
 : IState()
 , DefaultState()
 , m_board(other.m_board)
-, m_flags(other.m_flags)
 , m_turn(other.m_turn)
 , m_behaviour(other.m_behaviour)
 , m_delegator(this)
@@ -49,34 +48,15 @@ IState* State::clone() const {
   return s;
 }
 
-#define COL(i, c) c == Black::self() ? (i) : (m_board.size().x - i - 1)
 void State::setup() {
-  for (int c = 0; c < 2; c++) {
-    IColor* color = COLORS[c];
-    int r0 = rank(0, color);
-    int r1 = rank(1, color);
-    int r2 = rank(2, color);
-    
-    for (int i = 0; i < m_board.size().x; i++) {
-      m_board.set(Point(i, r2), Piece(color, Pawn::self()));
-    }
-    m_board.set(Point(0, r0), Piece(color, Lance::self()));
-    m_board.set(Point(1, r0), Piece(color, Knight::self()));
-    m_board.set(Point(2, r0), Piece(color, Silver::self()));
-    m_board.set(Point(3, r0), Piece(color, Gold::self()));
-    m_board.set(Point(4, r0), Piece(color, King::self()));
-    m_board.set(Point(5, r0), Piece(color, Gold::self()));
-    m_board.set(Point(6, r0), Piece(color, Silver::self()));
-    m_board.set(Point(7, r0), Piece(color, Knight::self()));
-    m_board.set(Point(8, r0), Piece(color, Lance::self()));
-
-    m_board.set(Point(COL(1, color), r1), Piece(color, Bishop::self()));
-    m_board.set(Point(COL(7, color), r1), Piece(color, Rook::self()));
-  }
-  
-  m_turn = White::self();
+  // Chaos starts, board is empty
+  m_turn = Black::self();
+  // FIXME: all pieces in pool
+  IPool* pool = pools()->pool(Black::self());
+  pool->insert(-1, Piece(Black::self(), Stone::color(0)));
+  pool->insert(-1, Piece(Black::self(), Stone::color(1)));
+  pool->insert(-1, Piece(Black::self(), Stone::color(2)));
 }
-#undef COL
 
 const Board* State::board() const {
   return &m_board;
@@ -96,14 +76,12 @@ void State::setTurn(const IColor* turn) {
   
 bool State::equals(IState* other) const {
   return m_board.equals(other->board()) &&
-         m_turn == other->turn() &&
-         m_flags == *other->flags();
+    m_turn == other->turn();
 }
 
 void State::assign(const IState* other) {
   m_board = *other->board();
   m_turn = other->turn();
-  m_flags = *other->flags();
 
   const IPoolCollection* pools = other->pools();
   if (pools) {
@@ -114,41 +92,19 @@ void State::assign(const IState* other) {
 
 void State::move(const Move& m) {
   if (m.drop() != Piece()) {
-    //const Piece captured = board()->get(m.dst());
     board()->set(m.dst(), m.drop());
     pools()->pool(m.drop().color())->take(m.drop());
 
-#if 0
-    // handle capturing by drop: some variants could use it
-    if (captured != Piece()) {
-      if (captured.get("promoted").toBool()) {
-        captured.setType(pawn);
-      }
-      pools()->pool(behaviour()->opponent(captured.color()))
-             ->insert(-1, captured);
-    }
-#endif
   } else {
     const Piece piece = m_board.get(m.src());
     if (piece == Piece()) return;
 
-    Point captureSquare = behaviour()->captureSquare(this, m);
-    behaviour()->captureOn(m_delegator, captureSquare);
     behaviour()->move(m_delegator, m);
-
-    const IType* promotion_type = m.promotion();
-
-    if (promotion_type != 0) {
-      m_board.set(m.dst(), Piece(piece.color(), promotion_type));
-    }
   }
 
   behaviour()->advanceTurn(m_delegator);
 }
 
-const TaguaObject* State::flags() const { return &m_flags; }
-TaguaObject* State::flags() { return &m_flags; }
-
 int State::rank(int n, const IColor* turn) const {
   if (turn == White::self())
     return m_board.size().y - n - 1;
@@ -161,13 +117,11 @@ const IPoolCollection* State::pools() const { return m_pools; }
 
 const IBehaviour* State::behaviour() const { return m_behaviour; }
 
-void State::setDelegator(IState* delegator) {
-  m_delegator = delegator;
-}
+void State::setDelegator(IState* delegator) { m_delegator = delegator; }
 
-IState* State::clone(const IBehaviour* behaviour,
-                    const Point& size) const {
+Component* State::clone(const IBehaviour* behaviour, 
+                        const Point& size) const {
   return new State(behaviour, size);
 }
 
-} // namespace Shogi
+} // namespace RandomlessEntropy
diff --git a/src/variants/randomless-entropy/state.h b/src/variants/randomless-entropy/state.h
new file mode 100644 (file)
index 0000000..be43c61
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+  Copyright (c) 2007 Paolo Capriotti <p.capriotti@gmail.com>
+            (c) 2007 Maurizio Monge <maurizio.monge@kdemail.net>
+
+  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 RANDOMLESSENTROPY__STATE_H
+#define RANDOMLESSENTROPY__STATE_H
+
+#include <core/board.h>
+#include <core/defaultstate.h>
+#include <core/piece.h>
+#include <core/taguaobject.h>
+
+/**
+  * @brief Namespace holding Randomless-Entropy components.
+  *
+  * @details Randomless-Entropy is a variant of Entropy where Chaos
+  * does not randomly draws the next stone to place, but can choose
+  * from all stones in the pool.
+  */
+namespace RandomlessEntropy {
+
+class State : public DefaultState {
+Q_OBJECT
+  Board m_board;
+  const IColor* m_turn;
+  const IBehaviour* m_behaviour;
+  IState* m_delegator;
+  IPoolCollection* m_pools;
+protected:
+  State(const State&);
+public:
+  State(const IBehaviour* behaviour, 
+        const Point& size);
+  virtual ~State();
+public:
+  virtual IState* clone() const;
+  
+  virtual void setup();
+  
+  virtual const Board* board() const;
+  virtual Board* board();
+  
+  virtual const IColor* turn() const;
+  
+  virtual void setTurn(const IColor* turn);
+  
+  virtual bool equals(IState* other) const;
+  
+  virtual void assign(const IState* other);
+
+  virtual void move(const Move& move);
+  
+  virtual TaguaObject* flags() { return NULL; };
+  virtual const TaguaObject* flags() const { return NULL; };
+  
+  virtual int rank(int n, const IColor* turn) const;
+
+  virtual const IPoolCollection* pools() const;
+  virtual IPoolCollection* pools();
+  
+  virtual const IBehaviour* behaviour() const;
+  
+  virtual void setDelegator(IState* delegator);
+public Q_SLOTS:
+  virtual Component* clone(const IBehaviour* behaviour,
+                           const Point& size) const;
+};
+
+} // namespace RandomlessEntropy
+
+#endif // RANDOMLESSENTROPY__STATE_H
+
diff --git a/src/variants/randomless-entropy/stone.cpp b/src/variants/randomless-entropy/stone.cpp
new file mode 100644 (file)
index 0000000..4fd38c1
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+  Copyright (c) 2007 Paolo Capriotti <p.capriotti@gmail.com>
+            (c) 2007 Maurizio Monge <maurizio.monge@kdemail.net>
+
+  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 "stone.h"
+
+namespace RandomlessEntropy {
+
+Stone::Stone() {
+  const MoveDefinition movesDefinition[] = {
+    {-1,  0, 0 },
+    { 1,  0, 0 },
+    { 0,  1, 0 },
+    { 0, -1, 0 },
+  };
+
+  for (unsigned i = 0; i < sizeof(movesDefinition)/sizeof(movesDefinition[0]); i++)
+    m_moveDefinitions.push_back(movesDefinition[i]);
+}
+
+QString Stone::name() const { return "stone" + m_color; }
+
+const std::vector<MoveDefinition> * const Stone::movesDefinitions() const {
+  return &m_moveDefinitions;
+}
+
+int Stone::index() const { return m_color; }
+
+// FIXME: parametrize number of colors
+// FIXME: find a way to set m_color in Stone constructor instead
+Stone* Stone::color(unsigned color) {
+  static Stone s_instance[3];
+  static bool colors_initialized = false;
+  if (!colors_initialized) {
+    for (int i=0; i<3;i++)
+      s_instance[i].m_color = i;
+  }
+
+  return &s_instance[color];
+}
+
+}
diff --git a/src/variants/randomless-entropy/stone.h b/src/variants/randomless-entropy/stone.h
new file mode 100644 (file)
index 0000000..5eec319
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+  Copyright (c) 2007 Paolo Capriotti <p.capriotti@gmail.com>
+            (c) 2007 Maurizio Monge <maurizio.monge@kdemail.net>
+
+  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 RANDOMLESSENTROPY__STONE_H
+#define RANDOMLESSENTROPY__STONE_H
+
+#include <core/component.h>
+#include <core/defaulttype.h>
+
+namespace RandomlessEntropy {
+
+class TAGUA_EXPORT Stone : public Component, public DefaultType {
+Q_OBJECT
+  Stone();
+public:
+  virtual QString name() const;
+  virtual const std::vector<MoveDefinition> * const movesDefinitions() const;
+  virtual int index() const;
+  static Stone* color(unsigned color);
+private:
+  std::vector<MoveDefinition> m_moveDefinitions;
+  unsigned m_color;
+};
+
+}
+
+#endif // RANDOMLESSENTROPY__STONE_H
diff --git a/src/variants/randomless-entropy/tagua-randomlessentropy.desktop b/src/variants/randomless-entropy/tagua-randomlessentropy.desktop
new file mode 100644 (file)
index 0000000..04d749d
--- /dev/null
@@ -0,0 +1,20 @@
+[Desktop Entry]
+Encoding=UTF-8
+Name=Randomless Entropy
+Comment=Randomless variant of Entropy
+Icon=tagua
+Type=Service
+ServiceTypes=Tagua/Variant
+
+X-KDE-Library=taguarandomlessentropy
+X-KDE-PluginInfo-Author=Yann Dirson
+X-KDE-PluginInfo-Email=ydirson@altern.org
+X-KDE-PluginInfo-Name=randomlessentropy
+X-KDE-PluginInfo-Version=0.5.1
+X-KDE-PluginInfo-Website=http://www.tagua-project.org
+X-KDE-PluginInfo-Depends=
+X-KDE-PluginInfo-License=GPL
+X-KDE-PluginInfo-EnabledByDefault=true
+
+X-Tagua-Proxy=Entropy
+X-Tagua-Hidden=false
index 4745428..0e79399 100644 (file)
@@ -93,7 +93,8 @@ const IColor* State::turn() const {
 void State::setTurn(const IColor* turn) {
   m_turn = turn;
 }
-  
+
+// FIXME: should take pools into account
 bool State::equals(IState* other) const {
   return m_board.equals(other->board()) &&
          m_turn == other->turn() &&