def start(self, arguments: list): size = 0 error_message = "unsupported size" if (len(arguments) != 2): self.error(error_message) return try: size = int(arguments[1]) except ValueError: self.error(error_message) return if (size < 5 or size > 20): self.error(error_message) return self.game = Game(size, size) self.brain = EmacsBrain(self.game, self.infos) flush_print("OK")
def rectstart(self, arguments: list): size_x = 0 size_y = 0 error_message = "rectangular board is not supported or other error" if (len(arguments) != 3): self.error(error_message) return try: size_x = int(arguments[1]) size_y = int(arguments[2]) except ValueError: self.error(error_message) return if (size_x < 5 or size_x > 20): self.error(error_message) return if (size_y < 5 or size_y > 20): self.error(error_message) return self.game = Game(size_x, size_y) self.brain = EmacsBrain(self.game, self.infos) flush_print("OK") pass
def board_treat_line(self, line: str): line = line.strip() if (line.upper() == "DONE"): answer = self.brain.play() flush_print("%d,%d" % (answer[0], answer[1])) self.game.set_piece(answer[0], answer[1], 1) return (False) arguments = line.split(",") arguments = list(map(lambda arg: arg.strip(), arguments)) try: x = int(arguments[0]) y = int(arguments[1]) player = int(arguments[2]) if (player != 1 and player != 2): self.error("Invalid values.") return (False) if not (self.game.set_piece(x, y, player)): self.error("Invalid values.") return (True) except ValueError: self.error("Invalid arguments.") return (True)
def error(self, message: str): flush_print("ERROR %s" % (message))
def unknow(self, message: str): flush_print("UNKNOWN %s" % (message))
def restart(self, arguments: list): self.game = Game(self.game.size_x, self.game.size_y) self.brain = EmacsBrain(self.game, self.infos) flush_print("OK")
def about(self, arguments: list): flush_print( "name=\"%s\", version=\"%s\", author=\"%s\", country=\"%s\"" % ("Gomme au fesses", "0.2.0", "Toto & Kebab", "FR"))