Commits

mcc  committed fc681a2

Shelves

  • Participants
  • Parent commits 6f54665

Comments (0)

Files changed (1)

File server/server.py

 define("tanks", default=5, help="number of tanks", type=int)
 define("specs", default=10, help="species per tank", type=int)
 define("giants", default=0, help="how many giants?", type=int)
+define("shelf_after", default=0, help="where is shelf?", type=int)
+define("shelf_size", default=0, help="how big is shelf?", type=int)
 define("debug", default=0, help="debug runlevel", type=int)
 define("debug_delay", default=0, help="debug: fake response delay", type=float)
 define("debug_failure", default=0, help="debug: fake request failure", type=int)
 def randomfromdict(s):
 	return s[randomfrom(s.keys())]
 
+player_db = {}
+def player_hits(post_obj):
+	if options.shelf_after <= 0 or not post_obj:
+		return 0
+	key = None
+	if post_obj.hasAttribute("pid"):
+		key = post_obj["pid"]
+	else:
+		for node in post_obj.getElementsByTagName("pid"):
+			if node.firstChild:
+				key = node.firstChild.nodeValue
+				break
+	
+	if not player_db.has_key(key):
+		player_db[key] = 0
+	player_db[key] += 1
+	if options.debug > 3:
+		print ("Visit #%d for player '%s'" % (player_db[key], key))
+	return player_db[key]
+
 class Board:
 	def __init__(self, xdim = 24, ydim = 24, suppress = False):
 		self.xdim = xdim
 class Manager:
 	def __init__(self):
 		self.tanks = {}
+		self.alltanks = {}
 		for _i in range(options.tanks):
 			i = _i + 1
 			if options.debug > 0:
 				print("Generating tank %d" % i)
-			self.tanks[i] = Genome(i)
+			self.alltanks[i] = Genome(i)
+			if _i < options.shelf_size:
+				self.tanks[i] = self.alltanks[i]
 	
-	def any(self):
-		return randomfromdict(self.tanks)
+	def any(self, post_obj):
+		if player_hits(post_obj) > options.shelf_after:
+			return randomfromdict(self.alltanks)
+		else:
+			return randomfromdict(self.tanks)
 		
 	def report(self, post_obj):
 		for a in ["gid","sid","deaths","lastf"]:
 		if post_obj:
 			m.report(post_obj)
 		r = doc.createElement("level")
-		s = m.any()
+		s = m.any(post_obj)
 		s.any().xml(doc, r)
 		return r