Author: crab
Date: Mon Jan 18 22:32:38 2010
New Revision: 40744

URL: http://svn.gna.org/viewcvs/wesnoth?rev=40744&view=rev
Log:
lua ai support engine, interface code and ai integration

Added:
    trunk/src/ai/composite/engine_lua.cpp   (with props)
    trunk/src/ai/composite/engine_lua.hpp   (with props)
Modified:
    trunk/projectfiles/CodeBlocks-SCons/wesnoth.cbp
    trunk/projectfiles/CodeBlocks/wesnoth.cbp
    trunk/projectfiles/VC9/wesnoth.vcproj
    trunk/src/CMakeLists.txt
    trunk/src/Makefile.am
    trunk/src/SConscript
    trunk/src/ai/registry.cpp

Modified: trunk/projectfiles/CodeBlocks-SCons/wesnoth.cbp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/projectfiles/CodeBlocks-SCons/wesnoth.cbp?rev=40744&r1=40743&r2=40744&view=diff
==============================================================================
--- trunk/projectfiles/CodeBlocks-SCons/wesnoth.cbp (original)
+++ trunk/projectfiles/CodeBlocks-SCons/wesnoth.cbp Mon Jan 18 22:32:38 2010
@@ -63,6 +63,8 @@
                <Unit filename="..\..\src\ai\composite\engine_default.hpp" />
                <Unit filename="..\..\src\ai\composite\engine_fai.cpp" />
                <Unit filename="..\..\src\ai\composite\engine_fai.hpp" />
+               <Unit filename="..\..\src\ai\composite\engine_lua.cpp" />
+               <Unit filename="..\..\src\ai\composite\engine_lua.hpp" />
                <Unit filename="..\..\src\ai\composite\goal.cpp" />
                <Unit filename="..\..\src\ai\composite\goal.hpp" />
                <Unit filename="..\..\src\ai\composite\property_handler.hpp" />

Modified: trunk/projectfiles/CodeBlocks/wesnoth.cbp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/projectfiles/CodeBlocks/wesnoth.cbp?rev=40744&r1=40743&r2=40744&view=diff
==============================================================================
--- trunk/projectfiles/CodeBlocks/wesnoth.cbp (original)
+++ trunk/projectfiles/CodeBlocks/wesnoth.cbp Mon Jan 18 22:32:38 2010
@@ -92,6 +92,8 @@
                <Unit filename="..\..\src\ai\composite\engine_default.hpp" />
                <Unit filename="..\..\src\ai\composite\engine_fai.cpp" />
                <Unit filename="..\..\src\ai\composite\engine_fai.hpp" />
+               <Unit filename="..\..\src\ai\composite\engine_lua.cpp" />
+               <Unit filename="..\..\src\ai\composite\engine_lua.hpp" />
                <Unit filename="..\..\src\ai\composite\goal.cpp" />
                <Unit filename="..\..\src\ai\composite\goal.hpp" />
                <Unit filename="..\..\src\ai\composite\property_handler.hpp" />

Modified: trunk/projectfiles/VC9/wesnoth.vcproj
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/projectfiles/VC9/wesnoth.vcproj?rev=40744&r1=40743&r2=40744&view=diff
==============================================================================
--- trunk/projectfiles/VC9/wesnoth.vcproj (original)
+++ trunk/projectfiles/VC9/wesnoth.vcproj Mon Jan 18 22:32:38 2010
@@ -4460,6 +4460,34 @@
                                                </FileConfiguration>
                                        </File>
                                        <File
+                                               
RelativePath="..\..\src\ai\composite\engine_lua.cpp"
+                                               >
+                                               <FileConfiguration
+                                                       Name="Debug|Win32"
+                                                       >
+                                                       <Tool
+                                                               
Name="VCCLCompilerTool"
+                                                               
ObjectFile="$(IntDir)\ai\composite\"
+                                                       />
+                                               </FileConfiguration>
+                                               <FileConfiguration
+                                                       Name="Release|Win32"
+                                                       >
+                                                       <Tool
+                                                               
Name="VCCLCompilerTool"
+                                                               
ObjectFile="$(IntDir)\ai\composite\"
+                                                       />
+                                               </FileConfiguration>
+                                               <FileConfiguration
+                                                       Name="Debug 
(fast)|Win32"
+                                                       >
+                                                       <Tool
+                                                               
Name="VCCLCompilerTool"
+                                                               
ObjectFile="$(IntDir)\ai\composite\"
+                                                       />
+                                               </FileConfiguration>
+                                       </File>
+                                       <File
                                                
RelativePath="..\..\src\ai\composite\goal.cpp"
                                                >
                                                <FileConfiguration
@@ -6247,6 +6275,10 @@
                                                >
                                        </File>
                                        <File
+                                               
RelativePath="..\..\src\ai\composite\engine_lua.hpp"
+                                               >
+                                       </File>
+                                       <File
                                                
RelativePath="..\..\src\ai\composite\goal.hpp"
                                                >
                                        </File>

