Fixed! Forgot to attach the patch file.

On Fri, Apr 18, 2008 at 3:45 PM, Juan Lafont <[EMAIL PROTECTED]> wrote:

> The Generator should be fully deterministic now and not mess up as the
> seed should now be implemented in the actual initialization of the generator
> instead of being given for each time the function is called.
>
> Also added my name to gitconfig.
>
From c9c4e04b38f8aa45cbb48664396fca74485b9a30 Mon Sep 17 00:00:00 2001
From: Juan Lafont <[EMAIL PROTECTED]>
Date: Fri, 18 Apr 2008 15:42:35 -0400
Subject: Minisec Planet Name Generator. Should be fully deterministic and working correctly

Minisec should now have planet names be generated by the --populate command instead of using numbers. Generator should be deterministic and produce the same names for the same seed.
---
 tp/server/rules/minisec/__init__.py |    3 +--
 tp/server/utils/planetGenerator.py  |   10 +++++-----
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/tp/server/rules/minisec/__init__.py b/tp/server/rules/minisec/__init__.py
index 2624468..c7643a4 100644
--- a/tp/server/rules/minisec/__init__.py
+++ b/tp/server/rules/minisec/__init__.py
@@ -97,13 +97,12 @@ class Ruleset(RulesetBase):
 			# FIXME: Assuming that the Universe and the Galaxy exist.
 			r = random.Random()
 			r.seed(int(seed))
+			PG = PlanetGenerator(theSeed = int(seed))
 
 			# Create this many systems
 			for i in range(0, r.randint(system_min, system_max)):
 				pos = r.randint(SIZE*-1, SIZE)*1000, r.randint(SIZE*-1, SIZE)*1000, r.randint(SIZE*-1, SIZE)*1000
 				
-				PG = PlanetGenerator()
-				
 				# Add system
 				system = Object(type='tp.server.rules.base.objects.System')
 				system.name = "System %s" % PG.genName()
diff --git a/tp/server/utils/planetGenerator.py b/tp/server/utils/planetGenerator.py
index d4cb116..e82cc12 100644
--- a/tp/server/utils/planetGenerator.py
+++ b/tp/server/utils/planetGenerator.py
@@ -10,7 +10,7 @@ class PlanetGenerator:
 	"""\
 	Class Planet Generator
 	"""
-	def __init__(self, s = os.path.abspath(os.path.curdir) + '/tp/server/utils/default.txt'):
+	def __init__(self, s = os.path.abspath(os.path.curdir) + '/tp/server/utils/default.txt', theSeed= None):
 		"""\
 		Initialization:
 		s is a string containing the file name
@@ -20,13 +20,13 @@ class PlanetGenerator:
 		for s in syl:
 			self.syllables.append(s.strip())
 		syl.close()
+		random.seed(theSeed)
 
-	def genName(self, theSeed= None):
+	def genName(self):
 		"""/
 		Name Generator
 		theSeed is the seed number used for the number generator.
 		"""
-		random.seed(theSeed)
 		numberOfWords = random.randint(1, 2)
 		numberOfSyllables = random.randint(2, 4)
 		for x in range(0, numberOfWords):
@@ -47,5 +47,5 @@ class PlanetGenerator:
 
 
 #Testing Code
-#p = PlanetGenerator("default.txt")
-#print p.genName()
+#p = PlanetGenerator("default.txt", 100)
+#for x in range(1 , 10): print p.genName()
-- 
1.5.2.5

_______________________________________________
tp-devel mailing list
[email protected]
http://www.thousandparsec.net/tp/mailman.php/listinfo/tp-devel

Reply via email to