Skip to content

Commit

Permalink
Cleaned up excessive indentation and newlines in the AI code
Browse files Browse the repository at this point in the history
  • Loading branch information
Vultraz committed Dec 1, 2020
1 parent 62aa0b2 commit baa1a87
Show file tree
Hide file tree
Showing 52 changed files with 166 additions and 949 deletions.
14 changes: 0 additions & 14 deletions src/ai/composite/ai.cpp
Expand Up @@ -88,25 +88,21 @@ void ai_composite::on_create()

}


void ai_composite::create_stage(std::vector<stage_ptr> &stages, const config &cfg)
{
engine::parse_stage_from_config(*this,cfg,std::back_inserter(stages));
}


void ai_composite::create_goal(std::vector<goal_ptr> &goals, const config &cfg)
{
engine::parse_goal_from_config(*this,cfg,std::back_inserter(goals));
}


void ai_composite::create_engine(std::vector<engine_ptr> &engines, const config &cfg)
{
engine::parse_engine_from_config(*this,cfg,std::back_inserter(engines));
}


void ai_composite::replace_aspect(std::map<std::string,aspect_ptr> &aspects, const config &cfg, std::string id)
{
std::vector<aspect_ptr> temp_aspects;
Expand All @@ -118,7 +114,6 @@ ai_composite::~ai_composite()
{
}


bool ai_composite::add_stage(const config &cfg)
{
std::vector< stage_ptr > stages;
Expand All @@ -131,7 +126,6 @@ bool ai_composite::add_stage(const config &cfg)
return (j>0);
}


bool ai_composite::add_goal(const config &cfg)
{
std::vector< goal_ptr > goals;
Expand All @@ -144,33 +138,28 @@ bool ai_composite::add_goal(const config &cfg)
return (j>0);
}


void ai_composite::play_turn(){
for (stage_ptr &s : stages_) {
s->play_stage();
}
}


std::string ai_composite::get_id() const
{
return cfg_["id"];
}



std::string ai_composite::get_name() const
{
return cfg_["name"];
}


std::string ai_composite::get_engine() const
{
return cfg_["engine"];
}


std::string ai_composite::evaluate(const std::string& str)
{
config cfg;
Expand All @@ -183,7 +172,6 @@ std::string ai_composite::evaluate(const std::string& str)
return e_ptr->evaluate(str);
}


void ai_composite::new_turn()
{
recalculate_move_maps();
Expand All @@ -193,7 +181,6 @@ void ai_composite::new_turn()
unit_stats_cache().clear();
}


int ai_composite::get_recursion_count() const
{
return recursion_counter_.get_count();
Expand All @@ -209,7 +196,6 @@ ai_context& ai_composite::get_ai_context()
return *this;
}


config ai_composite::to_config() const
{
config cfg;
Expand Down
17 changes: 0 additions & 17 deletions src/ai/composite/ai.hpp
Expand Up @@ -28,25 +28,21 @@ namespace ai {
class ai_composite : public ai_context, public virtual default_ai_context_proxy, public component {
public:


/**
* Constructor
*/
ai_composite( default_ai_context &context, const config &cfg );


/**
* Destructor
*/
virtual ~ai_composite();


/**
* Play the turn
*/
void play_turn();


/**
* Evaluate command (using fai)
*/
Expand All @@ -57,47 +53,36 @@ class ai_composite : public ai_context, public virtual default_ai_context_proxy,
*/
virtual void new_turn();


std::string describe_self() const;

/**
* serialize
*/
virtual config to_config() const;


int get_recursion_count() const;


void switch_side(side_number side);


virtual bool add_goal(const config &cfg);


virtual bool add_stage(const config &cfg);


void create_stage(std::vector<stage_ptr> &stages, const config &cfg);


void create_goal(std::vector<goal_ptr> &goals, const config &cfg);


void create_engine(std::vector<engine_ptr> &engines, const config &cfg);


void replace_aspect(std::map<std::string,aspect_ptr> &aspects, const config &cfg, std::string id);


void on_create();

/**
* unwrap
*/
virtual ai_context& get_ai_context();


virtual std::string get_id() const;
virtual std::string get_name() const;
virtual std::string get_engine() const;
Expand All @@ -111,13 +96,11 @@ class ai_composite : public ai_context, public virtual default_ai_context_proxy,
*/
const config &cfg_;


/**
* Stages of the composite AI
*/
std::vector< stage_ptr > stages_;


/**
* Recursion counter
*/
Expand Down
1 change: 0 additions & 1 deletion src/ai/composite/aspect.cpp
Expand Up @@ -42,7 +42,6 @@ aspect::aspect(readonly_context &context, const config &cfg, const std::string &
DBG_AI_ASPECT << "aspect has time_of_day=["<<time_of_day_<<"], turns=["<<turns_<<"]" << std::endl;
}


aspect::~aspect()
{
manager& manager = manager::get_singleton();
Expand Down
30 changes: 0 additions & 30 deletions src/ai/composite/aspect.hpp
Expand Up @@ -45,37 +45,27 @@ class aspect : public readonly_context_proxy, public events::observer, public co
valid_lua_ = false;
}


virtual const wfl::variant& get_variant() const = 0;


virtual std::shared_ptr<wfl::variant> get_variant_ptr() const = 0;


virtual void get_lua(lua_State* L) const = 0;


virtual void recalculate() const = 0;


virtual void on_create();


virtual bool redeploy(const config &cfg, const std::string & id);


virtual config to_config() const;


virtual bool delete_all_facets();


void handle_generic_event(const std::string &/*event_name*/)
{
invalidate();
}


virtual bool active() const;

virtual std::string get_name() const
Expand Down Expand Up @@ -122,13 +112,11 @@ class typesafe_aspect : public aspect {
{
}


virtual const T& get() const
{
return *get_ptr();
}


virtual const wfl::variant& get_variant() const
{
return *get_variant_ptr();
Expand Down Expand Up @@ -164,7 +152,6 @@ class typesafe_aspect : public aspect {

virtual void recalculate() const = 0;


virtual std::shared_ptr<T> get_ptr() const
{
if (!valid_) {
Expand Down Expand Up @@ -193,28 +180,22 @@ class typesafe_aspect : public aspect {
mutable std::shared_ptr< lua_object<T>> value_lua_;
};


class known_aspect {
public:
known_aspect(const std::string &name);


virtual ~known_aspect();


virtual void set(aspect_ptr a) = 0;


virtual void add_facet(const config &cfg) = 0;


const std::string& get_name() const;

protected:
const std::string name_;
};


template<class T>
class composite_aspect;

Expand Down Expand Up @@ -255,7 +236,6 @@ class typesafe_known_aspect : public known_aspect {
aspect_map &aspects_;
};


template<typename T>
class composite_aspect : public typesafe_aspect<T> {
public:
Expand Down Expand Up @@ -291,7 +271,6 @@ class composite_aspect : public typesafe_aspect<T> {

}


void create_facet(typesafe_aspect_vector<T>& facets, const config &cfg)
{
std::vector<aspect_ptr> facets_base;
Expand All @@ -305,7 +284,6 @@ class composite_aspect : public typesafe_aspect<T> {
}
}


virtual void recalculate() const
{
for(const auto& f : boost::adaptors::reverse(facets_)) {
Expand All @@ -321,7 +299,6 @@ class composite_aspect : public typesafe_aspect<T> {
}
}


virtual config to_config() const
{
config cfg = aspect::to_config();
Expand All @@ -334,7 +311,6 @@ class composite_aspect : public typesafe_aspect<T> {
return cfg;
}


using typesafe_aspect<T>::add_facet;
virtual bool add_facet(int pos, const config &cfg)
{
Expand All @@ -355,7 +331,6 @@ class composite_aspect : public typesafe_aspect<T> {
return (j>0);
}


virtual bool delete_all_facets()
{
bool b = !facets_.empty();
Expand Down Expand Up @@ -391,14 +366,12 @@ class standard_aspect : public typesafe_aspect<T> {
LOG_STREAM(debug, aspect::log()) << "standard aspect has value: "<< std::endl << config_value_translator<T>::value_to_cfg(this->get()) << std::endl;
}


void recalculate() const
{
//nothing to recalculate
this->valid_ = true;
}


config to_config() const
{
config cfg = aspect::to_config();
Expand Down Expand Up @@ -469,7 +442,6 @@ class lua_aspect : public typesafe_aspect<T>
const config params_;
};


class aspect_factory{
bool is_duplicate(const std::string &name);
public:
Expand Down Expand Up @@ -499,7 +471,6 @@ class aspect_factory{
virtual ~aspect_factory() {}
};


template<class ASPECT>
class register_aspect_factory : public aspect_factory {
public:
Expand Down Expand Up @@ -557,5 +528,4 @@ class register_lua_aspect_factory : public lua_aspect_factory {
}
};


} //end of namespace ai

0 comments on commit baa1a87

Please sign in to comment.