Last active
June 1, 2016 15:30
-
-
Save NullVoxPopuli/97753b30b039553d35b566a985135772 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
coords = [ | |
[-3, 0], [2, -3], [0, 0], | |
[2, -4], [-1, -4], [-3, -2], | |
[2, -1], [1, -4], [-2, -1], | |
[-1, -3], [2, 0], [-2, -3], | |
[2, -2], [-2, -2], [-2, 0], | |
[-3, -3], [1, 0], [-3, -1], | |
[0, -4]] | |
pre_normalized_coords = [ | |
[0, 4], [5, 1], [3, 4], | |
[5, 0], [2, 0], [0, 2], | |
[5, 3], [4, 0], [1, 3], | |
[2, 1], [5, 4], [1, 1], | |
[5, 2], [1, 2], [1, 4], | |
[0, 1], [4, 4], [0, 3], | |
[3, 0]] | |
def show_normalized_grid(normalized, center_x = 0, center_y = 0) | |
# map to 2D array of strings | |
grid = normalized.each_with_object([]) do |pair, result| | |
(result[pair[0]] ||= [])[pair[1]] = ' ' | |
end | |
# set center character | |
grid[center_x][center_y] = '▢' | |
# convert empty elements to spaces | |
grid = grid.map{ |a| a.map{ |b| b.nil? ? '▉' : b } } | |
# convert to string | |
puts grid.map(&:join).join("\n") | |
end | |
# normalize the negatives | |
adjust_x_by = coords.min{ |a, b| a[0] <=> b[0] }[0] * -1 | |
adjust_y_by = coords.min{ |a, b| a[1] <=> b[1] }[1] * -1 | |
normalized = coords.map{ |pair| [pair[0] + adjust_x_by, pair[1] + adjust_y_by] } | |
puts '------' | |
show_normalized_grid( | |
normalized, | |
adjust_x_by, # because of 0,0 moving | |
adjust_y_by) # because of 0,0 moving | |
puts '------' | |
show_normalized_grid( | |
pre_normalized_coords, | |
adjust_x_by, # because 0,0 isn't actually at 0,0 | |
adjust_y_by) # because 0,0 isn't actually at 0,0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
output:

▉ = wall
▢ = origin
░ = walkable