(svn r9308) [NoAI] -Change: make the regression scripts run without any user intervention; not manual enabling and disabling of AIs noai
authorrubidium
Mon, 19 Mar 2007 00:00:26 +0000
branchnoai
changeset 9470 4593c953a276
parent 9469 7072beb81014
child 9471 467ee8749166
(svn r9308) [NoAI] -Change: make the regression scripts run without any user intervention; not manual enabling and disabling of AIs
[NoAI] -Update: the regression outcome because the AI isn't chosen random anymore.
bin/ai/regression/main.nut
bin/ai/regression/regression.nut
bin/ai/regression/regression.txt
bin/ai/regression/run.sh
--- a/bin/ai/regression/main.nut	Sun Mar 18 23:59:07 2007 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,181 +0,0 @@
-class Regression extends AIController {
-	stop     = false;
-
-	function Start();
-	function Stop();
-
-	constructor() {	}
-}
-
-
-
-function Regression::TestInit()
-{
-	print("");
-	print("--TestInit--");
-	print(" TickTest: " + this.GetTick());
-	Sleep(1);
-	print(" TickTest: " + this.GetTick());
-}
-
-function Regression::Base()
-{
-	local base = AIBase();
-
-	print("");
-	print("--AIBase--");
-	print("  Rand():       " + base.Rand());
-	print("  Rand():       " + base.Rand());
-	print("  Rand():       " + base.Rand());
-	print("  RandRange(0): " + base.RandRange(0));
-	print("  RandRange(0): " + base.RandRange(0));
-	print("  RandRange(0): " + base.RandRange(0));
-	print("  RandRange(1): " + base.RandRange(1));
-	print("  RandRange(1): " + base.RandRange(1));
-	print("  RandRange(1): " + base.RandRange(1));
-	print("  RandRange(2): " + base.RandRange(2));
-	print("  RandRange(2): " + base.RandRange(2));
-	print("  RandRange(2): " + base.RandRange(2));
-	print("  RandRange(9): " + base.RandRange(9));
-	print("  RandRange(9): " + base.RandRange(9));
-	print("  RandRange(9): " + base.RandRange(9));
-	print("  Chance(1, 2): " + base.Chance(1, 2));
-	print("  Chance(1, 2): " + base.Chance(1, 2));
-	print("  Chance(1, 2): " + base.Chance(1, 2));
-}
-
-function Regression::Cargo()
-{
-	local cargo = AICargo();
-
-	print("");
-	print("--AICargo--");
-	for (local i = -1; i < 15; i++) {
-		print("  Cargo " + i);
-		print("    GetCargoLabel():         '" + cargo.GetCargoLabel(i)+ "'");
-		print("    IsFreight():             " + cargo.IsFreight(i));
-		print("    GetCargoIncome(0, 0):    " + cargo.GetCargoIncome(0, 0, i));
-		print("    GetCargoIncome(10, 10):  " + cargo.GetCargoIncome(10, 10, i));
-		print("    GetCargoIncome(100, 10): " + cargo.GetCargoIncome(100, 10, i));
-		print("    GetCargoIncome(10, 100): " + cargo.GetCargoIncome(10, 100, i));
-	}
-}
-
-function Regression::Company()
-{
-	local company = AICompany();
-
-	print("");
-	print("--Company--");
-	print("  SetCompanyName():     " + company.SetCompanyName("Regression"));
-	print("  SetCompanyName():     " + company.SetCompanyName("Regression"));
-	print("  GetCompanyName():     " + company.GetCompanyName());
-	print("  GetCompanyValue():    " + company.GetCompanyValue());
-	print("  GetBankBalance():     " + company.GetBankBalance());
-	print("  GetLoanAmount():      " + company.GetLoanAmount());
-	print("  GetMaxLoanAmount():   " + company.GetMaxLoanAmount());
-	print("  GetLoanInterval():    " + company.GetLoanInterval());
-	print("  SetLoanAmount(1):     " + company.SetLoanAmount(1));
-	print("  SetLoanAmount(100):   " + company.SetLoanAmount(100));
-	print("  SetLoanAmount(10000): " + company.SetLoanAmount(10000));
-	print("  GetBankBalance():     " + company.GetBankBalance());
-	print("  GetLoanAmount():      " + company.GetLoanAmount());
-	print("  SetLoanAmount(10000): " + company.SetLoanAmount(company.GetMaxLoanAmount()));
-	print("  GetBankBalance():     " + company.GetBankBalance());
-	print("  GetLoanAmount():      " + company.GetLoanAmount());
-}
-
-function Regression::Industry()
-{
-	local industry = AIIndustry();
-	local j = 0;
-
-	print("");
-	print("--Industry--");
-	print("  GetMaxIndustryID():  " + industry.GetMaxIndustryID());
-	print("  GetIndustryCount():  " + industry.GetIndustryCount());
-	for (local i = -1; i < industry.GetMaxIndustryID(); i++) {
-		if (industry.IsValidIndustry(i)) j++;
-		print("  Industry " + i);
-		print("    IsValidIndustry(): " + industry.IsValidIndustry(i));
-		print("    GetName():         " + industry.GetName(i));
-		print("    GetLocation():     " + industry.GetLocation(i));
-	}
-	print("  Valid Industries:    " + j);
-	print("  GetIndustryCount():  " + industry.GetIndustryCount());
-}
-
-function Regression::Map()
-{
-	local map = AIMap();
-
-	print("");
-	print("--Map--");
-	print("  GetMapSize():     " + map.GetMapSize());
-	print("  GetMapSizeX():    " + map.GetMapSizeX());
-	print("  GetMapSizeY():    " + map.GetMapSizeY());
-	print("  GetTileX(123):    " + map.GetTileX(123));
-	print("  GetTileY(123):    " + map.GetTileY(123));
-	print("  IsValidTile(123): " + map.IsValidTile(123));
-	print("  GetTileX(124):    " + map.GetTileX(124));
-	print("  GetTileY(124):    " + map.GetTileY(124));
-	print("  IsValidTile(124): " + map.IsValidTile(124));
-	print("  IsValidTile(0):   " + map.IsValidTile(0));
-	print("  IsValidTile(-1):  " + map.IsValidTile(-1));
-	print("  IsValidTile():    " + map.IsValidTile(map.GetMapSize()));
-	print("  IsValidTile():    " + map.IsValidTile(map.GetMapSize() - 1));
-}
-
-function Regression::Town()
-{
-	local town = AITown();
-	local j = 0;
-
-	print("");
-	print("--Town--");
-	print("  GetMaxTownID():    " + town.GetMaxTownID());
-	print("  GetTownCount():    " + town.GetTownCount());
-	for (local i = -1; i < town.GetMaxTownID(); i++) {
-		if (town.IsValidTown(i)) j++;
-		print("  Town " + i);
-		print("    IsValidTown():   " + town.IsValidTown(i));
-		print("    GetName():       " + town.GetName(i));
-		print("    GetPopulation(): " + town.GetPopulation(i));
-		print("    GetLocation():   " + town.GetLocation(i));
-	}
-	print("  Valid Industries:  " + j);
-	print("  GetTownCount():    " + town.GetTownCount());
-}
-
-
-function Regression::Start()
-{
-	this.TestInit();
-	this.Base();
-	this.Cargo();
-	this.Company();
-	this.Industry();
-	this.Map();
-	this.Town();
-}
-
-function Regression::Stop()
-{
-	this.stop = true;
-}
-
-class FRegression extends AIFactory {
-	function GetAuthor()      { return "OpenTTD Dev Team"; }
-	function GetName()        { return "Regression"; }
-	function GetDescription() { return "This runs regression-tests on all commands. On the same map the result should always be the same."; }
-	function GetVersion()     { return 1; }
-	function GetDate()        { return "2007-03-18"; }
-	function CreateInstance() { return "Regression"; }
-}
-
-/* Only enable this if you want to run the regression test.
- *  The best way to do it is to disable all other AIs, so you are sure thisone
- *  kicks in, and use a pre-made savegame of which you already know the result.
- * You can compare the output from this AI with the pre-made one, and it should
- *  match. If not, something went wrong. */
-//iFRegression <-FRegression();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bin/ai/regression/regression.nut	Mon Mar 19 00:00:26 2007 +0000
@@ -0,0 +1,181 @@
+class Regression extends AIController {
+	stop     = false;
+
+	function Start();
+	function Stop();
+
+	constructor() {	}
+}
+
+
+
+function Regression::TestInit()
+{
+	print("");
+	print("--TestInit--");
+	print(" TickTest: " + this.GetTick());
+	Sleep(1);
+	print(" TickTest: " + this.GetTick());
+}
+
+function Regression::Base()
+{
+	local base = AIBase();
+
+	print("");
+	print("--AIBase--");
+	print("  Rand():       " + base.Rand());
+	print("  Rand():       " + base.Rand());
+	print("  Rand():       " + base.Rand());
+	print("  RandRange(0): " + base.RandRange(0));
+	print("  RandRange(0): " + base.RandRange(0));
+	print("  RandRange(0): " + base.RandRange(0));
+	print("  RandRange(1): " + base.RandRange(1));
+	print("  RandRange(1): " + base.RandRange(1));
+	print("  RandRange(1): " + base.RandRange(1));
+	print("  RandRange(2): " + base.RandRange(2));
+	print("  RandRange(2): " + base.RandRange(2));
+	print("  RandRange(2): " + base.RandRange(2));
+	print("  RandRange(9): " + base.RandRange(9));
+	print("  RandRange(9): " + base.RandRange(9));
+	print("  RandRange(9): " + base.RandRange(9));
+	print("  Chance(1, 2): " + base.Chance(1, 2));
+	print("  Chance(1, 2): " + base.Chance(1, 2));
+	print("  Chance(1, 2): " + base.Chance(1, 2));
+}
+
+function Regression::Cargo()
+{
+	local cargo = AICargo();
+
+	print("");
+	print("--AICargo--");
+	for (local i = -1; i < 15; i++) {
+		print("  Cargo " + i);
+		print("    GetCargoLabel():         '" + cargo.GetCargoLabel(i)+ "'");
+		print("    IsFreight():             " + cargo.IsFreight(i));
+		print("    GetCargoIncome(0, 0):    " + cargo.GetCargoIncome(0, 0, i));
+		print("    GetCargoIncome(10, 10):  " + cargo.GetCargoIncome(10, 10, i));
+		print("    GetCargoIncome(100, 10): " + cargo.GetCargoIncome(100, 10, i));
+		print("    GetCargoIncome(10, 100): " + cargo.GetCargoIncome(10, 100, i));
+	}
+}
+
+function Regression::Company()
+{
+	local company = AICompany();
+
+	print("");
+	print("--Company--");
+	print("  SetCompanyName():     " + company.SetCompanyName("Regression"));
+	print("  SetCompanyName():     " + company.SetCompanyName("Regression"));
+	print("  GetCompanyName():     " + company.GetCompanyName());
+	print("  GetCompanyValue():    " + company.GetCompanyValue());
+	print("  GetBankBalance():     " + company.GetBankBalance());
+	print("  GetLoanAmount():      " + company.GetLoanAmount());
+	print("  GetMaxLoanAmount():   " + company.GetMaxLoanAmount());
+	print("  GetLoanInterval():    " + company.GetLoanInterval());
+	print("  SetLoanAmount(1):     " + company.SetLoanAmount(1));
+	print("  SetLoanAmount(100):   " + company.SetLoanAmount(100));
+	print("  SetLoanAmount(10000): " + company.SetLoanAmount(10000));
+	print("  GetBankBalance():     " + company.GetBankBalance());
+	print("  GetLoanAmount():      " + company.GetLoanAmount());
+	print("  SetLoanAmount(10000): " + company.SetLoanAmount(company.GetMaxLoanAmount()));
+	print("  GetBankBalance():     " + company.GetBankBalance());
+	print("  GetLoanAmount():      " + company.GetLoanAmount());
+}
+
+function Regression::Industry()
+{
+	local industry = AIIndustry();
+	local j = 0;
+
+	print("");
+	print("--Industry--");
+	print("  GetMaxIndustryID():  " + industry.GetMaxIndustryID());
+	print("  GetIndustryCount():  " + industry.GetIndustryCount());
+	for (local i = -1; i < industry.GetMaxIndustryID(); i++) {
+		if (industry.IsValidIndustry(i)) j++;
+		print("  Industry " + i);
+		print("    IsValidIndustry(): " + industry.IsValidIndustry(i));
+		print("    GetName():         " + industry.GetName(i));
+		print("    GetLocation():     " + industry.GetLocation(i));
+	}
+	print("  Valid Industries:    " + j);
+	print("  GetIndustryCount():  " + industry.GetIndustryCount());
+}
+
+function Regression::Map()
+{
+	local map = AIMap();
+
+	print("");
+	print("--Map--");
+	print("  GetMapSize():     " + map.GetMapSize());
+	print("  GetMapSizeX():    " + map.GetMapSizeX());
+	print("  GetMapSizeY():    " + map.GetMapSizeY());
+	print("  GetTileX(123):    " + map.GetTileX(123));
+	print("  GetTileY(123):    " + map.GetTileY(123));
+	print("  IsValidTile(123): " + map.IsValidTile(123));
+	print("  GetTileX(124):    " + map.GetTileX(124));
+	print("  GetTileY(124):    " + map.GetTileY(124));
+	print("  IsValidTile(124): " + map.IsValidTile(124));
+	print("  IsValidTile(0):   " + map.IsValidTile(0));
+	print("  IsValidTile(-1):  " + map.IsValidTile(-1));
+	print("  IsValidTile():    " + map.IsValidTile(map.GetMapSize()));
+	print("  IsValidTile():    " + map.IsValidTile(map.GetMapSize() - 1));
+}
+
+function Regression::Town()
+{
+	local town = AITown();
+	local j = 0;
+
+	print("");
+	print("--Town--");
+	print("  GetMaxTownID():    " + town.GetMaxTownID());
+	print("  GetTownCount():    " + town.GetTownCount());
+	for (local i = -1; i < town.GetMaxTownID(); i++) {
+		if (town.IsValidTown(i)) j++;
+		print("  Town " + i);
+		print("    IsValidTown():   " + town.IsValidTown(i));
+		print("    GetName():       " + town.GetName(i));
+		print("    GetPopulation(): " + town.GetPopulation(i));
+		print("    GetLocation():   " + town.GetLocation(i));
+	}
+	print("  Valid Industries:  " + j);
+	print("  GetTownCount():    " + town.GetTownCount());
+}
+
+
+function Regression::Start()
+{
+	this.TestInit();
+	this.Base();
+	this.Cargo();
+	this.Company();
+	this.Industry();
+	this.Map();
+	this.Town();
+}
+
+function Regression::Stop()
+{
+	this.stop = true;
+}
+
+class FRegression extends AIFactory {
+	function GetAuthor()      { return "OpenTTD Dev Team"; }
+	function GetName()        { return "Regression"; }
+	function GetDescription() { return "This runs regression-tests on all commands. On the same map the result should always be the same."; }
+	function GetVersion()     { return 1; }
+	function GetDate()        { return "2007-03-18"; }
+	function CreateInstance() { return "Regression"; }
+}
+
+/* Only enable this if you want to run the regression test.
+ *  The best way to do it is to disable all other AIs, so you are sure thisone
+ *  kicks in, and use a pre-made savegame of which you already know the result.
+ * You can compare the output from this AI with the pre-made one, and it should
+ *  match. If not, something went wrong. */
+iFRegression <-FRegression();
--- a/bin/ai/regression/regression.txt	Sun Mar 18 23:59:07 2007 +0000
+++ b/bin/ai/regression/regression.txt	Mon Mar 19 00:00:26 2007 +0000
@@ -4,9 +4,9 @@
  TickTest: 1
 
 --AIBase--
