Exemple #1
0
def handle_move(game: database.Game, san_move: str) -> None:
    board = load_from_pgn(game.pgn)

    try:
        move(board, san_move)
    except ValueError as err:
        raise err

    game.pgn = save_to_pgn(board)
    database.add_to_database(game)
Exemple #2
0
	def handleGame(self, full, delta):
		if delta.get("isCrash"):
			delta["step"] = len(full["states"])
			if "queues" in full:
				for queue in full["queues"]:
					queue.put(delta)
			full["crashes"].append(delta)
			return True

		if full["action"] in ["start", "qualify"]:
			if "success" in delta and full["action"] == "start":
				if not self.app:
					raise RuntimeError("Spiel vor verbindung mit App")
				with self.app.app_context():
					logger.info("game finished!")
					g = Game.from_inprogress(full)
					logger.debug(g)
					if g:
						full["finished_game_obj"] = g
					else:
						logger.warning("Game.from_inprogress hat kein Spiel-Objekt zurückgegeben")
						logger.info("Sending exception as crash")
						for ai in [full["ai0"], full["ai1"]]:
							self.handleGame(full, {
								"isCrash": True,
								"requestid": delta["requestid"],
								"reason": delta.get("exception", "reason missing"),
								"id": str(ai.id)+'v'+str(ai.latest_version().version_id),
								"step": 0
							})

			if "data" in delta:
				delta["data"]["calculationPoints"] = delta["calculationPoints"]
				full["states"].append(delta["data"])

			if "status" in delta and delta["status"] == "restarted":
				full["states"] = []
				full["crashes"] = []

			for q in self.game_update_queues:
				q.put(delta)