Procházet zdrojové kódy

Uncommented Fuzzy code. Please let me know if it compiles on other platforms.

DjWarmonger před 12 roky
rodič
revize
8be4ca03c8
3 změnil soubory, kde provedl 33 přidání a 26 odebrání
  1. 18 17
      AI/VCAI/Fuzzy.cpp
  2. 2 2
      AI/VCAI/Fuzzy.h
  3. 13 7
      AI/VCAI/Goals.cpp

+ 18 - 17
AI/VCAI/Fuzzy.cpp

@@ -278,20 +278,21 @@ float FuzzyHelper::getTacticalAdvantage (const CArmedInstance *we, const CArmedI
 }
 
 //shared_ptr<AbstractGoal> chooseSolution (std::vector<shared_ptr<AbstractGoal>> & vec)
-//{
-//	typedef std::pair<shared_ptr<AbstractGoal>, float> goalValue;
-//	std::vector <goalValue> values;
-//
-//	for (auto g : vec)
-//	{
-//		values.push_back (std::make_pair(g, 66.6f));
-//	}
-//
-//	auto compareGoals = [&](const goalValue & lhs, const goalValue & rhs) -> bool
-//	{
-//		return lhs.second < rhs.second;
-//	};
-//
-//	boost::sort (values, compareGoals);
-//	return values.end()->first;
-//}
+Goals::TSubgoal chooseSolution (Goals::TGoalVec & vec)
+{
+	typedef std::pair<Goals::TSubgoal, float> goalValue;
+	std::vector <goalValue> values;
+
+	for (auto g : vec)
+	{
+		values.push_back (std::make_pair(g, 66.6f));
+	}
+
+	auto compareGoals = [&](const goalValue & lhs, const goalValue & rhs) -> bool
+	{
+		return lhs.second < rhs.second;
+	};
+
+	boost::sort (values, compareGoals);
+	return values.end()->first;
+}

+ 2 - 2
AI/VCAI/Fuzzy.h

@@ -1,5 +1,6 @@
 #pragma once
 #include "../FuzzyLite/FuzzyLite.h"
+#include "Goals.h"
 
 /*
  * Fuzzy.h, part of VCMI engine
@@ -44,7 +45,6 @@ public:
 	ui64 estimateBankDanger (int ID);
 	float getTacticalAdvantage (const CArmedInstance *we, const CArmedInstance *enemy); //returns factor how many times enemy is stronger than us
 
-	//FIXME: use Goals namespace
-	//Goals::TSubgoal chooseSolution (Goals::TGoalVec & vec);
+	Goals::TSubgoal chooseSolution (Goals::TGoalVec & vec);
 	//shared_ptr<AbstractGoal> chooseSolution (std::vector<shared_ptr<AbstractGoal>> & vec);
 };

+ 13 - 7
AI/VCAI/Goals.cpp

@@ -869,13 +869,19 @@ void CGoal<T>::accept (VCAI * ai)
 }
 
 //TODO: find out why the following are not generated automatically on MVS?
-void CGoal<Win>::accept (VCAI * ai)
-{
-	ai->tryRealize(static_cast<Win&>(*this));
-}
 
-void CGoal<Build>::accept (VCAI * ai)
-{
-	ai->tryRealize(static_cast<Build&>(*this));
+namespace Goals 
+{ 
+	template <>
+	void CGoal<Win>::accept (VCAI * ai)
+	{
+		ai->tryRealize(static_cast<Win&>(*this));
+	}
+
+	template <>
+	void CGoal<Build>::accept (VCAI * ai)
+	{
+		ai->tryRealize(static_cast<Build&>(*this));
+	}
 }