Modified: trunk/src/CMakeLists.txt
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/CMakeLists.txt?rev=40744&r1=40743&r2=40744&view=diff
==============================================================================
--- trunk/src/CMakeLists.txt (original)
+++ trunk/src/CMakeLists.txt Mon Jan 18 22:32:38 2010
@@ -170,6 +170,7 @@
     ai/composite/engine.cpp
     ai/composite/engine_default.cpp
     ai/composite/engine_fai.cpp
+    ai/composite/engine_lua.cpp
     ai/composite/goal.cpp
     ai/composite/rca.cpp
     ai/composite/stage.cpp

Modified: trunk/src/Makefile.am
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/Makefile.am?rev=40744&r1=40743&r2=40744&view=diff
==============================================================================
--- trunk/src/Makefile.am (original)
+++ trunk/src/Makefile.am Mon Jan 18 22:32:38 2010
@@ -50,6 +50,7 @@
        ai/composite/engine.cpp \
        ai/composite/engine_default.cpp \
        ai/composite/engine_fai.cpp \
+       ai/composite/engine_lua.cpp \
        ai/composite/goal.cpp \
        ai/composite/rca.cpp \
        ai/composite/stage.cpp \

Modified: trunk/src/SConscript
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/SConscript?rev=40744&r1=40743&r2=40744&view=diff
==============================================================================
--- trunk/src/SConscript (original)
+++ trunk/src/SConscript Mon Jan 18 22:32:38 2010
@@ -155,6 +155,7 @@
     ai/composite/engine.cpp
     ai/composite/engine_default.cpp
     ai/composite/engine_fai.cpp
+    ai/composite/engine_lua.cpp
     ai/composite/goal.cpp
     ai/composite/rca.cpp
     ai/composite/stage.cpp

Added: trunk/src/ai/composite/engine_lua.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/ai/composite/engine_lua.cpp?rev=40744&view=auto
==============================================================================
--- trunk/src/ai/composite/engine_lua.cpp (added)
+++ trunk/src/ai/composite/engine_lua.cpp Mon Jan 18 22:32:38 2010
@@ -1,0 +1,141 @@
+/* $Id$ */
+/*
+   Copyright (C) 2009 - 2010 by Yurii Chernyi <[email protected]>
+   Part of the Battle for Wesnoth Project http://www.wesnoth.org/
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License version 2
+   or at your option any later version.
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY.
+
+   See the COPYING file for more details.
+*/
+
+/**
+ * LUA AI Support engine - creating specific ai components from config
+ * @file ai/composite/engine_lua.cpp
+ */
+
+#include "ai.hpp"
+#include "engine_lua.hpp"
+#include "rca.hpp"
+#include "../../log.hpp"
+
+namespace ai {
+
+static lg::log_domain log_ai_engine_lua("ai/engine/lua");
+#define DBG_AI_LUA LOG_STREAM(debug, log_ai_engine_lua)
+#define LOG_AI_LUA LOG_STREAM(info, log_ai_engine_lua)
+#define WRN_AI_LUA LOG_STREAM(warn, log_ai_engine_lua)
+#define ERR_AI_LUA LOG_STREAM(err, log_ai_engine_lua)
+
+#ifdef _MSC_VER
+#pragma warning(push)
+//silence "inherits via dominance" warnings
+#pragma warning(disable:4250)
+#endif
+
+class lua_candidate_action_wrapper : public candidate_action {
+public:
+       lua_candidate_action_wrapper( rca_context &context, const config &cfg )
+               : candidate_action(context,cfg),cfg_(cfg)
+       {
+
+       }
+
+       virtual ~lua_candidate_action_wrapper() {}
+
+
+       virtual double evaluate()
+       {
+               //@todo: lua must evaluate the score and return it
+               return 0;
+       }
+
+
+       virtual bool execute()
+       {
+               //@todo: lua must do the actions. the return value is supposed 
to be 'true if gamestate has changed' but it'll be refactored away soon.
+               return false;
+       }
+
+       virtual config to_config() const
+       {
+               return cfg_;//or we can serialize our current state to config 
instead of using original cfg
+       }
+private:
+       const config cfg_;
+};
+
+
+/**
+ * Note that initially we get access only to readonly context (engine is 
created rather early, when there's no way to move/attack.
+ * We inject full ai_context later.
+ */
+engine_lua::engine_lua( readonly_context &context, const config &cfg )
+       : engine(context,cfg)
+{
+       name_ = "lua";
+}
+
+
+engine_lua::~engine_lua()
+{
+}
+
+
+void engine_lua::do_parse_candidate_action_from_config( rca_context & 
/*context*/, const config &cfg, std::back_insert_iterator<std::vector< 
candidate_action_ptr > > b ){
+       if (!cfg) {
+               return;
+       }
+       candidate_action_ptr ca_ptr;
+       //@todo : need to code an adapter class which implements the candidate 
action interface
+       //ca_ptr = candidate_action_ptr(new 
lua_candidate_action_wrapper(context,cfg));
+       if (ca_ptr) {
+               *b = ca_ptr;
+       }
+}
+
+void engine_lua::do_parse_stage_from_config( ai_context & /*context*/, const 
config &cfg, std::back_insert_iterator<std::vector< stage_ptr > > b )
+{
+       if (!cfg) {
+               return;
+       }
+       stage_ptr st_ptr;
+
+       //@todo : need to code an adapter class which implements the stage 
interface
+       //it's simple - the main part is do_play_stage() method
+       //st_ptr = stage_ptr(new lua_stage_wrapper(context,cfg));
+       if (st_ptr) {
+               st_ptr->on_create();
+               *b = st_ptr;
+       }
+}
+
+std::string engine_lua::evaluate(const std::string &str)
+{
+       //@todo: this is not mandatory, but if we want to allow lua to evaluate
+       // something 'in context' of this ai, this will be useful
+       return "";
+}
+
+
+void engine_lua::set_ai_context(ai_context * /*context*/)
+{
+       //this function is called when the ai is fully initialized
+}
+
+
+config engine_lua::to_config() const
+{
+       config cfg = engine::to_config();
+       //we can modify the cfg here
+       return cfg;
+}
+
+#ifdef _MSC_VER
+#pragma warning(pop)
+#endif
+
+} //end of namespace ai

