Пример #1
0
def main(runs):
    print('gamma, eta, width, runs, hareWins, houndWins')
    for p in glob.glob('trainedQs/*.q'):
        with open(p, 'rb') as f:
            (gamma, width, eta, oruns, hareQ, houndQ) = pickle.load(f)
            gm = GameMaster(width, gamma, eta, False)
            res = gm.run(runs, hareQ, houndQ)
            print("{}, {}, {}, {}, {}, {}"
                    .format(gamma, eta, width, oruns, res['hare'], res['hounds']))
Пример #2
0
def train_worker(q):
    while 1:
        try:
            task = q.get(True, 1)
        except queue.Empty:
            break
        width, gamma, eta, runs = task
        logger.warning('Training with gamma {} eta {} width {} runs {}'.format(
            gamma, eta, width, runs))
        gm = GameMaster(width, gamma, eta, True)
        Qs = gm.run(runs)
        with open('trainedQs/g{}_w{}_e{}_r{}.q'.format(gamma, width,
                eta, runs), 'wb') as f:
            pickle.dump((gamma, width, eta, runs, Qs[0], Qs[1]), f)
        q.task_done()
Пример #3
0
	def accept(self, reader, writer):
		emit = lambda **event: self.emit(writer, **event)
		
		try:
			player = yield from asyncio.wait_for(reader.readline(), 1)
			player = json.loads(player.decode())
			
			if type(player) is dict and player["name"] and player["game"]:
				if type(player["game"]) is str:
					if self.games[player["game"]] and not self.games[player["game"]].playersFull:
						player = self.games[player["game"]].join(player["name"], emit)
					else:
						raise Exception("invalid game key")
				elif player["game"]["players"] >= 2 and player["game"]["dice"] >= 2:
					gkey = hex(random.getrandbits(64))[2:]
					gcls = GameMaster(player["game"]["players"], player["game"]["dice"])
					
					self.games[gkey] = gcls
					
					player = gcls.join(player["name"], emit)
				else:
					raise Exception("invalid game parameters")
			else:
				raise Exception("invalid join request")
		except Exception as err:
			emit(type="error", error=str(err) or "timeout")
			emit(type="end")
			return
		
		while True:
			data = yield from reader.readline()
			
			if not data:
				player(type="leave")
				break
			
			try:
				player(**json.loads(data.decode()))
			except Exception as err:
				emit(type="error", error=str(err))