def convert_to_rc_solution( solution: Solution, translator: PegTranslator, starting_person_position: Peg) -> RiverCrossingSolution: ''' Takes a solution, a translator from pegs to RC characters, ...and a peg number for the starting person position, ...and returns the River Crossing solution string for that solution. ''' def plank_converter(plank: Plank) -> str: ans = "" for peg in plank: ans += translator[peg].upper() return "".join(sorted(ans)) ans = "" person_position = starting_person_position for move_type, peg in solution: if move_type == "walk": person_position = peg elif move_type == "grab": ans += plank_converter(get_plank(peg, person_position)) + '-' elif move_type == "place": ans += plank_converter(get_plank(peg, person_position)) + ' ' else: raise ValueError("Unrecognized move type {}".format(move_type)) return ans.strip()
def __init__(self) -> None: start, end = 34, 3 pegs = [3, 7, 9, 11, 12, 15, 18, 20, 21, 24, 26, 28, 34] planks = [(34, 24), (24, 9), (9, 7), (7, 12)] # make sure my plank pegs are in the correct order planks = [get_plank(*points) for points in planks] # checking input assert start in pegs assert end in pegs for peg1, peg2 in planks: assert peg1 in pegs assert peg2 in pegs super().__init__(start, end, pegs, planks)
def __init__(self) -> None: start, end = 16, 20 pegs = [16, 20, 18, 1, 4, 7, 8, 14, 22, 28, 29, 34, 31, 32] planks = [(31, 16), (28, 29), (4, 14), (7, 22)] # make sure my plank pegs are in the correct order planks = [get_plank(*points) for points in planks] # checking input assert start in pegs assert end in pegs for peg1, peg2 in planks: assert peg1 in pegs assert peg2 in pegs super().__init__(start, end, pegs, planks)
def __init__(self) -> None: start, end = 27, 15 pegs = [7, 9, 15, 13, 11, 17, 27, 19, 24, 23, 21] planks = [(27, 17), (23, 13), (24, 19)] # make sure my plank pegs are in the correct order planks = [get_plank(*points) for points in planks] # checking input assert start in pegs assert end in pegs for peg1, peg2 in planks: assert peg1 in pegs assert peg2 in pegs super().__init__(start, end, pegs, planks)
def __init__(self) -> None: start, end = 32, 4 pegs = [4, 14, 13, 23, 22, 32] planks = [(32, 22), (22, 23)] # make sure my plank pegs are in the correct order planks = [get_plank(*points) for points in planks] # checking input assert start in pegs assert end in pegs for peg1, peg2 in planks: assert peg1 in pegs assert peg2 in pegs super().__init__(start, end, pegs, planks)
def __init__(self) -> None: start, end = 30, 1 pegs = [1, 4, 8, 9, 12, 15, 16, 18, 19, 21, 22, 24, 26, 28, 30, 32, 33, 34] planks = [(30, 15), (24, 19), (26, 28), (22, 12), (8, 9)] # make sure my plank pegs are in the correct order planks = [get_plank(*points) for points in planks] # checking input assert start in pegs assert end in pegs for peg1, peg2 in planks: assert peg1 in pegs assert peg2 in pegs super().__init__(start, end, pegs, planks)
def __init__(self, base_board_creator: Callable[[], Board], solution_string: RiverCrossingSolution, translator: RiverCrossingCharacterTranslator): ''' Takes a function that creates a board when called with no parameters ...and a River Crossing solution string, ...and a translator from pegs to RC solution characters ''' # when called, creates the board after 0 steps self.base_board_creator = base_board_creator solution_string = solution_string.strip().upper() self.moves: List[Tuple[ Plank, Plank]] = solution_string.split() # type: ignore self.moves = [move.split('-') for move in self.moves] # type: ignore self.moves = [ tuple([ get_plank(*[translator[peg] for peg in plank]) # type: ignore for plank in move ]) for move in self.moves ]