Propchange: trunk/src/ai/composite/engine_lua.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: trunk/src/ai/composite/engine_lua.cpp
------------------------------------------------------------------------------
    svn:keywords = 'Author Date Id Revision'

Added: trunk/src/ai/composite/engine_lua.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/ai/composite/engine_lua.hpp?rev=40744&view=auto
==============================================================================
--- trunk/src/ai/composite/engine_lua.hpp (added)
+++ trunk/src/ai/composite/engine_lua.hpp Mon Jan 18 22:32:38 2010
@@ -1,0 +1,68 @@
+/* $Id$ */
+/*
+   Copyright (C) 2009 - 2010 by Yurii Chernyi <[email protected]>
+   Part of the Battle for Wesnoth Project http://www.wesnoth.org/
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License version 2
+   or at your option any later version.
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY.
+
+   See the COPYING file for more details.
+*/
+
+/**
+ * LUA AI Support engine - creating specific ai components from config
+ * @file ai/composite/engine_lua.hpp
+ */
+
+#ifndef AI_COMPOSITE_ENGINE_LUA_HPP_INCLUDED
+#define AI_COMPOSITE_ENGINE_LUA_HPP_INCLUDED
+
+#include "../../global.hpp"
+
+#include "engine.hpp"
+#include "../contexts.hpp"
+
+//============================================================================
+namespace ai {
+
+class engine_lua : public engine {
+public:
+       engine_lua( readonly_context &context, const config &cfg );
+
+       virtual ~engine_lua();
+
+       /**
+        * Taka a config (with engine=lua in it)
+        * and parse several (usually, 1) candidate actions out of it
+        */
+       virtual void do_parse_candidate_action_from_config( rca_context 
&context, const config &cfg, std::back_insert_iterator<std::vector< 
candidate_action_ptr > > b );
+
+       /**
+        * Taka a config (with engine=lua in it)
+        * and parse several (usually, 1) stages out of it
+        */
+       virtual void do_parse_stage_from_config( ai_context &context, const 
config &cfg, std::back_insert_iterator<std::vector< stage_ptr > > b );
+
+       virtual std::string evaluate(const std::string &str);
+
+       /**
+        * Serialize to config
+        */
+       virtual config to_config() const;
+
+       /**
+        * Method to inject AI context into the engine.
+        * The context includes all that in necessary for the AI -
+        * , like access to game state and movement/attack routines.
+        */
+       virtual void set_ai_context(ai_context *context);
+private:
+       //There is one lua engine per AI. So, it can hold state
+};
+
+} //end of namespace ai
+
+#endif

Propchange: trunk/src/ai/composite/engine_lua.hpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: trunk/src/ai/composite/engine_lua.hpp
------------------------------------------------------------------------------
    svn:keywords = 'Author Date Id Revision'

Modified: trunk/src/ai/registry.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/ai/registry.cpp?rev=40744&r1=40743&r2=40744&view=diff
==============================================================================
--- trunk/src/ai/registry.cpp (original)
+++ trunk/src/ai/registry.cpp Mon Jan 18 22:32:38 2010
@@ -22,6 +22,7 @@
 #include "composite/aspect.hpp"
 #include "composite/engine_default.hpp"
 #include "composite/engine_fai.hpp"
+#include "composite/engine_lua.hpp"
 #include "composite/goal.hpp"
 #include "default/ai.hpp"
 #include "formula/ai.hpp"
@@ -56,6 +57,9 @@
 static register_engine_factory<engine_fai>
        composite_ai_factory_fai("fai");
 
+static register_engine_factory<engine_lua>
+       composite_ai_factory_lua("lua");
+
 // =======================================================================
 // Stages
 // =======================================================================


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to