Commits

mcc committed c5030c8

Clone and mutate-- badly

Comments (0)

Files changed (3)

media/overlay/play/onLoad.lua

 		dos:set_centered(0,safeline,40,   "DEAD!!!!#YOU#ARE#A#TERRIBLE#PLAYER", false)
 		dos:set_centered(0,safeline+1,40, "PRESS#\010#TO#CONTINUE", false)
 		dos:set_centered(0,safeline+2,40, "(OR#Q#IF#THIS#LEVEL#IS#IMPOSSIBLE)", false)
+		force_load = gm.level
 	end
 end
 
--- "The actual game" 
-
-makeDos()
-dosLoading()
-xhr(um.level, function(t)
-	dos:clear()
-	gm.level = Spec(t)
+function startWithSpec(level)
+	gm.level = level
 	gm.level:load(gm)
 	bridge:register_room_onCollision(gm.player, function()
 		local _b = bridge:room_b()
 			end
 		end
 	end)
-end)
+end
+
+-- "The actual game" 
+
+makeDos()
+if force_load then
+	local will_force_load = force_load
+	force_load = nil -- TODO -- not in debug mode
+	startWithSpec(will_force_load)
+else
+	dosLoading()
+	xhr(um.level, function(t)
+		dos:clear()
+		startWithSpec(Spec(t))
+	end)
+end
 
 -- Set up input handler
 down = {} pressed = {}

media/overlay/play/onUpdate.lua

 	if not gm.playerat then
 		gm.playerat = ticks
 	end
-	if not gm.introdone then
+	if not gm.introdone then -- TODO: This sucks
 		local playerticks = ticks-gm.playerat
 		local pmod = playerticks%km.introflick
 		local pat = math.floor(playerticks/km.introflick)
 define("history", default='history.log', help="history log filename", type=str)
 define("database", default='database.db', help="database filename", type=str)
 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("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)
 PLAYER=1
 EXIT=2
 
+def randomfrom(s):
+	return s[randint(0,len(s)-1)]
+
 class Board:
-	def __init__(self, xdim = 24, ydim = 24):
+	def __init__(self, xdim = 24, ydim = 24, suppress = False):
 		self.xdim = xdim
 		self.ydim = ydim
-		self.basic()
-		self.noise(10, WALL)
-		self.noise(3, LAVA)
-		self.px = randint(1,self.xdim-2)
-		self.py = self.ydim-2
-		self.ex = randint(1,self.xdim-2)
-		self.ey = randint(2,4)
+		if not suppress:
+			self.basic()
+			self.noise(10, WALL)
+			self.noise(3, LAVA)
+			self.px = randint(1,self.xdim-2)
+			self.py = self.ydim-2
+			self.ex = randint(1,self.xdim-2)
+			self.ey = randint(2,4)
+		
+	def clone(self):
+		c = Board(self.xdim,self.ydim, True)
+		c.str = self.str
+		c.px = self.px
+		c.py = self.py
+		c.ex = self.ex
+		c.ey = self.ey
+		return c
 	
 	def basic(self):
 		cap = [WALL] * self.xdim
 		mid = [WALL] + [AIR]*(self.xdim-2) + [WALL]
 		self.str = cap + mid*(self.ydim-2) + cap
-		
+	
+	def mutate(self):
+		self.noise(1, WALL)
+		self.noise(1, AIR)
+		if random()<0.3:
+			self.noise(1,LAVA)
+		return self
+	
 	# Dust, don't flip
 	def noise(self, c, what):
 		for i in range(c):
 				if x2 >= 0 and x2 < self.xdim:
 					self.set(y,x2,what)
 	
-	def clear():
+	def clear(self):
 		self.str = AIR * (self.xdim*self.ydim)
 	
 	def i(self, x,y):
 		return r
 	
 class Spec:
-	def __init__(self, gid, sid):
+	def __init__(self, gid, suppress = False):
 		self.gid = gid
-		self.sid = sid
-		self.board = Board()
+		self.sid = -1
+		if not suppress:
+			self.board = Board()
+		
+	def clone(self):
+		c = Spec(self.gid, True)
+		c.board = self.board.clone()
+		return c
+		
+	def mutate(self):
+		self.board.mutate()
+		return self
 		
 	def xml(self, doc, r):
 		r.setAttribute("gid", str(self.gid))
 class Genome:
 	def __init__(self, id):
 		self.id = id
-		self.specs = [Spec(id, 0)]
+		self.specs = []
+		basic = Spec(id)
+		for i in range(options.specs):
+			s = basic.clone().mutate()
+			s.sid = i
+			self.specs.append(s)
+
 	def any(self):
-		return self.specs[0]
+		return randomfrom(self.specs)
 
 class Manager:
 	def __init__(self):
 			self.tanks.append(Genome(i))
 	
 	def any(self):
-		return self.tanks[randint(0,len(self.tanks)-1)]
-
-m = Manager()
+		return randomfrom(self.tanks)
 
 class LuaHandler(tornado.web.RequestHandler):
 	def result(self, doc, post_obj):
 class LevelHandler(LuaHandler):
 	def result(self, doc, post_obj):
 		r = doc.createElement("level")
-		m.any().any().xml(doc, r)
+		s = m.any()
+		s.any().xml(doc, r)
 		return r
 
 class UnUpdateHandler(tornado.web.RequestHandler):
 	if options.database:
 		global database
 		print("Will save to %s" % (options.database))
+		
+	global m
+	m = Manager()
+	
 	application = tornado.web.Application([
 		(r"/", MainHandler),
 		(r"/welcome", WelcomeHandler),