def tour(self): # log logger.info("\n------------------") logger.info(self) logger.debug(json.dumps(self.update_game_state(""), indent=4)) # work self.actions() self.fantom_scream() for p in self.characters: p.power = True self.num_tour += 1
def receive_json_from_player(player): """ Receives a python object from the client and converts it to a python object. :param player: object of the class Player. Either the fantom or the inspector. :return: return a python-readable object. """ logger.debug(f"receive json from player {player}") received_bytes = protocol.receive_json(clients[player]) json_object = json.loads(received_bytes) return json_object
def play(self, game): logger.info("--\n" + self.role + " plays\n--") logger.debug(json.dumps(game.update_game_state(""), indent=4)) charact = self.select(game.active_cards, game.update_game_state(self.role)) # red character can choose to activate its power # before OR after moving if charact.color == "red": activation_possibilities = ["before", "after"] question = { "question type": "red character power activation time", "data": activation_possibilities, "game state": game.update_game_state(self.role) } power_activation_time = ask_question_json(self, question) if power_activation_time not in [0, 1]: power_activation_time = random.choice(activation_possibilities) else: power_activation_time = activation_possibilities[ power_activation_time] # now play red character if power_activation_time == "before": moved_characters = self.activate_power( charact, game, before | both, game.update_game_state(self.role)) self.move(charact, [charact], game.blocked, game.update_game_state(self.role)) else: self.move(charact, [charact], game.blocked, game.update_game_state(self.role)) self.activate_power(charact, game, after | both, game.update_game_state(self.role)) # character is not red else: moved_characters = self.activate_power( charact, game, before | both, game.update_game_state(self.role)) self.move(charact, moved_characters, game.blocked, game.update_game_state(self.role)) self.activate_power(charact, game, after | both, game.update_game_state(self.role))
def play(self, game): logger.info("--\n" + self.role + " plays\n--") logger.debug(json.dumps(game.update_game_state(""), indent=4)) charact = self.select(game.active_cards, game.update_game_state(self.role)) # purple and brown power choose to activate or not before moving moved_character = self.activate_power( charact, game, before, game.update_game_state(self.role)) self.move(charact, moved_character, game.blocked, game.update_game_state(self.role), game) self.activate_power(charact, game, after, game.update_game_state(self.role))
def play(self, game): logger.info("--\n" + self.role + " plays\n--") logger.debug(json.dumps(game.update_game_state(""), indent=4)) charact = self.select(game.active_tiles, game.update_game_state(self.role)) moved_characters = self.activate_power(charact, game, before | two, game.update_game_state(self.role)) self.move(charact, moved_characters, game.blocked, game.update_game_state(self.role)) self.activate_power(charact, game, after | two, game.update_game_state(self.role))
def move(self, charact, moved_characters, blocked, game_state): """ Select a new position for the character. """ pass_act = pink_passages if charact.color == 'pink' else passages if charact.color != 'purple' or charact.power: disp = { x for x in pass_act[charact.position] if charact.position not in blocked or x not in blocked } available_positions = list(disp) question = { "question type": "select position", "data": available_positions, "game state": game_state } selected_index = ask_question_json(self, question) # test if selected_index not in range(len(disp)): warning_message = (' ! : selected position not available ' 'Choosing random position.') logger.warning(warning_message) selected_position = disp.pop() else: selected_position = available_positions[selected_index] logger.info(f"question : {question['question type']}") logger.info("answer : " + str(selected_position)) if len(moved_characters) > 1: logger.debug("more than one character moves") for q in moved_characters: q.position = selected_position logger.info("new position : " + str(q))