def get_exit_port(index, rotate_degree, entry_port): tile_config = convert_representation(get_representation(index)) target_tile = tile.Tile(tile_config) rotation_time = rotate_degree // 90 for i in range(rotation_time): target_tile = target_tile.rotate_90() exit_port = target_tile.get_path(convert_letter_to_int(entry_port)) return convert_int_to_letter(exit_port)
def generate_tile_dictionary(): tile_dict = {} tiles_list = tiles.splitlines() for i in range(len(tiles_list)): tile_letter_representation = json.loads(tiles_list[i])[1] tile_int_representation = convert_representation(tile_letter_representation) current_tile = tile.Tile(tile_int_representation) tile_dict[i] = current_tile return tile_dict
rule_checker = rules.RuleChecker() input_content = ''.join(sys.stdin.readlines()) json_array = json.loads(input_content) for placement_json in json_array[:-1]: if not parse_move(game_board, placement_json): raise Exception("Invalid placement.") player_final_move = json_array[-1] color = player_final_move[0][0] chosen_tile_index = player_final_move[0][1] rotation = player_final_move[0][2] target_x = player_final_move[0][3] target_y = player_final_move[0][4] choice_one = player_final_move[1] choice_two = player_final_move[2] if color not in valid_colors: raise Exception("Invalid color") chosen_tile = tile.Tile( convert_representation( get_representation(chosen_tile_index))).rotate_tile(rotation) choice_one_tile = tile.Tile( convert_representation(get_representation(choice_one))) choice_two_tile = tile.Tile( convert_representation(get_representation(choice_two))) player_pos = game_board.get_player(color) check = rule_checker.valid_move(game_board, target_x, target_y, chosen_tile, [choice_one_tile, choice_two_tile], player_pos[0], player_pos[1], player_pos[2]) print("legal" if check else "illegal")