day_16
Types
pub type Direction {
North
East
South
West
None
}
Constructors
-
North
-
East
-
South
-
West
-
None
Functions
pub fn get_end_position(
map: Dict(#(Int, Int), Tile),
) -> #(Int, Int)
Get end position of a given map.
pub fn get_paths(
map: Dict(#(Int, Int), Tile),
current_position: #(Int, Int),
current_direction: Direction,
current_path: List(#(Int, Int)),
current_score: Int,
paths: List(#(Int, List(#(Int, Int)))),
already_checked: Dict(#(Int, Int), Bool),
target_position: #(Int, Int),
) -> List(#(Int, List(#(Int, Int))))
pub fn get_possible_steps(
map: Dict(#(Int, Int), Tile),
position: #(Int, Int),
) -> List(#(#(Int, Int), Direction))
Given a position, get all possible next steps, (i.e not a wall, start, or out of bounds)
pub fn get_scores(
map: Dict(#(Int, Int), Tile),
current_position: #(Int, Int),
current_direction: Direction,
current_path: List(#(Int, Int)),
current_score: Int,
scores: List(Int),
already_checked: Dict(#(Int, Int), Bool),
target_position: #(Int, Int),
counter: Int,
) -> List(Int)
pub fn get_scores_memoized(
map: Dict(#(Int, Int), Tile),
current_position: #(Int, Int),
current_direction: Direction,
current_path: List(#(Int, Int)),
current_score: Int,
scores: List(Int),
already_checked: Dict(#(Int, Int), Bool),
target_position: #(Int, Int),
known_scores: Dict(#(Int, Int), List(Int)),
) -> #(List(Int), Dict(#(Int, Int), List(Int)))
pub fn get_start_position(
map: Dict(#(Int, Int), Tile),
) -> #(Int, Int)
Get start position of a given map.
pub fn get_step_cost(
current_direction: Direction,
next_direction: Direction,
) -> Int
Get the step cost associated with two directions. If they are the same, it’s 1 - if they are different, we assume that we have to turn once, as there is no path that makes a 180 degree turn necessary.
pub fn get_surrounding_positions(
position: #(Int, Int),
) -> List(#(#(Int, Int), Direction))
Get all surrounding positions (in a cross pattern) of a given position.
pub fn get_tile_position(
map: Dict(#(Int, Int), Tile),
tile: Tile,
) -> #(Int, Int)
Find the first coordinates corresponding to a specific tile (only really useful for start and end, as they appear exactly once)
pub fn heuristic_score(
current_position: #(Int, Int),
target_position: #(Int, Int),
) -> Int
Get a heuristic for the score from one position to another. This assumes that there are no walls between the two positions and, using the taxicab distance as a basis, adds 1000 depending on whether a single turn needs to be made or not.
(If we’re not on the same x or y line, we assoume that we have to turn once)
pub fn is_start(
map: Dict(#(Int, Int), Tile),
position: #(Int, Int),
) -> Bool
Given a position, check if it is the start
pub fn parse_tile(char: String) -> Tile
pub fn print_path(
path: List(#(Int, Int)),
map: Dict(#(Int, Int), Tile),
) -> List(#(Int, Int))
pub fn stringify_map(
map: Dict(#(Int, Int), Tile),
) -> Dict(#(Int, Int), String)
pub fn tile_to_string(tile: Tile) -> String