+  Rand():       -393215143
   Rand():       -814314580
   Rand():       959788226
-  Rand():       -1372813959
   RandRange(0): 0
   RandRange(0): 0
   RandRange(0): 0
@@ -14,14 +14,14 @@
   RandRange(1): 0
   RandRange(1): 0
   RandRange(2): 0
+  RandRange(2): 0
   RandRange(2): 1
-  RandRange(2): 0
+  RandRange(9): 1
   RandRange(9): 2
   RandRange(9): 8
-  RandRange(9): 2
   Chance(1, 2): true
   Chance(1, 2): true
-  Chance(1, 2): false
+  Chance(1, 2): true
 
 --AICargo--
   Cargo -1
--- a/bin/ai/regression/run.sh	Sun Mar 18 23:59:07 2007 +0000
+++ b/bin/ai/regression/run.sh	Mon Mar 19 00:00:26 2007 +0000
@@ -1,16 +1,11 @@
 #!/bin/sh
 
-if ! [ -f ai/regression/main.nut ]; then
+if ! [ -f ai/regression/regression.nut ]; then
 	echo "Make sure you are in the root of OpenTTD before starting this script."
 	exit 1
 fi
 
-if [ -n "`cat ai/regression/main.nut | grep '//iFRegression <-FRegression();'`" ]; then
-	echo "Enable the Regression AI before starting the regression test."
-	echo "Also disable any other AI. Check main.nut in ai/regression for"
-	echo "more information about this."
-	exit 1
-fi
+cp ai/regression/regression.nut ai/regression/main.nut
 
 ./openttd -a regression -x -c ai/regression/regression.cfg -snull -mnull -vnull -g ai/regression/regression.sav | awk '{ gsub("0x\\(nil\\)", "0x00000000", $0); print $0; }' > tmp.regression
 res="`diff -u ai/regression/regression.txt tmp.regression`"
@@ -23,6 +18,8 @@
 echo ""
 echo "Regression test done"
 
+rm ai/regression/main.nut
+
 if [ "$1" != "-k" ]; then
 	rm -f tmp.regression
 fi