diff options
Diffstat (limited to 'samples/13_path_finding_algorithms')
15 files changed, 4077 insertions, 713 deletions
diff --git a/samples/13_path_finding_algorithms/01_breadth_first_search/app/main.rb b/samples/13_path_finding_algorithms/01_breadth_first_search/app/main.rb index 7f98509..8b84f1c 100644 --- a/samples/13_path_finding_algorithms/01_breadth_first_search/app/main.rb +++ b/samples/13_path_finding_algorithms/01_breadth_first_search/app/main.rb @@ -35,19 +35,19 @@ class BreadthFirstSearch # Stores which step of the animation is being rendered # When the user moves the star or messes with the walls, # the breadth first search is recalculated up to this step - args.state.anim_steps = 0 + args.state.anim_steps = 0 # At some step the animation will end, # and further steps won't change anything (the whole grid will be explored) # This step is roughly the grid's width * height # When anim_steps equals max_steps no more calculations will occur # and the slider will be at the end - args.state.max_steps = args.state.grid.width * args.state.grid.height + args.state.max_steps = args.state.grid.width * args.state.grid.height # Whether the animation should play or not # If true, every tick moves anim_steps forward one # Pressing the stepwise animation buttons will pause the animation - args.state.play = true + args.state.play = true # The location of the star and walls of the grid # They can be modified to have a different initial grid @@ -116,7 +116,7 @@ class BreadthFirstSearch [24, 9] => true, [25, 8] => true, [25, 9] => true, - } + } # Variables that are used by the breadth first search # Storing cells that the search has visited, prevents unnecessary steps @@ -132,7 +132,7 @@ class BreadthFirstSearch # We store this value, because we want to remember the value even when # the user's cursor is no longer over what they're interacting with, but # they are still clicking down on the mouse. - args.state.click_and_drag = :none + args.state.click_and_drag = :none # Store the rects of the buttons that control the animation # They are here for user customization @@ -166,13 +166,13 @@ class BreadthFirstSearch # User input is processed, and # The next step in the search is calculated def tick - render - input + render + input # If animation is playing, and max steps have not been reached # Move the search a step forward if state.play && state.anim_steps < state.max_steps # Variable that tells the program what step to recalculate up to - state.anim_steps += 1 + state.anim_steps += 1 calc end end @@ -182,8 +182,8 @@ class BreadthFirstSearch render_buttons render_slider - render_background - render_visited + render_background + render_visited render_frontier render_walls render_star @@ -260,8 +260,8 @@ class BreadthFirstSearch # Draws what the grid looks like with nothing on it def render_background - render_unvisited - render_grid_lines + render_unvisited + render_grid_lines end # Draws a rectangle the size of the entire grid to represent unvisited cells @@ -276,7 +276,7 @@ class BreadthFirstSearch end for y in 0..grid.height - outputs.lines << horizontal_line(y) + outputs.lines << horizontal_line(y) end end @@ -294,28 +294,28 @@ class BreadthFirstSearch # The frontier is the most outward parts of the search def render_frontier outputs.solids << state.frontier.map do |cell| - [scale_up(cell), frontier_color] + [scale_up([cell.x, cell.y]), frontier_color] end end # Draws the walls def render_walls outputs.solids << state.walls.map do |wall| - [scale_up(wall), wall_color] + [scale_up([wall.x, wall.y]), wall_color] end end # Renders cells that have been searched in the appropriate color def render_visited outputs.solids << state.visited.map do |cell| - [scale_up(cell), visited_color] + [scale_up([cell.x, cell.y]), visited_color] end end # Renders the star def render_star outputs.sprites << [scale_up(state.star), 'star.png'] - end + end # In code, the cells are represented as 1x1 rectangles # When drawn, the cells are larger than 1x1 rectangles @@ -369,20 +369,20 @@ class BreadthFirstSearch # The detection and processing of click and drag inputs are separate # The program has to remember that the user is dragging an object # even when the mouse is no longer over that object - detect_click_and_drag - process_click_and_drag + detect_click_and_drag + process_click_and_drag end # Detects and Process input for each button def input_buttons - input_left_button - input_center_button - input_next_step_button + input_left_button + input_center_button + input_next_step_button end # Checks if the previous step button is clicked # If it is, it pauses the animation and moves the search one step backward - def input_left_button + def input_left_button if left_button_clicked? state.play = false state.anim_steps -= 1 @@ -394,7 +394,7 @@ class BreadthFirstSearch # Inverses whether the animation is playing or not when clicked def input_center_button if center_button_clicked? or inputs.keyboard.key_down.space - state.play = !state.play + state.play = !state.play end end @@ -402,8 +402,8 @@ class BreadthFirstSearch # If it is, it pauses the animation and moves the search one step forward def input_next_step_button if right_button_clicked? - state.play = false - state.anim_steps += 1 + state.play = false + state.anim_steps += 1 calc end end @@ -412,29 +412,29 @@ class BreadthFirstSearch # Storing the value allows the user to continue the same edit as long as the # mouse left click is held def detect_click_and_drag - if inputs.mouse.up - state.click_and_drag = :none - elsif star_clicked? - state.click_and_drag = :star - elsif wall_clicked? - state.click_and_drag = :remove_wall - elsif grid_clicked? - state.click_and_drag = :add_wall - elsif slider_clicked? - state.click_and_drag = :slider + if inputs.mouse.up + state.click_and_drag = :none + elsif star_clicked? + state.click_and_drag = :star + elsif wall_clicked? + state.click_and_drag = :remove_wall + elsif grid_clicked? + state.click_and_drag = :add_wall + elsif slider_clicked? + state.click_and_drag = :slider end end # Processes click and drag based on what the user is currently dragging def process_click_and_drag - if state.click_and_drag == :star - input_star - elsif state.click_and_drag == :remove_wall - input_remove_wall - elsif state.click_and_drag == :add_wall - input_add_wall - elsif state.click_and_drag == :slider - input_slider + if state.click_and_drag == :star + input_star + elsif state.click_and_drag == :remove_wall + input_remove_wall + elsif state.click_and_drag == :add_wall + input_add_wall + elsif state.click_and_drag == :slider + input_slider end end @@ -442,10 +442,10 @@ class BreadthFirstSearch # Only recalculates the search if the star changes position # Called whenever the user is editing the star (puts mouse down on star) def input_star - old_star = state.star.clone + old_star = state.star.clone state.star = cell_closest_to_mouse - unless old_star == state.star - recalculate + unless old_star == state.star + recalculate end end @@ -454,20 +454,20 @@ class BreadthFirstSearch # The mouse needs to be inside the grid, because we only want to remove walls # the cursor is directly over # Recalculations should only occur when a wall is actually deleted - if mouse_inside_grid? + if mouse_inside_grid? if state.walls.has_key?(cell_closest_to_mouse) - state.walls.delete(cell_closest_to_mouse) - recalculate + state.walls.delete(cell_closest_to_mouse) + recalculate end end end # Adds walls at cells under the cursor def input_add_wall - if mouse_inside_grid? + if mouse_inside_grid? unless state.walls.has_key?(cell_closest_to_mouse) - state.walls[cell_closest_to_mouse] = true - recalculate + state.walls[cell_closest_to_mouse] = true + recalculate end end end @@ -477,18 +477,18 @@ class BreadthFirstSearch # on the slider # Changes the step of the search to be animated def input_slider - state.play = false + state.play = false mouse_x = inputs.mouse.point.x # Bounds the mouse_x to the closest x value on the slider line - mouse_x = slider.x if mouse_x < slider.x - mouse_x = slider.x + slider.w if mouse_x > slider.x + slider.w + mouse_x = slider.x if mouse_x < slider.x + mouse_x = slider.x + slider.w if mouse_x > slider.x + slider.w # Sets the current search step to the one represented by the mouse x value # The slider's circle moves due to the render_slider method using anim_steps state.anim_steps = ((mouse_x - slider.x) / slider.spacing).to_i - recalculate + recalculate end # Whenever the user edits the grid, @@ -496,11 +496,11 @@ class BreadthFirstSearch # with the current grid as the initial state of the grid def recalculate # Resets the search - state.frontier = [] - state.visited = {} + state.frontier = [] + state.visited = {} # Moves the animation forward one step at a time - state.anim_steps.times { calc } + state.anim_steps.times { calc } end @@ -515,39 +515,39 @@ class BreadthFirstSearch # The setup to the search # Runs once when the there is no frontier or visited cells - if state.frontier.empty? && state.visited.empty? - state.frontier << state.star - state.visited[state.star] = true + if state.frontier.empty? && state.visited.empty? + state.frontier << state.star + state.visited[state.star] = true end # A step in the search - unless state.frontier.empty? + unless state.frontier.empty? # Takes the next frontier cell - new_frontier = state.frontier.shift + new_frontier = state.frontier.shift # For each of its neighbors - adjacent_neighbors(new_frontier).each do |neighbor| + adjacent_neighbors(new_frontier).each do |neighbor| # That have not been visited and are not walls - unless state.visited.has_key?(neighbor) || state.walls.has_key?(neighbor) + unless state.visited.has_key?(neighbor) || state.walls.has_key?(neighbor) # Add them to the frontier and mark them as visited - state.frontier << neighbor - state.visited[neighbor] = true + state.frontier << neighbor + state.visited[neighbor] = true end end end end - + # Returns a list of adjacent cells # Used to determine what the next cells to be added to the frontier are def adjacent_neighbors(cell) - neighbors = [] + neighbors = [] - neighbors << [cell.x, cell.y + 1] unless cell.y == grid.height - 1 - neighbors << [cell.x + 1, cell.y] unless cell.x == grid.width - 1 - neighbors << [cell.x, cell.y - 1] unless cell.y == 0 - neighbors << [cell.x - 1, cell.y] unless cell.x == 0 + neighbors << [cell.x, cell.y + 1] unless cell.y == grid.height - 1 + neighbors << [cell.x + 1, cell.y] unless cell.x == grid.width - 1 + neighbors << [cell.x, cell.y - 1] unless cell.y == 0 + neighbors << [cell.x - 1, cell.y] unless cell.x == 0 - neighbors + neighbors end # When the user grabs the star and puts their cursor to the far right @@ -555,13 +555,13 @@ class BreadthFirstSearch # Finding the cell closest to the mouse helps with this def cell_closest_to_mouse # Closest cell to the mouse - x = (inputs.mouse.point.x / grid.cell_size).to_i - y = (inputs.mouse.point.y / grid.cell_size).to_i + x = (inputs.mouse.point.x / grid.cell_size).to_i + y = (inputs.mouse.point.y / grid.cell_size).to_i # Bound x and y to the grid - x = grid.width - 1 if x > grid.width - 1 - y = grid.height - 1 if y > grid.height - 1 + x = grid.width - 1 if x > grid.width - 1 + y = grid.height - 1 if y > grid.height - 1 # Return closest cell - [x, y] + [x, y] end # These methods detect when the buttons are clicked @@ -605,7 +605,7 @@ class BreadthFirstSearch # Part of the condition that checks whether the user is removing a wall def mouse_inside_a_wall? state.walls.each_key do | wall | - return true if inputs.mouse.point.inside_rect?(scale_up(wall)) + return true if inputs.mouse.point.inside_rect?(scale_up([wall.x, wall.y])) end false @@ -622,27 +622,27 @@ class BreadthFirstSearch # Light brown def unvisited_color - [221, 212, 213] + [221, 212, 213] end # Black def grid_line_color - [255, 255, 255] + [255, 255, 255] end # Dark Brown def visited_color - [204, 191, 179] + [204, 191, 179] end # Blue def frontier_color - [103, 136, 204] + [103, 136, 204] end # Camo Green def wall_color - [134, 134, 120] + [134, 134, 120] end # Button Background diff --git a/samples/13_path_finding_algorithms/01_breadth_first_search/replay.txt b/samples/13_path_finding_algorithms/01_breadth_first_search/replay.txt new file mode 100644 index 0000000..62f4aca --- /dev/null +++ b/samples/13_path_finding_algorithms/01_breadth_first_search/replay.txt @@ -0,0 +1,203 @@ +replay_version 2.0 +stopped_at 213 +seed 100 +recorded_at 2021-11-20 11:17:21 -0600 +[:mouse_button_up, 1, 0, 1, 1, 4] +[:mouse_move, 780, 95, 2, 2, 11] +[:mouse_move, 781, 95, 2, 3, 12] +[:mouse_move, 782, 95, 2, 4, 13] +[:mouse_move, 783, 95, 2, 5, 14] +[:mouse_move, 771, 95, 2, 6, 32] +[:mouse_move, 752, 95, 2, 7, 32] +[:mouse_move, 718, 95, 2, 8, 34] +[:mouse_move, 652, 95, 2, 9, 34] +[:mouse_move, 549, 95, 2, 10, 35] +[:mouse_move, 462, 101, 2, 11, 36] +[:mouse_move, 425, 106, 2, 12, 37] +[:mouse_move, 405, 108, 2, 13, 38] +[:mouse_move, 406, 109, 2, 14, 39] +[:mouse_move, 412, 111, 2, 15, 40] +[:mouse_move, 429, 111, 2, 16, 41] +[:mouse_move, 450, 109, 2, 17, 42] +[:mouse_move, 460, 107, 2, 18, 42] +[:mouse_move, 460, 106, 2, 19, 43] +[:mouse_move, 460, 105, 2, 20, 45] +[:mouse_move, 460, 104, 2, 21, 46] +[:mouse_move, 456, 104, 2, 22, 47] +[:mouse_move, 469, 104, 2, 23, 49] +[:mouse_move, 489, 103, 2, 24, 50] +[:mouse_move, 512, 100, 2, 25, 51] +[:mouse_move, 536, 96, 2, 26, 52] +[:mouse_move, 565, 92, 2, 27, 52] +[:mouse_move, 587, 92, 2, 28, 53] +[:mouse_move, 597, 92, 2, 29, 54] +[:mouse_move, 599, 92, 2, 30, 55] +[:mouse_button_pressed, 1, 0, 1, 31, 59] +[:mouse_button_up, 1, 0, 1, 32, 62] +[:mouse_move, 599, 91, 2, 33, 65] +[:mouse_move, 590, 86, 2, 34, 65] +[:mouse_move, 570, 78, 2, 35, 66] +[:mouse_move, 543, 70, 2, 36, 66] +[:mouse_move, 516, 65, 2, 37, 67] +[:mouse_move, 481, 61, 2, 38, 68] +[:mouse_move, 449, 59, 2, 39, 69] +[:mouse_move, 429, 57, 2, 40, 69] +[:mouse_move, 424, 56, 2, 41, 70] +[:mouse_move, 426, 56, 2, 42, 74] +[:mouse_move, 429, 56, 2, 43, 75] +[:mouse_move, 431, 56, 2, 44, 75] +[:mouse_move, 433, 56, 2, 45, 76] +[:mouse_move, 435, 55, 2, 46, 77] +[:mouse_move, 437, 55, 2, 47, 78] +[:mouse_move, 440, 55, 2, 48, 78] +[:mouse_move, 444, 55, 2, 49, 79] +[:mouse_move, 445, 54, 2, 50, 79] +[:mouse_move, 444, 53, 2, 51, 81] +[:mouse_move, 444, 52, 2, 52, 82] +[:mouse_move, 443, 51, 2, 53, 89] +[:mouse_button_pressed, 1, 0, 1, 54, 89] +[:mouse_move, 442, 51, 2, 55, 89] +[:mouse_move, 436, 51, 2, 56, 90] +[:mouse_move, 432, 49, 2, 57, 91] +[:mouse_move, 431, 49, 2, 58, 91] +[:mouse_move, 429, 49, 2, 59, 92] +[:mouse_move, 428, 49, 2, 60, 93] +[:mouse_move, 426, 49, 2, 61, 94] +[:mouse_move, 425, 49, 2, 62, 94] +[:mouse_move, 424, 49, 2, 63, 95] +[:mouse_move, 423, 49, 2, 64, 96] +[:mouse_move, 422, 49, 2, 65, 98] +[:mouse_move, 421, 49, 2, 66, 99] +[:mouse_move, 420, 49, 2, 67, 99] +[:mouse_move, 419, 49, 2, 68, 100] +[:mouse_move, 417, 49, 2, 69, 100] +[:mouse_move, 415, 49, 2, 70, 101] +[:mouse_move, 414, 49, 2, 71, 102] +[:mouse_move, 413, 49, 2, 72, 108] +[:mouse_move, 415, 49, 2, 73, 124] +[:mouse_move, 416, 49, 2, 74, 125] +[:mouse_move, 420, 49, 2, 75, 126] +[:mouse_move, 424, 49, 2, 76, 127] +[:mouse_move, 429, 49, 2, 77, 128] +[:mouse_move, 433, 49, 2, 78, 128] +[:mouse_move, 441, 49, 2, 79, 129] +[:mouse_move, 450, 49, 2, 80, 129] +[:mouse_move, 460, 49, 2, 81, 130] +[:mouse_move, 472, 49, 2, 82, 131] +[:mouse_move, 480, 49, 2, 83, 131] +[:mouse_move, 486, 49, 2, 84, 132] +[:mouse_move, 488, 49, 2, 85, 132] +[:mouse_move, 492, 49, 2, 86, 132] +[:mouse_move, 498, 49, 2, 87, 133] +[:mouse_move, 507, 49, 2, 88, 133] +[:mouse_move, 513, 48, 2, 89, 134] +[:mouse_move, 518, 47, 2, 90, 134] +[:mouse_move, 523, 47, 2, 91, 134] +[:mouse_move, 529, 46, 2, 92, 135] +[:mouse_move, 533, 46, 2, 93, 135] +[:mouse_move, 538, 46, 2, 94, 135] +[:mouse_move, 543, 46, 2, 95, 136] +[:mouse_move, 545, 46, 2, 96, 136] +[:mouse_move, 546, 46, 2, 97, 136] +[:mouse_move, 551, 46, 2, 98, 137] +[:mouse_move, 558, 46, 2, 99, 137] +[:mouse_move, 567, 46, 2, 100, 138] +[:mouse_move, 573, 46, 2, 101, 138] +[:mouse_move, 576, 45, 2, 102, 138] +[:mouse_move, 579, 45, 2, 103, 138] +[:mouse_move, 581, 45, 2, 104, 138] +[:mouse_move, 584, 45, 2, 105, 139] +[:mouse_move, 590, 45, 2, 106, 139] +[:mouse_move, 597, 45, 2, 107, 139] +[:mouse_move, 602, 45, 2, 108, 140] +[:mouse_move, 606, 45, 2, 109, 140] +[:mouse_move, 611, 45, 2, 110, 140] +[:mouse_move, 617, 45, 2, 111, 140] +[:mouse_move, 625, 45, 2, 112, 140] +[:mouse_move, 632, 45, 2, 113, 140] +[:mouse_move, 638, 45, 2, 114, 141] +[:mouse_move, 643, 45, 2, 115, 141] +[:mouse_move, 644, 44, 2, 116, 141] +[:mouse_move, 646, 44, 2, 117, 141] +[:mouse_move, 647, 44, 2, 118, 142] +[:mouse_move, 650, 44, 2, 119, 142] +[:mouse_move, 653, 44, 2, 120, 142] +[:mouse_move, 656, 44, 2, 121, 142] +[:mouse_move, 658, 43, 2, 122, 142] +[:mouse_move, 659, 43, 2, 123, 143] +[:mouse_move, 663, 43, 2, 124, 143] +[:mouse_move, 665, 43, 2, 125, 143] +[:mouse_move, 667, 43, 2, 126, 143] +[:mouse_move, 669, 43, 2, 127, 143] +[:mouse_move, 670, 43, 2, 128, 143] +[:mouse_move, 671, 43, 2, 129, 143] +[:mouse_move, 672, 43, 2, 130, 144] +[:mouse_move, 674, 43, 2, 131, 144] +[:mouse_move, 677, 43, 2, 132, 144] +[:mouse_move, 679, 43, 2, 133, 144] +[:mouse_move, 680, 43, 2, 134, 144] +[:mouse_move, 681, 43, 2, 135, 144] +[:mouse_move, 683, 43, 2, 136, 145] +[:mouse_move, 684, 43, 2, 137, 145] +[:mouse_move, 685, 43, 2, 138, 145] +[:mouse_move, 686, 43, 2, 139, 145] +[:mouse_move, 687, 43, 2, 140, 145] +[:mouse_move, 688, 43, 2, 141, 146] +[:mouse_button_up, 1, 0, 1, 142, 150] +[:mouse_move, 688, 44, 2, 143, 150] +[:mouse_move, 685, 45, 2, 144, 150] +[:mouse_move, 674, 47, 2, 145, 150] +[:mouse_move, 657, 52, 2, 146, 150] +[:mouse_move, 621, 57, 2, 147, 151] +[:mouse_move, 593, 62, 2, 148, 151] +[:mouse_move, 568, 65, 2, 149, 151] +[:mouse_move, 550, 68, 2, 150, 151] +[:mouse_move, 542, 69, 2, 151, 152] +[:mouse_move, 539, 69, 2, 152, 152] +[:mouse_move, 536, 70, 2, 153, 152] +[:mouse_move, 534, 70, 2, 154, 153] +[:mouse_move, 531, 72, 2, 155, 153] +[:mouse_move, 528, 73, 2, 156, 153] +[:mouse_move, 522, 75, 2, 157, 154] +[:mouse_move, 515, 80, 2, 158, 154] +[:mouse_move, 514, 81, 2, 159, 154] +[:mouse_move, 513, 81, 2, 160, 154] +[:mouse_move, 509, 84, 2, 161, 156] +[:mouse_move, 502, 88, 2, 162, 156] +[:mouse_move, 491, 93, 2, 163, 156] +[:mouse_move, 487, 97, 2, 164, 156] +[:mouse_move, 486, 97, 2, 165, 156] +[:mouse_move, 487, 96, 2, 166, 157] +[:mouse_button_pressed, 1, 0, 1, 167, 159] +[:mouse_button_up, 1, 0, 1, 168, 160] +[:mouse_button_pressed, 1, 0, 1, 169, 161] +[:mouse_move, 488, 96, 2, 170, 161] +[:mouse_button_up, 1, 0, 1, 171, 161] +[:mouse_move, 488, 97, 2, 172, 166] +[:mouse_move, 487, 97, 2, 173, 166] +[:mouse_move, 486, 97, 2, 174, 167] +[:mouse_move, 485, 97, 2, 175, 167] +[:mouse_move, 484, 97, 2, 176, 168] +[:mouse_button_pressed, 1, 0, 1, 177, 172] +[:mouse_button_up, 1, 0, 1, 178, 173] +[:mouse_move, 485, 97, 2, 179, 185] +[:key_down_raw, 96, 0, 2, 180, 191] +[:mouse_move, 486, 96, 2, 181, 192] +[:mouse_move, 488, 96, 2, 182, 192] +[:mouse_move, 495, 94, 2, 183, 192] +[:key_up_raw, 96, 0, 2, 184, 192] +[:mouse_move, 503, 93, 2, 185, 193] +[:mouse_move, 514, 92, 2, 186, 193] +[:mouse_move, 544, 92, 2, 187, 193] +[:mouse_move, 573, 92, 2, 188, 194] +[:mouse_move, 607, 92, 2, 189, 194] +[:mouse_move, 641, 89, 2, 190, 194] +[:mouse_move, 674, 89, 2, 191, 194] +[:mouse_move, 705, 89, 2, 192, 194] +[:mouse_move, 735, 89, 2, 193, 195] +[:mouse_move, 759, 89, 2, 194, 195] +[:mouse_move, 776, 89, 2, 195, 195] +[:mouse_move, 784, 89, 2, 196, 195] +[:mouse_move, 786, 89, 2, 197, 196] +[:mouse_move, 786, 90, 2, 198, 204] +[:key_down_raw, 13, 0, 2, 199, 213] diff --git a/samples/13_path_finding_algorithms/02_detailed_breadth_first_search/replay.txt b/samples/13_path_finding_algorithms/02_detailed_breadth_first_search/replay.txt new file mode 100644 index 0000000..aa8719b --- /dev/null +++ b/samples/13_path_finding_algorithms/02_detailed_breadth_first_search/replay.txt @@ -0,0 +1,241 @@ +replay_version 2.0 +stopped_at 435 +seed 100 +recorded_at 2021-11-20 11:18:03 -0600 +[:mouse_button_up, 1, 0, 1, 1, 4] +[:mouse_move, 789, 89, 2, 2, 27] +[:mouse_move, 785, 90, 2, 3, 28] +[:mouse_move, 768, 94, 2, 4, 29] +[:mouse_move, 752, 99, 2, 5, 30] +[:mouse_move, 737, 104, 2, 6, 31] +[:mouse_move, 729, 104, 2, 7, 32] +[:mouse_move, 724, 104, 2, 8, 33] +[:mouse_move, 720, 103, 2, 9, 34] +[:mouse_move, 711, 103, 2, 10, 35] +[:mouse_move, 702, 103, 2, 11, 36] +[:mouse_move, 698, 103, 2, 12, 37] +[:mouse_move, 697, 103, 2, 13, 38] +[:mouse_move, 696, 103, 2, 14, 40] +[:mouse_move, 694, 104, 2, 15, 41] +[:mouse_move, 684, 104, 2, 16, 42] +[:mouse_move, 666, 104, 2, 17, 43] +[:mouse_move, 645, 105, 2, 18, 44] +[:mouse_move, 626, 106, 2, 19, 45] +[:mouse_move, 615, 106, 2, 20, 46] +[:mouse_move, 609, 106, 2, 21, 47] +[:mouse_move, 606, 106, 2, 22, 48] +[:mouse_move, 605, 106, 2, 23, 49] +[:mouse_move, 600, 104, 2, 24, 50] +[:mouse_move, 590, 100, 2, 25, 51] +[:mouse_move, 579, 97, 2, 26, 52] +[:mouse_move, 575, 96, 2, 27, 53] +[:mouse_move, 581, 96, 2, 28, 58] +[:mouse_move, 596, 98, 2, 29, 59] +[:mouse_move, 614, 98, 2, 30, 60] +[:mouse_move, 635, 97, 2, 31, 61] +[:mouse_move, 652, 94, 2, 32, 62] +[:mouse_move, 657, 93, 2, 33, 63] +[:mouse_move, 658, 92, 2, 34, 64] +[:mouse_button_pressed, 1, 0, 1, 35, 70] +[:mouse_move, 659, 92, 2, 36, 70] +[:mouse_button_up, 1, 0, 1, 37, 74] +[:mouse_move, 660, 92, 2, 38, 87] +[:mouse_button_pressed, 1, 0, 1, 39, 92] +[:mouse_button_up, 1, 0, 1, 40, 98] +[:mouse_move, 661, 92, 2, 41, 101] +[:mouse_button_pressed, 1, 0, 1, 42, 103] +[:mouse_button_up, 1, 0, 1, 43, 108] +[:mouse_move, 662, 92, 2, 44, 112] +[:mouse_button_pressed, 1, 0, 1, 45, 113] +[:mouse_button_up, 1, 0, 1, 46, 119] +[:mouse_move, 657, 92, 2, 47, 125] +[:mouse_move, 641, 92, 2, 48, 126] +[:mouse_move, 623, 93, 2, 49, 127] +[:mouse_move, 610, 95, 2, 50, 128] +[:mouse_move, 599, 97, 2, 51, 129] +[:mouse_move, 588, 98, 2, 52, 130] +[:mouse_move, 584, 99, 2, 53, 131] +[:mouse_move, 581, 99, 2, 54, 132] +[:mouse_move, 580, 99, 2, 55, 133] +[:mouse_move, 575, 99, 2, 56, 134] +[:mouse_move, 572, 99, 2, 57, 135] +[:mouse_move, 570, 99, 2, 58, 136] +[:mouse_move, 564, 101, 2, 59, 137] +[:mouse_move, 559, 101, 2, 60, 138] +[:mouse_move, 557, 101, 2, 61, 139] +[:mouse_move, 555, 102, 2, 62, 140] +[:mouse_move, 554, 102, 2, 63, 141] +[:mouse_button_pressed, 1, 0, 1, 64, 145] +[:mouse_button_up, 1, 0, 1, 65, 149] +[:mouse_button_pressed, 1, 0, 1, 66, 154] +[:mouse_move, 555, 102, 2, 67, 154] +[:mouse_button_up, 1, 0, 1, 68, 159] +[:mouse_button_pressed, 1, 0, 1, 69, 163] +[:mouse_button_up, 1, 0, 1, 70, 168] +[:mouse_move, 555, 103, 2, 71, 168] +[:mouse_move, 539, 103, 2, 72, 169] +[:mouse_move, 519, 100, 2, 73, 170] +[:mouse_move, 498, 95, 2, 74, 171] +[:mouse_move, 488, 90, 2, 75, 172] +[:mouse_move, 484, 88, 2, 76, 173] +[:mouse_move, 475, 81, 2, 77, 174] +[:mouse_move, 460, 73, 2, 78, 175] +[:mouse_move, 441, 64, 2, 79, 176] +[:mouse_move, 424, 57, 2, 80, 177] +[:mouse_move, 413, 53, 2, 81, 178] +[:mouse_move, 408, 50, 2, 82, 179] +[:mouse_move, 407, 49, 2, 83, 182] +[:mouse_move, 405, 47, 2, 84, 183] +[:mouse_move, 404, 46, 2, 85, 184] +[:mouse_move, 404, 45, 2, 86, 185] +[:mouse_move, 403, 45, 2, 87, 186] +[:mouse_button_pressed, 1, 0, 1, 88, 195] +[:mouse_move, 406, 45, 2, 89, 197] +[:mouse_move, 413, 45, 2, 90, 198] +[:mouse_move, 423, 45, 2, 91, 199] +[:mouse_move, 434, 45, 2, 92, 200] +[:mouse_move, 446, 45, 2, 93, 201] +[:mouse_move, 461, 45, 2, 94, 202] +[:mouse_move, 472, 45, 2, 95, 203] +[:mouse_move, 480, 45, 2, 96, 204] +[:mouse_move, 486, 45, 2, 97, 205] +[:mouse_move, 492, 45, 2, 98, 206] +[:mouse_move, 495, 45, 2, 99, 207] +[:mouse_move, 496, 45, 2, 100, 208] +[:mouse_move, 497, 45, 2, 101, 209] +[:mouse_move, 498, 45, 2, 102, 210] +[:mouse_move, 501, 45, 2, 103, 211] +[:mouse_move, 507, 45, 2, 104, 212] +[:mouse_move, 512, 45, 2, 105, 213] +[:mouse_move, 516, 45, 2, 106, 214] +[:mouse_move, 518, 45, 2, 107, 215] +[:mouse_move, 519, 45, 2, 108, 216] +[:mouse_move, 520, 45, 2, 109, 217] +[:mouse_move, 522, 45, 2, 110, 218] +[:mouse_move, 525, 45, 2, 111, 219] +[:mouse_move, 533, 45, 2, 112, 220] +[:mouse_move, 537, 45, 2, 113, 221] +[:mouse_move, 541, 45, 2, 114, 222] +[:mouse_move, 545, 45, 2, 115, 223] +[:mouse_move, 546, 45, 2, 116, 224] +[:mouse_move, 547, 45, 2, 117, 226] +[:mouse_move, 549, 45, 2, 118, 227] +[:mouse_move, 554, 45, 2, 119, 228] +[:mouse_move, 556, 45, 2, 120, 229] +[:mouse_move, 560, 45, 2, 121, 230] +[:mouse_move, 566, 45, 2, 122, 231] +[:mouse_move, 570, 45, 2, 123, 232] +[:mouse_move, 577, 45, 2, 124, 233] +[:mouse_move, 585, 45, 2, 125, 234] +[:mouse_move, 593, 46, 2, 126, 235] +[:mouse_move, 602, 48, 2, 127, 236] +[:mouse_move, 609, 48, 2, 128, 237] +[:mouse_move, 614, 48, 2, 129, 238] +[:mouse_move, 619, 48, 2, 130, 239] +[:mouse_move, 625, 49, 2, 131, 240] +[:mouse_move, 633, 49, 2, 132, 241] +[:mouse_move, 643, 49, 2, 133, 242] +[:mouse_move, 651, 49, 2, 134, 243] +[:mouse_move, 658, 49, 2, 135, 243] +[:mouse_move, 664, 49, 2, 136, 244] +[:mouse_move, 669, 49, 2, 137, 245] +[:mouse_move, 675, 49, 2, 138, 246] +[:mouse_move, 679, 49, 2, 139, 247] +[:mouse_move, 682, 49, 2, 140, 248] +[:mouse_move, 686, 49, 2, 141, 249] +[:mouse_move, 689, 49, 2, 142, 250] +[:mouse_move, 691, 49, 2, 143, 251] +[:mouse_move, 697, 49, 2, 144, 252] +[:mouse_move, 706, 49, 2, 145, 253] +[:mouse_move, 715, 49, 2, 146, 254] +[:mouse_move, 723, 49, 2, 147, 255] +[:mouse_move, 730, 49, 2, 148, 256] +[:mouse_move, 733, 49, 2, 149, 256] +[:mouse_move, 734, 49, 2, 150, 257] +[:mouse_move, 737, 49, 2, 151, 258] +[:mouse_move, 742, 49, 2, 152, 259] +[:mouse_move, 749, 49, 2, 153, 260] +[:mouse_move, 755, 49, 2, 154, 261] +[:mouse_move, 758, 49, 2, 155, 262] +[:mouse_move, 760, 49, 2, 156, 263] +[:mouse_move, 761, 49, 2, 157, 264] +[:mouse_move, 762, 49, 2, 158, 266] +[:mouse_move, 763, 49, 2, 159, 268] +[:mouse_move, 763, 48, 2, 160, 269] +[:mouse_move, 757, 48, 2, 161, 290] +[:mouse_move, 746, 48, 2, 162, 291] +[:mouse_move, 732, 48, 2, 163, 291] +[:mouse_move, 716, 48, 2, 164, 292] +[:mouse_move, 698, 48, 2, 165, 293] +[:mouse_move, 684, 47, 2, 166, 294] +[:mouse_move, 673, 46, 2, 167, 295] +[:mouse_move, 665, 44, 2, 168, 296] +[:mouse_move, 660, 44, 2, 169, 297] +[:mouse_move, 656, 44, 2, 170, 297] +[:mouse_move, 652, 44, 2, 171, 298] +[:mouse_move, 648, 44, 2, 172, 299] +[:mouse_move, 637, 44, 2, 173, 300] +[:mouse_move, 628, 44, 2, 174, 301] +[:mouse_move, 618, 44, 2, 175, 302] +[:mouse_move, 609, 44, 2, 176, 303] +[:mouse_move, 602, 44, 2, 177, 304] +[:mouse_move, 598, 43, 2, 178, 305] +[:mouse_move, 596, 43, 2, 179, 306] +[:mouse_move, 595, 43, 2, 180, 307] +[:mouse_move, 594, 42, 2, 181, 308] +[:mouse_move, 593, 42, 2, 182, 308] +[:mouse_move, 591, 42, 2, 183, 309] +[:mouse_move, 588, 42, 2, 184, 310] +[:mouse_move, 586, 42, 2, 185, 311] +[:mouse_move, 584, 42, 2, 186, 312] +[:mouse_move, 582, 42, 2, 187, 313] +[:mouse_move, 576, 42, 2, 188, 314] +[:mouse_move, 570, 42, 2, 189, 315] +[:mouse_move, 562, 42, 2, 190, 316] +[:mouse_move, 554, 42, 2, 191, 317] +[:mouse_move, 547, 42, 2, 192, 318] +[:mouse_move, 537, 42, 2, 193, 319] +[:mouse_move, 532, 42, 2, 194, 320] +[:mouse_move, 528, 42, 2, 195, 321] +[:mouse_move, 527, 42, 2, 196, 322] +[:mouse_move, 526, 42, 2, 197, 323] +[:mouse_move, 525, 42, 2, 198, 324] +[:mouse_move, 524, 42, 2, 199, 325] +[:mouse_move, 522, 42, 2, 200, 326] +[:mouse_move, 521, 42, 2, 201, 327] +[:mouse_move, 520, 42, 2, 202, 328] +[:mouse_move, 519, 42, 2, 203, 329] +[:mouse_move, 516, 42, 2, 204, 330] +[:mouse_move, 513, 42, 2, 205, 331] +[:mouse_move, 512, 42, 2, 206, 332] +[:mouse_move, 509, 42, 2, 207, 333] +[:mouse_move, 497, 42, 2, 208, 334] +[:mouse_move, 490, 42, 2, 209, 335] +[:mouse_move, 486, 42, 2, 210, 336] +[:mouse_move, 483, 42, 2, 211, 337] +[:mouse_move, 482, 42, 2, 212, 338] +[:mouse_move, 481, 42, 2, 213, 339] +[:mouse_button_up, 1, 0, 1, 214, 354] +[:mouse_move, 484, 43, 2, 215, 361] +[:mouse_move, 497, 47, 2, 216, 362] +[:mouse_move, 513, 51, 2, 217, 363] +[:mouse_move, 530, 55, 2, 218, 364] +[:mouse_move, 544, 58, 2, 219, 365] +[:mouse_move, 562, 63, 2, 220, 366] +[:mouse_move, 589, 71, 2, 221, 367] +[:mouse_move, 623, 81, 2, 222, 368] +[:mouse_move, 656, 91, 2, 223, 369] +[:mouse_move, 687, 95, 2, 224, 370] +[:mouse_move, 731, 102, 2, 225, 371] +[:mouse_move, 762, 110, 2, 226, 372] +[:mouse_move, 792, 117, 2, 227, 373] +[:mouse_move, 819, 123, 2, 228, 374] +[:key_down_raw, 96, 0, 2, 229, 375] +[:mouse_move, 842, 125, 2, 230, 375] +[:mouse_move, 859, 128, 2, 231, 376] +[:mouse_move, 871, 130, 2, 232, 377] +[:mouse_move, 878, 131, 2, 233, 378] +[:mouse_move, 879, 131, 2, 234, 379] +[:key_up_raw, 96, 0, 2, 235, 379] +[:mouse_move, 878, 131, 2, 236, 411] +[:key_down_raw, 13, 0, 2, 237, 435] diff --git a/samples/13_path_finding_algorithms/03_breadcrumbs/app/main.rb b/samples/13_path_finding_algorithms/03_breadcrumbs/app/main.rb index 648805a..533a962 100644 --- a/samples/13_path_finding_algorithms/03_breadcrumbs/app/main.rb +++ b/samples/13_path_finding_algorithms/03_breadcrumbs/app/main.rb @@ -12,8 +12,8 @@ class Breadcrumbs calc # Calc Path end - render - input + render + input end def defaults @@ -90,7 +90,7 @@ class Breadcrumbs [24, 9] => true, [25, 8] => true, [25, 9] => true, - } + } # Variables that are used by the breadth first search # Storing cells that the search has visited, prevents unnecessary steps @@ -109,36 +109,36 @@ class Breadcrumbs # We store this value, because we want to remember the value even when # the user's cursor is no longer over what they're interacting with, but # they are still clicking down on the mouse. - state.current_input ||= :none + state.current_input ||= :none end def calc # Setup the search to start from the star - search.frontier << grid.star + search.frontier << grid.star search.came_from[grid.star] = nil # Until there are no more cells to expand from - until search.frontier.empty? + until search.frontier.empty? # Takes the next frontier cell - new_frontier = search.frontier.shift + new_frontier = search.frontier.shift # For each of its neighbors - adjacent_neighbors(new_frontier).each do |neighbor| + adjacent_neighbors(new_frontier).each do |neighbor| # That have not been visited and are not walls - unless search.came_from.has_key?(neighbor) || grid.walls.has_key?(neighbor) + unless search.came_from.has_key?(neighbor) || grid.walls.has_key?(neighbor) # Add them to the frontier and mark them as visited in the first grid # Unless the target has been visited # Add the neighbor to the frontier and remember which cell it came from - search.frontier << neighbor + search.frontier << neighbor search.came_from[neighbor] = new_frontier end end end end - + # Draws everything onto the screen def render - render_background + render_background # render_heat_map render_walls # render_path @@ -157,7 +157,7 @@ class Breadcrumbs if current_cell && parent_cell outputs.lines << [(current_cell.x + 0.5) * grid.cell_size, (current_cell.y + 0.5) * grid.cell_size, (parent_cell.x + 0.5) * grid.cell_size, (parent_cell.y + 0.5) * grid.cell_size, purple] - + end render_trail(parent_cell) end @@ -183,8 +183,8 @@ class Breadcrumbs # Draws what the grid looks like with nothing on it def render_background - render_unvisited - render_grid_lines + render_unvisited + render_grid_lines end # Draws both grids @@ -199,7 +199,7 @@ class Breadcrumbs end for y in 0..grid.height - outputs.lines << horizontal_line(y) + outputs.lines << horizontal_line(y) end end @@ -215,7 +215,7 @@ class Breadcrumbs # Draws the walls on both grids def render_walls - grid.walls.each_key do |wall| + grid.walls.each_key do |wall| outputs.solids << [scale_up(wall), wall_color] end end @@ -223,12 +223,12 @@ class Breadcrumbs # Renders the star on both grids def render_star outputs.sprites << [scale_up(grid.star), 'star.png'] - end + end # Renders the target on both grids def render_target outputs.sprites << [scale_up(grid.target), 'target.png'] - end + end # Labels the grids def render_labels @@ -288,14 +288,14 @@ class Breadcrumbs # The program has to remember that the user is dragging an object # even when the mouse is no longer over that object # So detecting input and processing input is separate - # detect_input - # process_input + # detect_input + # process_input if inputs.mouse.up state.current_input = :none elsif star_clicked? state.current_input = :star end - + if mouse_inside_grid? unless grid.target == cell_closest_to_mouse grid.target = cell_closest_to_mouse @@ -313,33 +313,33 @@ class Breadcrumbs # mouse left click is held def detect_input # When the mouse is up, nothing is being edited - if inputs.mouse.up - state.current_input = :none + if inputs.mouse.up + state.current_input = :none # When the star in the no second grid is clicked - elsif star_clicked? - state.current_input = :star + elsif star_clicked? + state.current_input = :star # When the target in the no second grid is clicked - elsif target_clicked? - state.current_input = :target + elsif target_clicked? + state.current_input = :target # When a wall in the first grid is clicked - elsif wall_clicked? - state.current_input = :remove_wall + elsif wall_clicked? + state.current_input = :remove_wall # When the first grid is clicked - elsif grid_clicked? + elsif grid_clicked? state.current_input = :add_wall end end # Processes click and drag based on what the user is currently dragging def process_input - if state.current_input == :star - input_star - elsif state.current_input == :target - input_target - elsif state.current_input == :remove_wall - input_remove_wall - elsif state.current_input == :add_wall - input_add_wall + if state.current_input == :star + input_star + elsif state.current_input == :target + input_target + elsif state.current_input == :remove_wall + input_remove_wall + elsif state.current_input == :add_wall + input_add_wall end end @@ -347,10 +347,10 @@ class Breadcrumbs # Only resets the search if the star changes position # Called whenever the user is editing the star (puts mouse down on star) def input_star - old_star = grid.star.clone + old_star = grid.star.clone grid.star = cell_closest_to_mouse - unless old_star == grid.star - reset_search + unless old_star == grid.star + reset_search end end @@ -358,10 +358,10 @@ class Breadcrumbs # Only reset_searchs the search if the target changes position # Called whenever the user is editing the target (puts mouse down on target) def input_target - old_target = grid.target.clone + old_target = grid.target.clone grid.target = cell_closest_to_mouse - unless old_target == grid.target - reset_search + unless old_target == grid.target + reset_search end end @@ -370,32 +370,32 @@ class Breadcrumbs # The mouse needs to be inside the grid, because we only want to remove walls # the cursor is directly over # Recalculations should only occur when a wall is actually deleted - if mouse_inside_grid? + if mouse_inside_grid? if grid.walls.has_key?(cell_closest_to_mouse) - grid.walls.delete(cell_closest_to_mouse) - reset_search + grid.walls.delete(cell_closest_to_mouse) + reset_search end end end # Adds a wall in the first grid in the cell the mouse is over def input_add_wall - if mouse_inside_grid? + if mouse_inside_grid? unless grid.walls.has_key?(cell_closest_to_mouse) - grid.walls[cell_closest_to_mouse] = true - reset_search + grid.walls[cell_closest_to_mouse] = true + reset_search end end end - + # Whenever the user edits the grid, # The search has to be reset_searchd upto the current step # with the current grid as the initial state of the grid def reset_search # Reset_Searchs the search - search.frontier = [] - search.came_from = {} + search.frontier = [] + search.came_from = {} search.path = {} end @@ -403,21 +403,21 @@ class Breadcrumbs # Returns a list of adjacent cells # Used to determine what the next cells to be added to the frontier are def adjacent_neighbors(cell) - neighbors = [] + neighbors = [] # Gets all the valid neighbors into the array # From southern neighbor, clockwise - neighbors << [cell.x, cell.y - 1] unless cell.y == 0 - neighbors << [cell.x - 1, cell.y] unless cell.x == 0 - neighbors << [cell.x, cell.y + 1] unless cell.y == grid.height - 1 - neighbors << [cell.x + 1, cell.y] unless cell.x == grid.width - 1 + neighbors << [cell.x, cell.y - 1] unless cell.y == 0 + neighbors << [cell.x - 1, cell.y] unless cell.x == 0 + neighbors << [cell.x, cell.y + 1] unless cell.y == grid.height - 1 + neighbors << [cell.x + 1, cell.y] unless cell.x == grid.width - 1 # Sorts the neighbors so the rendered path is a zigzag path # Cells in a diagonal direction are given priority # Comment this line to see the difference neighbors = neighbors.sort_by { |neighbor_x, neighbor_y| proximity_to_star(neighbor_x, neighbor_y) } - neighbors + neighbors end # Finds the vertical and horizontal distance of a cell from the star @@ -442,13 +442,13 @@ class Breadcrumbs # Finding the cell closest to the mouse helps with this def cell_closest_to_mouse # Closest cell to the mouse in the first grid - x = (inputs.mouse.point.x / grid.cell_size).to_i - y = (inputs.mouse.point.y / grid.cell_size).to_i + x = (inputs.mouse.point.x / grid.cell_size).to_i + y = (inputs.mouse.point.y / grid.cell_size).to_i # Bound x and y to the grid - x = grid.width - 1 if x > grid.width - 1 - y = grid.height - 1 if y > grid.height - 1 + x = grid.width - 1 if x > grid.width - 1 + y = grid.height - 1 if y > grid.height - 1 # Return closest cell - [x, y] + [x, y] end # Signal that the user is going to be moving the star from the first grid @@ -476,13 +476,13 @@ class Breadcrumbs # Light brown def unvisited_color - [221, 212, 213] + [221, 212, 213] # [255, 255, 255] end # Camo Green def wall_color - [134, 134, 120] + [134, 134, 120] end # Pastel White @@ -520,7 +520,7 @@ def tick args end # Every tick, new args are passed, and the Breadth First Search tick is called - $breadcrumbs ||= Breadcrumbs.new(args) + $breadcrumbs ||= Breadcrumbs.new $breadcrumbs.args = args $breadcrumbs.tick end diff --git a/samples/13_path_finding_algorithms/03_breadcrumbs/replay.txt b/samples/13_path_finding_algorithms/03_breadcrumbs/replay.txt new file mode 100644 index 0000000..4e98cf7 --- /dev/null +++ b/samples/13_path_finding_algorithms/03_breadcrumbs/replay.txt @@ -0,0 +1,365 @@ +replay_version 2.0 +stopped_at 211 +seed 100 +recorded_at 2021-11-20 11:18:41 -0600 +[:mouse_button_up, 1, 0, 1, 1, 1] +[:mouse_move, 778, 91, 2, 2, 7] +[:mouse_move, 778, 90, 2, 3, 7] +[:mouse_move, 773, 94, 2, 4, 10] +[:mouse_move, 748, 101, 2, 5, 11] +[:mouse_move, 704, 112, 2, 6, 11] +[:mouse_move, 656, 127, 2, 7, 11] +[:mouse_move, 617, 138, 2, 8, 12] +[:mouse_move, 595, 142, 2, 9, 12] +[:mouse_move, 582, 143, 2, 10, 13] +[:mouse_move, 574, 143, 2, 11, 13] +[:mouse_move, 561, 144, 2, 12, 13] +[:mouse_move, 550, 148, 2, 13, 13] +[:mouse_move, 536, 155, 2, 14, 14] +[:mouse_move, 519, 162, 2, 15, 14] +[:mouse_move, 497, 168, 2, 16, 14] +[:mouse_move, 475, 174, 2, 17, 15] +[:mouse_move, 450, 179, 2, 18, 15] +[:mouse_move, 420, 188, 2, 19, 15] +[:mouse_move, 385, 200, 2, 20, 16] +[:mouse_move, 350, 219, 2, 21, 16] +[:mouse_move, 317, 239, 2, 22, 16] +[:mouse_move, 278, 272, 2, 23, 17] +[:mouse_move, 251, 292, 2, 24, 17] +[:mouse_move, 229, 314, 2, 25, 17] +[:mouse_move, 213, 335, 2, 26, 18] +[:mouse_move, 205, 355, 2, 27, 18] +[:mouse_move, 201, 375, 2, 28, 19] +[:mouse_move, 199, 394, 2, 29, 19] +[:mouse_move, 199, 409, 2, 30, 20] +[:mouse_move, 199, 419, 2, 31, 20] +[:mouse_move, 198, 427, 2, 32, 20] +[:mouse_move, 198, 434, 2, 33, 20] +[:mouse_move, 198, 441, 2, 34, 21] +[:mouse_move, 198, 453, 2, 35, 21] +[:mouse_move, 197, 457, 2, 36, 21] +[:mouse_move, 188, 464, 2, 37, 22] +[:mouse_move, 178, 470, 2, 38, 22] +[:mouse_move, 169, 477, 2, 39, 22] +[:mouse_move, 161, 484, 2, 40, 23] +[:mouse_move, 148, 491, 2, 41, 23] +[:mouse_move, 128, 499, 2, 42, 24] +[:mouse_move, 109, 509, 2, 43, 24] +[:mouse_move, 94, 521, 2, 44, 25] +[:mouse_move, 86, 530, 2, 45, 25] +[:mouse_move, 80, 540, 2, 46, 25] +[:mouse_move, 76, 550, 2, 47, 25] +[:mouse_move, 76, 552, 2, 48, 26] +[:mouse_move, 77, 555, 2, 49, 26] +[:mouse_move, 78, 556, 2, 50, 27] +[:mouse_move, 86, 560, 2, 51, 27] +[:mouse_move, 99, 564, 2, 52, 27] +[:mouse_move, 111, 568, 2, 53, 27] +[:mouse_move, 125, 571, 2, 54, 28] +[:mouse_move, 142, 572, 2, 55, 28] +[:mouse_move, 164, 572, 2, 56, 29] +[:mouse_move, 190, 572, 2, 57, 29] +[:mouse_move, 215, 572, 2, 58, 29] +[:mouse_move, 249, 568, 2, 59, 30] +[:mouse_move, 271, 565, 2, 60, 30] +[:mouse_move, 288, 563, 2, 61, 31] +[:mouse_move, 303, 561, 2, 62, 31] +[:mouse_move, 314, 559, 2, 63, 31] +[:mouse_move, 323, 556, 2, 64, 31] +[:mouse_move, 330, 553, 2, 65, 32] +[:mouse_move, 335, 550, 2, 66, 32] +[:mouse_move, 342, 547, 2, 67, 32] +[:mouse_move, 351, 543, 2, 68, 33] +[:mouse_move, 359, 538, 2, 69, 33] +[:mouse_move, 370, 533, 2, 70, 34] +[:mouse_move, 393, 521, 2, 71, 34] +[:mouse_move, 412, 511, 2, 72, 34] +[:mouse_move, 432, 503, 2, 73, 35] +[:mouse_move, 451, 497, 2, 74, 35] +[:mouse_move, 468, 493, 2, 75, 35] +[:mouse_move, 479, 492, 2, 76, 36] +[:mouse_move, 487, 490, 2, 77, 36] +[:mouse_move, 494, 489, 2, 78, 37] +[:mouse_move, 501, 489, 2, 79, 37] +[:mouse_move, 506, 487, 2, 80, 37] +[:mouse_move, 507, 487, 2, 81, 38] +[:mouse_move, 508, 486, 2, 82, 38] +[:mouse_move, 502, 486, 2, 83, 38] +[:mouse_move, 500, 486, 2, 84, 39] +[:mouse_move, 496, 487, 2, 85, 39] +[:mouse_move, 491, 489, 2, 86, 40] +[:mouse_move, 492, 489, 2, 87, 45] +[:mouse_move, 499, 487, 2, 88, 46] +[:mouse_move, 509, 484, 2, 89, 46] +[:mouse_move, 526, 480, 2, 90, 46] +[:mouse_move, 548, 475, 2, 91, 47] +[:mouse_move, 580, 468, 2, 92, 47] +[:mouse_move, 598, 465, 2, 93, 47] +[:mouse_move, 615, 461, 2, 94, 48] +[:mouse_move, 628, 459, 2, 95, 48] +[:mouse_move, 636, 459, 2, 96, 49] +[:mouse_move, 641, 459, 2, 97, 49] +[:mouse_move, 645, 459, 2, 98, 49] +[:mouse_move, 647, 459, 2, 99, 50] +[:mouse_move, 648, 459, 2, 100, 50] +[:mouse_move, 650, 459, 2, 101, 51] +[:mouse_move, 651, 459, 2, 102, 51] +[:mouse_move, 652, 459, 2, 103, 52] +[:mouse_move, 655, 459, 2, 104, 52] +[:mouse_move, 661, 459, 2, 105, 52] +[:mouse_move, 667, 459, 2, 106, 53] +[:mouse_move, 674, 459, 2, 107, 53] +[:mouse_move, 680, 460, 2, 108, 54] +[:mouse_move, 687, 461, 2, 109, 54] +[:mouse_move, 695, 462, 2, 110, 54] +[:mouse_move, 699, 463, 2, 111, 55] +[:mouse_move, 700, 463, 2, 112, 55] +[:mouse_move, 702, 463, 2, 113, 56] +[:mouse_move, 705, 463, 2, 114, 56] +[:mouse_move, 709, 464, 2, 115, 56] +[:mouse_move, 714, 464, 2, 116, 57] +[:mouse_move, 718, 464, 2, 117, 57] +[:mouse_move, 721, 464, 2, 118, 57] +[:mouse_move, 723, 464, 2, 119, 58] +[:mouse_move, 726, 465, 2, 120, 58] +[:mouse_move, 729, 465, 2, 121, 59] +[:mouse_move, 731, 465, 2, 122, 59] +[:mouse_move, 732, 465, 2, 123, 60] +[:mouse_move, 733, 465, 2, 124, 61] +[:mouse_move, 734, 465, 2, 125, 61] +[:mouse_move, 737, 465, 2, 126, 61] +[:mouse_move, 739, 465, 2, 127, 62] +[:mouse_move, 743, 465, 2, 128, 62] +[:mouse_move, 751, 467, 2, 129, 62] +[:mouse_move, 761, 469, 2, 130, 63] +[:mouse_move, 772, 469, 2, 131, 63] +[:mouse_move, 782, 469, 2, 132, 63] +[:mouse_move, 793, 471, 2, 133, 64] +[:mouse_move, 808, 471, 2, 134, 64] +[:mouse_move, 818, 472, 2, 135, 64] +[:mouse_move, 829, 473, 2, 136, 65] +[:mouse_move, 839, 475, 2, 137, 65] +[:mouse_move, 849, 477, 2, 138, 66] +[:mouse_move, 861, 479, 2, 139, 66] +[:mouse_move, 876, 480, 2, 140, 66] +[:mouse_move, 893, 480, 2, 141, 67] +[:mouse_move, 912, 480, 2, 142, 67] +[:mouse_move, 933, 482, 2, 143, 68] +[:mouse_move, 952, 482, 2, 144, 68] +[:mouse_move, 967, 482, 2, 145, 68] +[:mouse_move, 983, 482, 2, 146, 68] +[:mouse_move, 1007, 482, 2, 147, 69] +[:mouse_move, 1021, 482, 2, 148, 69] +[:mouse_move, 1031, 482, 2, 149, 70] +[:mouse_move, 1041, 482, 2, 150, 70] +[:mouse_move, 1045, 482, 2, 151, 71] +[:mouse_move, 1049, 481, 2, 152, 71] +[:mouse_move, 1052, 481, 2, 153, 71] +[:mouse_move, 1053, 481, 2, 154, 71] +[:mouse_move, 1054, 481, 2, 155, 72] +[:mouse_move, 1055, 480, 2, 156, 73] +[:mouse_move, 1057, 480, 2, 157, 73] +[:mouse_move, 1060, 479, 2, 158, 74] +[:mouse_move, 1062, 479, 2, 159, 74] +[:mouse_move, 1063, 478, 2, 160, 75] +[:mouse_move, 1064, 478, 2, 161, 75] +[:mouse_move, 1065, 478, 2, 162, 77] +[:mouse_move, 1066, 478, 2, 163, 77] +[:mouse_move, 1067, 478, 2, 164, 78] +[:mouse_move, 1069, 478, 2, 165, 83] +[:mouse_move, 1074, 477, 2, 166, 84] +[:mouse_move, 1082, 476, 2, 167, 84] +[:mouse_move, 1093, 469, 2, 168, 85] +[:mouse_move, 1106, 459, 2, 169, 85] +[:mouse_move, 1117, 447, 2, 170, 85] +[:mouse_move, 1125, 433, 2, 171, 85] +[:mouse_move, 1130, 414, 2, 172, 85] +[:mouse_move, 1130, 382, 2, 173, 86] +[:mouse_move, 1127, 358, 2, 174, 86] +[:mouse_move, 1119, 333, 2, 175, 87] +[:mouse_move, 1109, 309, 2, 176, 87] +[:mouse_move, 1102, 293, 2, 177, 87] +[:mouse_move, 1094, 280, 2, 178, 88] +[:mouse_move, 1089, 272, 2, 179, 88] +[:mouse_move, 1087, 264, 2, 180, 89] +[:mouse_move, 1086, 258, 2, 181, 89] +[:mouse_move, 1086, 248, 2, 182, 89] +[:mouse_move, 1084, 241, 2, 183, 89] +[:mouse_move, 1084, 240, 2, 184, 90] +[:mouse_button_pressed, 1, 0, 1, 185, 95] +[:mouse_button_up, 1, 0, 1, 186, 97] +[:mouse_move, 1086, 251, 2, 187, 105] +[:mouse_move, 1086, 267, 2, 188, 105] +[:mouse_move, 1087, 287, 2, 189, 106] +[:mouse_move, 1087, 310, 2, 190, 106] +[:mouse_move, 1087, 339, 2, 191, 107] +[:mouse_move, 1078, 387, 2, 192, 107] +[:mouse_move, 1064, 422, 2, 193, 107] +[:mouse_move, 1050, 449, 2, 194, 108] +[:mouse_move, 1033, 470, 2, 195, 108] +[:mouse_move, 1015, 485, 2, 196, 108] +[:mouse_move, 995, 494, 2, 197, 109] +[:mouse_move, 973, 500, 2, 198, 109] +[:mouse_move, 955, 505, 2, 199, 109] +[:mouse_move, 936, 506, 2, 200, 110] +[:mouse_move, 919, 510, 2, 201, 110] +[:mouse_move, 906, 510, 2, 202, 110] +[:mouse_move, 891, 513, 2, 203, 111] +[:mouse_move, 873, 516, 2, 204, 111] +[:mouse_move, 854, 520, 2, 205, 111] +[:mouse_move, 843, 522, 2, 206, 112] +[:mouse_move, 830, 525, 2, 207, 112] +[:mouse_move, 816, 526, 2, 208, 112] +[:mouse_move, 804, 527, 2, 209, 113] +[:mouse_move, 794, 527, 2, 210, 113] +[:mouse_move, 784, 527, 2, 211, 114] +[:mouse_move, 775, 526, 2, 212, 114] +[:mouse_move, 765, 522, 2, 213, 114] +[:mouse_move, 755, 518, 2, 214, 115] +[:mouse_move, 746, 513, 2, 215, 115] +[:mouse_move, 732, 505, 2, 216, 116] +[:mouse_move, 706, 483, 2, 217, 116] +[:mouse_move, 694, 463, 2, 218, 116] +[:mouse_move, 689, 446, 2, 219, 116] +[:mouse_move, 689, 429, 2, 220, 117] +[:mouse_move, 689, 409, 2, 221, 117] +[:mouse_move, 689, 388, 2, 222, 118] +[:mouse_move, 689, 361, 2, 223, 118] +[:mouse_move, 683, 327, 2, 224, 119] +[:mouse_move, 677, 295, 2, 225, 119] +[:mouse_move, 666, 266, 2, 226, 119] +[:mouse_move, 656, 245, 2, 227, 119] +[:mouse_move, 650, 233, 2, 228, 120] +[:mouse_move, 640, 215, 2, 229, 120] +[:mouse_move, 630, 203, 2, 230, 121] +[:mouse_move, 612, 189, 2, 231, 121] +[:mouse_move, 586, 178, 2, 232, 121] +[:mouse_move, 553, 168, 2, 233, 121] +[:mouse_move, 528, 166, 2, 234, 122] +[:mouse_move, 510, 165, 2, 235, 122] +[:mouse_move, 498, 165, 2, 236, 123] +[:mouse_move, 482, 165, 2, 237, 123] +[:mouse_move, 466, 165, 2, 238, 123] +[:mouse_move, 450, 165, 2, 239, 124] +[:mouse_move, 426, 165, 2, 240, 124] +[:mouse_move, 416, 165, 2, 241, 125] +[:mouse_move, 411, 166, 2, 242, 125] +[:mouse_move, 407, 168, 2, 243, 126] +[:mouse_move, 405, 169, 2, 244, 126] +[:mouse_move, 400, 172, 2, 245, 126] +[:mouse_move, 391, 178, 2, 246, 126] +[:mouse_move, 381, 185, 2, 247, 127] +[:mouse_move, 368, 195, 2, 248, 127] +[:mouse_move, 355, 207, 2, 249, 128] +[:mouse_move, 345, 223, 2, 250, 128] +[:mouse_move, 343, 243, 2, 251, 128] +[:mouse_move, 343, 273, 2, 252, 129] +[:mouse_move, 343, 290, 2, 253, 129] +[:mouse_move, 343, 308, 2, 254, 129] +[:mouse_move, 342, 326, 2, 255, 130] +[:mouse_move, 340, 343, 2, 256, 130] +[:mouse_move, 339, 363, 2, 257, 130] +[:mouse_move, 339, 384, 2, 258, 131] +[:mouse_move, 339, 407, 2, 259, 131] +[:mouse_move, 338, 427, 2, 260, 132] +[:mouse_move, 333, 446, 2, 261, 132] +[:mouse_move, 330, 463, 2, 262, 132] +[:mouse_move, 325, 477, 2, 263, 133] +[:mouse_move, 317, 488, 2, 264, 133] +[:mouse_move, 313, 494, 2, 265, 133] +[:mouse_move, 308, 500, 2, 266, 134] +[:mouse_move, 302, 511, 2, 267, 134] +[:mouse_move, 295, 522, 2, 268, 135] +[:mouse_move, 285, 535, 2, 269, 135] +[:mouse_move, 277, 547, 2, 270, 135] +[:mouse_move, 267, 558, 2, 271, 136] +[:mouse_move, 259, 568, 2, 272, 136] +[:mouse_move, 250, 574, 2, 273, 137] +[:mouse_move, 241, 580, 2, 274, 137] +[:mouse_move, 233, 586, 2, 275, 137] +[:mouse_move, 222, 593, 2, 276, 138] +[:mouse_move, 213, 599, 2, 277, 138] +[:mouse_move, 206, 606, 2, 278, 138] +[:mouse_move, 203, 615, 2, 279, 139] +[:mouse_move, 202, 622, 2, 280, 139] +[:mouse_move, 200, 625, 2, 281, 139] +[:mouse_move, 199, 627, 2, 282, 140] +[:mouse_move, 198, 628, 2, 283, 140] +[:mouse_move, 197, 628, 2, 284, 141] +[:mouse_move, 194, 630, 2, 285, 141] +[:mouse_move, 190, 632, 2, 286, 141] +[:mouse_move, 186, 633, 2, 287, 142] +[:mouse_move, 180, 635, 2, 288, 142] +[:mouse_move, 175, 636, 2, 289, 143] +[:mouse_move, 174, 636, 2, 290, 144] +[:mouse_move, 173, 636, 2, 291, 144] +[:mouse_move, 170, 636, 2, 292, 144] +[:mouse_move, 164, 636, 2, 293, 144] +[:mouse_move, 155, 636, 2, 294, 145] +[:mouse_move, 147, 634, 2, 295, 145] +[:mouse_move, 141, 634, 2, 296, 146] +[:mouse_move, 139, 634, 2, 297, 146] +[:mouse_move, 138, 634, 2, 298, 146] +[:mouse_move, 136, 634, 2, 299, 147] +[:mouse_move, 135, 633, 2, 300, 148] +[:mouse_move, 134, 633, 2, 301, 148] +[:mouse_move, 133, 633, 2, 302, 148] +[:key_down_raw, 96, 0, 2, 303, 159] +[:mouse_move, 134, 632, 2, 304, 160] +[:mouse_move, 138, 632, 2, 305, 161] +[:key_up_raw, 96, 0, 2, 306, 161] +[:mouse_move, 144, 630, 2, 307, 161] +[:mouse_move, 155, 628, 2, 308, 161] +[:mouse_move, 170, 623, 2, 309, 161] +[:mouse_move, 189, 618, 2, 310, 161] +[:mouse_move, 213, 611, 2, 311, 162] +[:mouse_move, 243, 600, 2, 312, 162] +[:mouse_move, 281, 586, 2, 313, 163] +[:mouse_move, 330, 565, 2, 314, 163] +[:mouse_move, 400, 533, 2, 315, 163] +[:mouse_move, 476, 492, 2, 316, 164] +[:mouse_move, 564, 445, 2, 317, 164] +[:mouse_move, 703, 362, 2, 318, 164] +[:mouse_move, 797, 306, 2, 319, 165] +[:mouse_move, 872, 251, 2, 320, 165] +[:mouse_move, 951, 196, 2, 321, 165] +[:mouse_move, 1012, 147, 2, 322, 166] +[:mouse_move, 1058, 112, 2, 323, 166] +[:mouse_move, 1085, 87, 2, 324, 166] +[:mouse_move, 1100, 67, 2, 325, 166] +[:mouse_move, 1111, 51, 2, 326, 167] +[:mouse_move, 1117, 42, 2, 327, 167] +[:mouse_move, 1118, 39, 2, 328, 168] +[:mouse_move, 1110, 35, 2, 329, 170] +[:mouse_move, 1101, 34, 2, 330, 171] +[:mouse_move, 1095, 34, 2, 331, 171] +[:mouse_move, 1087, 34, 2, 332, 171] +[:mouse_move, 1076, 34, 2, 333, 172] +[:mouse_move, 1064, 34, 2, 334, 172] +[:mouse_move, 1045, 38, 2, 335, 172] +[:mouse_move, 1031, 42, 2, 336, 172] +[:mouse_move, 1018, 45, 2, 337, 173] +[:mouse_move, 1002, 50, 2, 338, 173] +[:mouse_move, 978, 53, 2, 339, 173] +[:mouse_move, 947, 54, 2, 340, 174] +[:mouse_move, 908, 54, 2, 341, 174] +[:mouse_move, 864, 54, 2, 342, 174] +[:mouse_move, 830, 54, 2, 343, 174] +[:mouse_move, 810, 58, 2, 344, 175] +[:mouse_move, 807, 59, 2, 345, 175] +[:mouse_move, 808, 59, 2, 346, 177] +[:mouse_move, 810, 61, 2, 347, 178] +[:mouse_move, 814, 65, 2, 348, 178] +[:mouse_move, 816, 66, 2, 349, 178] +[:mouse_move, 818, 69, 2, 350, 178] +[:mouse_move, 819, 71, 2, 351, 179] +[:mouse_move, 820, 73, 2, 352, 179] +[:mouse_move, 820, 74, 2, 353, 179] +[:mouse_move, 819, 75, 2, 354, 183] +[:mouse_move, 817, 77, 2, 355, 183] +[:mouse_move, 814, 81, 2, 356, 184] +[:mouse_move, 810, 84, 2, 357, 184] +[:mouse_move, 809, 85, 2, 358, 184] +[:mouse_move, 810, 85, 2, 359, 211] +[:key_down_raw, 13, 0, 2, 360, 211] +[:mouse_move, 811, 85, 2, 361, 211] diff --git a/samples/13_path_finding_algorithms/04_early_exit/app/main.rb b/samples/13_path_finding_algorithms/04_early_exit/app/main.rb index 1e9305b..40a3ba5 100644 --- a/samples/13_path_finding_algorithms/04_early_exit/app/main.rb +++ b/samples/13_path_finding_algorithms/04_early_exit/app/main.rb @@ -26,8 +26,8 @@ class EarlyExitBreadthFirstSearch # And calculate the path calc_path end - render - input + render + input end def defaults @@ -43,14 +43,14 @@ class EarlyExitBreadthFirstSearch # This step is roughly the grid's width * height # When anim_steps equals max_steps no more calculations will occur # and the slider will be at the end - state.max_steps ||= args.state.grid.width * args.state.grid.height + state.max_steps ||= args.state.grid.width * args.state.grid.height # The location of the star and walls of the grid # They can be modified to have a different initial grid # Walls are stored in a hash for quick look up when doing the search state.star ||= [2, 8] state.target ||= [10, 5] - state.walls ||= {} + state.walls ||= {} # Variables that are used by the breadth first search # Storing cells that the search has visited, prevents unnecessary steps @@ -73,12 +73,12 @@ class EarlyExitBreadthFirstSearch # We store this value, because we want to remember the value even when # the user's cursor is no longer over what they're interacting with, but # they are still clicking down on the mouse. - state.current_input ||= :none + state.current_input ||= :none end # Draws everything onto the screen def render - render_background + render_background render_heat_map render_walls render_path @@ -91,8 +91,8 @@ class EarlyExitBreadthFirstSearch # Draws what the grid looks like with nothing on it def render_background - render_unvisited - render_grid_lines + render_unvisited + render_grid_lines end # Draws both grids @@ -109,7 +109,7 @@ class EarlyExitBreadthFirstSearch end for y in 0..grid.height - outputs.lines << horizontal_line(y) + outputs.lines << horizontal_line(y) outputs.lines << early_exit_horizontal_line(y) end end @@ -136,7 +136,7 @@ class EarlyExitBreadthFirstSearch # Draws the walls on both grids def render_walls - state.walls.each_key do |wall| + state.walls.each_key do |wall| outputs.solids << [scale_up(wall), wall_color] outputs.solids << [early_exit_scale_up(wall), wall_color] end @@ -146,13 +146,13 @@ class EarlyExitBreadthFirstSearch def render_star outputs.sprites << [scale_up(state.star), 'star.png'] outputs.sprites << [early_exit_scale_up(state.star), 'star.png'] - end + end # Renders the target on both grids def render_target outputs.sprites << [scale_up(state.target), 'target.png'] outputs.sprites << [early_exit_scale_up(state.target), 'target.png'] - end + end # Labels the grids def render_labels @@ -244,8 +244,8 @@ class EarlyExitBreadthFirstSearch # The program has to remember that the user is dragging an object # even when the mouse is no longer over that object # So detecting input and processing input is separate - detect_input - process_input + detect_input + process_input end # Determines what the user is editing and stores the value @@ -253,53 +253,53 @@ class EarlyExitBreadthFirstSearch # mouse left click is held def detect_input # When the mouse is up, nothing is being edited - if inputs.mouse.up - state.current_input = :none + if inputs.mouse.up + state.current_input = :none # When the star in the no second grid is clicked - elsif star_clicked? - state.current_input = :star + elsif star_clicked? + state.current_input = :star # When the star in the second grid is clicked - elsif star2_clicked? - state.current_input = :star2 + elsif star2_clicked? + state.current_input = :star2 # When the target in the no second grid is clicked - elsif target_clicked? - state.current_input = :target + elsif target_clicked? + state.current_input = :target # When the target in the second grid is clicked - elsif target2_clicked? - state.current_input = :target2 + elsif target2_clicked? + state.current_input = :target2 # When a wall in the first grid is clicked - elsif wall_clicked? - state.current_input = :remove_wall + elsif wall_clicked? + state.current_input = :remove_wall # When a wall in the second grid is clicked - elsif wall2_clicked? + elsif wall2_clicked? state.current_input = :remove_wall2 # When the first grid is clicked - elsif grid_clicked? + elsif grid_clicked? state.current_input = :add_wall # When the second grid is clicked - elsif grid2_clicked? + elsif grid2_clicked? state.current_input = :add_wall2 end end # Processes click and drag based on what the user is currently dragging def process_input - if state.current_input == :star - input_star + if state.current_input == :star + input_star elsif state.current_input == :star2 - input_star2 - elsif state.current_input == :target - input_target - elsif state.current_input == :target2 - input_target2 - elsif state.current_input == :remove_wall - input_remove_wall + input_star2 + elsif state.current_input == :target + input_target + elsif state.current_input == :target2 + input_target2 + elsif state.current_input == :remove_wall + input_remove_wall elsif state.current_input == :remove_wall2 - input_remove_wall2 - elsif state.current_input == :add_wall - input_add_wall - elsif state.current_input == :add_wall2 - input_add_wall2 + input_remove_wall2 + elsif state.current_input == :add_wall + input_add_wall + elsif state.current_input == :add_wall2 + input_add_wall2 end end @@ -307,10 +307,10 @@ class EarlyExitBreadthFirstSearch # Only resets the search if the star changes position # Called whenever the user is editing the star (puts mouse down on star) def input_star - old_star = state.star.clone + old_star = state.star.clone state.star = cell_closest_to_mouse - unless old_star == state.star - reset_search + unless old_star == state.star + reset_search end end @@ -318,10 +318,10 @@ class EarlyExitBreadthFirstSearch # Only resets the search if the star changes position # Called whenever the user is editing the star (puts mouse down on star) def input_star2 - old_star = state.star.clone + old_star = state.star.clone state.star = cell_closest_to_mouse2 - unless old_star == state.star - reset_search + unless old_star == state.star + reset_search end end @@ -329,10 +329,10 @@ class EarlyExitBreadthFirstSearch # Only reset_searchs the search if the target changes position # Called whenever the user is editing the target (puts mouse down on target) def input_target - old_target = state.target.clone + old_target = state.target.clone state.target = cell_closest_to_mouse - unless old_target == state.target - reset_search + unless old_target == state.target + reset_search end end @@ -340,10 +340,10 @@ class EarlyExitBreadthFirstSearch # Only reset_searchs the search if the target changes position # Called whenever the user is editing the target (puts mouse down on target) def input_target2 - old_target = state.target.clone + old_target = state.target.clone state.target = cell_closest_to_mouse2 - unless old_target == state.target - reset_search + unless old_target == state.target + reset_search end end @@ -352,10 +352,10 @@ class EarlyExitBreadthFirstSearch # The mouse needs to be inside the grid, because we only want to remove walls # the cursor is directly over # Recalculations should only occur when a wall is actually deleted - if mouse_inside_grid? + if mouse_inside_grid? if state.walls.has_key?(cell_closest_to_mouse) - state.walls.delete(cell_closest_to_mouse) - reset_search + state.walls.delete(cell_closest_to_mouse) + reset_search end end end @@ -365,31 +365,31 @@ class EarlyExitBreadthFirstSearch # The mouse needs to be inside the grid, because we only want to remove walls # the cursor is directly over # Recalculations should only occur when a wall is actually deleted - if mouse_inside_grid2? + if mouse_inside_grid2? if state.walls.has_key?(cell_closest_to_mouse2) - state.walls.delete(cell_closest_to_mouse2) - reset_search + state.walls.delete(cell_closest_to_mouse2) + reset_search end end end # Adds a wall in the first grid in the cell the mouse is over def input_add_wall - if mouse_inside_grid? + if mouse_inside_grid? unless state.walls.has_key?(cell_closest_to_mouse) - state.walls[cell_closest_to_mouse] = true - reset_search + state.walls[cell_closest_to_mouse] = true + reset_search end end end - + # Adds a wall in the second grid in the cell the mouse is over def input_add_wall2 - if mouse_inside_grid2? + if mouse_inside_grid2? unless state.walls.has_key?(cell_closest_to_mouse2) - state.walls[cell_closest_to_mouse2] = true - reset_search + state.walls[cell_closest_to_mouse2] = true + reset_search end end end @@ -399,10 +399,10 @@ class EarlyExitBreadthFirstSearch # with the current grid as the initial state of the grid def reset_search # Reset_Searchs the search - state.frontier = [] - state.visited = {} - state.early_exit_visited = {} - state.came_from = {} + state.frontier = [] + state.visited = {} + state.early_exit_visited = {} + state.came_from = {} state.path = {} end @@ -410,23 +410,23 @@ class EarlyExitBreadthFirstSearch def step # The setup to the search # Runs once when there are no visited cells - if state.visited.empty? - state.visited[state.star] = true - state.early_exit_visited[state.star] = true - state.frontier << state.star + if state.visited.empty? + state.visited[state.star] = true + state.early_exit_visited[state.star] = true + state.frontier << state.star state.came_from[state.star] = nil end # A step in the search - unless state.frontier.empty? + unless state.frontier.empty? # Takes the next frontier cell - new_frontier = state.frontier.shift + new_frontier = state.frontier.shift # For each of its neighbors - adjacent_neighbors(new_frontier).each do |neighbor| + adjacent_neighbors(new_frontier).each do |neighbor| # That have not been visited and are not walls - unless state.visited.has_key?(neighbor) || state.walls.has_key?(neighbor) + unless state.visited.has_key?(neighbor) || state.walls.has_key?(neighbor) # Add them to the frontier and mark them as visited in the first grid - state.visited[neighbor] = true + state.visited[neighbor] = true # Unless the target has been visited unless state.visited.has_key?(state.target) # Mark the neighbor as visited in the second grid as well @@ -434,32 +434,32 @@ class EarlyExitBreadthFirstSearch end # Add the neighbor to the frontier and remember which cell it came from - state.frontier << neighbor + state.frontier << neighbor state.came_from[neighbor] = new_frontier end end end end - + # Returns a list of adjacent cells # Used to determine what the next cells to be added to the frontier are def adjacent_neighbors(cell) - neighbors = [] + neighbors = [] # Gets all the valid neighbors into the array # From southern neighbor, clockwise - neighbors << [cell.x, cell.y - 1] unless cell.y == 0 - neighbors << [cell.x - 1, cell.y] unless cell.x == 0 - neighbors << [cell.x, cell.y + 1] unless cell.y == grid.height - 1 - neighbors << [cell.x + 1, cell.y] unless cell.x == grid.width - 1 + neighbors << [cell.x, cell.y - 1] unless cell.y == 0 + neighbors << [cell.x - 1, cell.y] unless cell.x == 0 + neighbors << [cell.x, cell.y + 1] unless cell.y == grid.height - 1 + neighbors << [cell.x + 1, cell.y] unless cell.x == grid.width - 1 # Sorts the neighbors so the rendered path is a zigzag path # Cells in a diagonal direction are given priority # Comment this line to see the difference neighbors = neighbors.sort_by { |neighbor_x, neighbor_y| proximity_to_star(neighbor_x, neighbor_y) } - neighbors + neighbors end # Finds the vertical and horizontal distance of a cell from the star @@ -484,13 +484,13 @@ class EarlyExitBreadthFirstSearch # Finding the cell closest to the mouse helps with this def cell_closest_to_mouse # Closest cell to the mouse in the first grid - x = (inputs.mouse.point.x / grid.cell_size).to_i - y = (inputs.mouse.point.y / grid.cell_size).to_i + x = (inputs.mouse.point.x / grid.cell_size).to_i + y = (inputs.mouse.point.y / grid.cell_size).to_i # Bound x and y to the grid - x = grid.width - 1 if x > grid.width - 1 - y = grid.height - 1 if y > grid.height - 1 + x = grid.width - 1 if x > grid.width - 1 + y = grid.height - 1 if y > grid.height - 1 # Return closest cell - [x, y] + [x, y] end # When the user grabs the star and puts their cursor to the far right @@ -498,15 +498,15 @@ class EarlyExitBreadthFirstSearch # Finding the cell closest to the mouse in the second grid helps with this def cell_closest_to_mouse2 # Closest cell grid to the mouse in the second - x = (inputs.mouse.point.x / grid.cell_size).to_i - y = (inputs.mouse.point.y / grid.cell_size).to_i + x = (inputs.mouse.point.x / grid.cell_size).to_i + y = (inputs.mouse.point.y / grid.cell_size).to_i # Translate the cell to the first grid x -= grid.width + 1 # Bound x and y to the first grid - x = grid.width - 1 if x > grid.width - 1 - y = grid.height - 1 if y > grid.height - 1 + x = grid.width - 1 if x > grid.width - 1 + y = grid.height - 1 if y > grid.height - 1 # Return closest cell - [x, y] + [x, y] end # Signal that the user is going to be moving the star from the first grid @@ -585,12 +585,12 @@ class EarlyExitBreadthFirstSearch # Light brown def unvisited_color - [221, 212, 213] + [221, 212, 213] end # Camo Green def wall_color - [134, 134, 120] + [134, 134, 120] end # Pastel White @@ -620,7 +620,7 @@ def tick args end # Every tick, new args are passed, and the Breadth First Search tick is called - $early_exit_breadth_first_search ||= EarlyExitBreadthFirstSearch.new(args) + $early_exit_breadth_first_search ||= EarlyExitBreadthFirstSearch.new $early_exit_breadth_first_search.args = args $early_exit_breadth_first_search.tick end diff --git a/samples/13_path_finding_algorithms/04_early_exit/replay.txt b/samples/13_path_finding_algorithms/04_early_exit/replay.txt new file mode 100644 index 0000000..3ec9254 --- /dev/null +++ b/samples/13_path_finding_algorithms/04_early_exit/replay.txt @@ -0,0 +1,364 @@ +replay_version 2.0 +stopped_at 322 +seed 100 +recorded_at 2021-11-20 11:19:30 -0600 +[:mouse_button_up, 1, 0, 1, 1, 1] +[:mouse_move, 806, 92, 2, 2, 12] +[:mouse_move, 799, 105, 2, 3, 13] +[:mouse_move, 786, 126, 2, 4, 13] +[:mouse_move, 761, 154, 2, 5, 13] +[:mouse_move, 722, 199, 2, 6, 14] +[:mouse_move, 692, 230, 2, 7, 14] +[:mouse_move, 659, 263, 2, 8, 14] +[:mouse_move, 629, 297, 2, 9, 14] +[:mouse_move, 598, 337, 2, 10, 15] +[:mouse_move, 569, 376, 2, 11, 15] +[:mouse_move, 538, 412, 2, 12, 15] +[:mouse_move, 510, 438, 2, 13, 16] +[:mouse_move, 488, 456, 2, 14, 16] +[:mouse_move, 471, 467, 2, 15, 16] +[:mouse_move, 459, 477, 2, 16, 17] +[:mouse_move, 455, 481, 2, 17, 17] +[:mouse_move, 455, 484, 2, 18, 18] +[:mouse_move, 454, 485, 2, 19, 18] +[:mouse_move, 464, 481, 2, 20, 23] +[:mouse_move, 482, 477, 2, 21, 23] +[:mouse_move, 490, 470, 2, 22, 23] +[:mouse_move, 491, 469, 2, 23, 24] +[:mouse_move, 492, 467, 2, 24, 24] +[:mouse_move, 493, 466, 2, 25, 25] +[:mouse_move, 485, 466, 2, 26, 26] +[:mouse_move, 474, 468, 2, 27, 27] +[:mouse_move, 460, 472, 2, 28, 27] +[:mouse_move, 441, 476, 2, 29, 27] +[:mouse_move, 419, 479, 2, 30, 27] +[:mouse_move, 392, 480, 2, 31, 28] +[:mouse_move, 359, 480, 2, 32, 28] +[:mouse_move, 329, 483, 2, 33, 29] +[:mouse_move, 306, 486, 2, 34, 29] +[:mouse_move, 281, 493, 2, 35, 30] +[:mouse_move, 271, 496, 2, 36, 30] +[:mouse_move, 270, 496, 2, 37, 30] +[:mouse_move, 272, 496, 2, 38, 32] +[:mouse_move, 275, 496, 2, 39, 32] +[:mouse_move, 279, 495, 2, 40, 32] +[:mouse_move, 283, 494, 2, 41, 33] +[:mouse_move, 289, 494, 2, 42, 33] +[:mouse_move, 292, 494, 2, 43, 34] +[:mouse_move, 293, 495, 2, 44, 35] +[:mouse_button_pressed, 1, 0, 1, 45, 39] +[:mouse_button_up, 1, 0, 1, 46, 40] +[:mouse_move, 294, 495, 2, 47, 49] +[:mouse_move, 294, 494, 2, 48, 50] +[:mouse_move, 295, 491, 2, 49, 50] +[:mouse_move, 296, 488, 2, 50, 50] +[:mouse_move, 297, 484, 2, 51, 50] +[:mouse_move, 297, 481, 2, 52, 51] +[:mouse_move, 298, 477, 2, 53, 51] +[:mouse_move, 298, 476, 2, 54, 51] +[:mouse_move, 299, 475, 2, 55, 52] +[:mouse_move, 300, 473, 2, 56, 52] +[:mouse_move, 300, 472, 2, 57, 53] +[:mouse_move, 300, 471, 2, 58, 55] +[:mouse_move, 300, 470, 2, 59, 56] +[:mouse_move, 300, 469, 2, 60, 57] +[:mouse_move, 300, 467, 2, 61, 57] +[:mouse_move, 300, 466, 2, 62, 57] +[:mouse_button_pressed, 1, 0, 1, 63, 59] +[:mouse_button_up, 1, 0, 1, 64, 61] +[:mouse_move, 300, 465, 2, 65, 61] +[:mouse_move, 300, 462, 2, 66, 62] +[:mouse_move, 300, 456, 2, 67, 62] +[:mouse_move, 300, 449, 2, 68, 62] +[:mouse_move, 300, 443, 2, 69, 63] +[:mouse_move, 299, 441, 2, 70, 63] +[:mouse_move, 299, 440, 2, 71, 63] +[:mouse_move, 299, 438, 2, 72, 64] +[:mouse_move, 299, 437, 2, 73, 65] +[:mouse_move, 299, 436, 2, 74, 65] +[:mouse_move, 299, 434, 2, 75, 65] +[:mouse_move, 299, 432, 2, 76, 65] +[:mouse_move, 299, 431, 2, 77, 67] +[:mouse_move, 299, 430, 2, 78, 67] +[:mouse_move, 299, 429, 2, 79, 68] +[:mouse_move, 299, 428, 2, 80, 68] +[:mouse_move, 299, 424, 2, 81, 68] +[:mouse_move, 300, 417, 2, 82, 69] +[:mouse_move, 301, 413, 2, 83, 69] +[:mouse_move, 302, 412, 2, 84, 70] +[:mouse_button_pressed, 1, 0, 1, 85, 72] +[:mouse_move, 302, 411, 2, 86, 72] +[:mouse_button_up, 1, 0, 1, 87, 74] +[:mouse_move, 302, 408, 2, 88, 94] +[:mouse_move, 302, 396, 2, 89, 94] +[:mouse_move, 302, 383, 2, 90, 95] +[:mouse_move, 302, 375, 2, 91, 95] +[:mouse_move, 303, 374, 2, 92, 95] +[:mouse_move, 303, 373, 2, 93, 95] +[:mouse_move, 303, 374, 2, 94, 99] +[:mouse_button_pressed, 1, 0, 1, 95, 101] +[:mouse_button_up, 1, 0, 1, 96, 103] +[:mouse_move, 303, 375, 2, 97, 103] +[:mouse_move, 306, 375, 2, 98, 132] +[:mouse_move, 317, 376, 2, 99, 132] +[:mouse_move, 333, 380, 2, 100, 133] +[:mouse_move, 352, 384, 2, 101, 133] +[:mouse_move, 374, 385, 2, 102, 133] +[:mouse_move, 401, 390, 2, 103, 134] +[:mouse_move, 424, 392, 2, 104, 134] +[:mouse_move, 442, 395, 2, 105, 134] +[:mouse_move, 455, 397, 2, 106, 135] +[:mouse_move, 458, 398, 2, 107, 135] +[:mouse_move, 460, 398, 2, 108, 136] +[:mouse_move, 466, 398, 2, 109, 136] +[:mouse_move, 473, 398, 2, 110, 136] +[:mouse_move, 477, 398, 2, 111, 136] +[:mouse_move, 478, 397, 2, 112, 136] +[:mouse_move, 479, 397, 2, 113, 137] +[:mouse_move, 480, 396, 2, 114, 137] +[:mouse_move, 480, 395, 2, 115, 138] +[:mouse_move, 480, 396, 2, 116, 138] +[:mouse_move, 478, 404, 2, 117, 139] +[:mouse_move, 474, 418, 2, 118, 139] +[:mouse_move, 472, 426, 2, 119, 139] +[:mouse_move, 466, 438, 2, 120, 140] +[:mouse_move, 461, 453, 2, 121, 140] +[:mouse_move, 453, 466, 2, 122, 140] +[:mouse_move, 448, 473, 2, 123, 141] +[:mouse_move, 446, 475, 2, 124, 141] +[:mouse_move, 444, 477, 2, 125, 142] +[:mouse_move, 441, 481, 2, 126, 142] +[:mouse_move, 435, 489, 2, 127, 142] +[:mouse_move, 426, 496, 2, 128, 143] +[:mouse_move, 422, 498, 2, 129, 143] +[:mouse_move, 422, 499, 2, 130, 143] +[:mouse_move, 421, 499, 2, 131, 145] +[:mouse_move, 420, 499, 2, 132, 145] +[:mouse_button_pressed, 1, 0, 1, 133, 147] +[:mouse_move, 419, 499, 2, 134, 148] +[:mouse_move, 419, 497, 2, 135, 148] +[:mouse_move, 421, 494, 2, 136, 149] +[:mouse_move, 426, 484, 2, 137, 149] +[:mouse_move, 432, 472, 2, 138, 149] +[:mouse_move, 439, 460, 2, 139, 150] +[:mouse_move, 445, 450, 2, 140, 150] +[:mouse_move, 456, 434, 2, 141, 150] +[:mouse_move, 466, 422, 2, 142, 150] +[:mouse_move, 474, 411, 2, 143, 151] +[:mouse_move, 480, 403, 2, 144, 151] +[:mouse_move, 485, 397, 2, 145, 151] +[:mouse_move, 489, 392, 2, 146, 151] +[:mouse_move, 491, 389, 2, 147, 151] +[:mouse_move, 494, 384, 2, 148, 151] +[:mouse_move, 495, 381, 2, 149, 152] +[:mouse_move, 497, 378, 2, 150, 152] +[:mouse_move, 499, 376, 2, 151, 152] +[:mouse_move, 500, 373, 2, 152, 152] +[:mouse_move, 501, 372, 2, 153, 152] +[:mouse_move, 501, 371, 2, 154, 152] +[:mouse_move, 502, 370, 2, 155, 153] +[:mouse_move, 502, 369, 2, 156, 153] +[:mouse_move, 503, 369, 2, 157, 157] +[:mouse_move, 504, 369, 2, 158, 158] +[:mouse_move, 505, 368, 2, 159, 158] +[:mouse_move, 508, 366, 2, 160, 158] +[:mouse_move, 512, 364, 2, 161, 159] +[:mouse_move, 513, 364, 2, 162, 159] +[:mouse_move, 514, 364, 2, 163, 159] +[:mouse_move, 515, 364, 2, 164, 160] +[:mouse_move, 519, 364, 2, 165, 161] +[:mouse_move, 526, 366, 2, 166, 161] +[:mouse_move, 538, 372, 2, 167, 161] +[:mouse_move, 550, 382, 2, 168, 161] +[:mouse_move, 563, 397, 2, 169, 162] +[:mouse_move, 570, 411, 2, 170, 162] +[:mouse_move, 574, 425, 2, 171, 162] +[:mouse_move, 576, 439, 2, 172, 163] +[:mouse_move, 576, 448, 2, 173, 163] +[:mouse_move, 576, 459, 2, 174, 163] +[:mouse_move, 576, 470, 2, 175, 163] +[:mouse_move, 576, 477, 2, 176, 163] +[:mouse_move, 576, 481, 2, 177, 163] +[:mouse_move, 576, 483, 2, 178, 163] +[:mouse_move, 576, 485, 2, 179, 164] +[:mouse_move, 576, 488, 2, 180, 164] +[:mouse_move, 576, 494, 2, 181, 164] +[:mouse_move, 577, 500, 2, 182, 164] +[:mouse_move, 577, 501, 2, 183, 164] +[:mouse_move, 579, 504, 2, 184, 164] +[:mouse_move, 579, 505, 2, 185, 164] +[:mouse_move, 581, 509, 2, 186, 165] +[:mouse_move, 583, 512, 2, 187, 165] +[:mouse_move, 584, 514, 2, 188, 165] +[:mouse_move, 585, 516, 2, 189, 165] +[:mouse_move, 586, 519, 2, 190, 165] +[:mouse_move, 587, 521, 2, 191, 165] +[:mouse_move, 588, 523, 2, 192, 166] +[:mouse_move, 588, 524, 2, 193, 166] +[:mouse_move, 588, 525, 2, 194, 166] +[:mouse_move, 588, 526, 2, 195, 167] +[:mouse_move, 588, 527, 2, 196, 167] +[:mouse_move, 588, 526, 2, 197, 173] +[:mouse_move, 586, 521, 2, 198, 173] +[:mouse_move, 586, 516, 2, 199, 174] +[:mouse_move, 585, 508, 2, 200, 174] +[:mouse_move, 582, 500, 2, 201, 174] +[:mouse_move, 578, 489, 2, 202, 174] +[:mouse_move, 573, 476, 2, 203, 175] +[:mouse_move, 568, 466, 2, 204, 175] +[:mouse_move, 566, 461, 2, 205, 176] +[:mouse_move, 565, 460, 2, 206, 176] +[:mouse_move, 564, 460, 2, 207, 176] +[:mouse_move, 563, 459, 2, 208, 176] +[:mouse_move, 562, 459, 2, 209, 177] +[:mouse_move, 561, 459, 2, 210, 177] +[:mouse_move, 549, 459, 2, 211, 177] +[:mouse_move, 522, 456, 2, 212, 177] +[:mouse_move, 484, 456, 2, 213, 177] +[:mouse_move, 423, 456, 2, 214, 177] +[:mouse_move, 385, 454, 2, 215, 177] +[:mouse_move, 359, 454, 2, 216, 178] +[:mouse_move, 345, 452, 2, 217, 178] +[:mouse_move, 343, 452, 2, 218, 178] +[:mouse_move, 342, 451, 2, 219, 180] +[:mouse_move, 343, 451, 2, 220, 180] +[:mouse_move, 344, 449, 2, 221, 180] +[:mouse_move, 348, 446, 2, 222, 180] +[:mouse_move, 352, 444, 2, 223, 180] +[:mouse_move, 362, 442, 2, 224, 181] +[:mouse_move, 369, 441, 2, 225, 181] +[:mouse_move, 376, 440, 2, 226, 181] +[:mouse_move, 381, 439, 2, 227, 182] +[:mouse_move, 385, 438, 2, 228, 182] +[:mouse_move, 386, 438, 2, 229, 182] +[:mouse_move, 387, 437, 2, 230, 183] +[:mouse_move, 387, 436, 2, 231, 183] +[:mouse_move, 388, 434, 2, 232, 183] +[:mouse_move, 388, 430, 2, 233, 183] +[:mouse_move, 387, 428, 2, 234, 183] +[:mouse_move, 387, 427, 2, 235, 183] +[:mouse_move, 386, 425, 2, 236, 184] +[:mouse_move, 383, 425, 2, 237, 184] +[:mouse_move, 382, 425, 2, 238, 185] +[:mouse_move, 381, 425, 2, 239, 185] +[:mouse_move, 380, 424, 2, 240, 185] +[:mouse_move, 379, 424, 2, 241, 187] +[:mouse_move, 378, 424, 2, 242, 189] +[:mouse_move, 377, 424, 2, 243, 192] +[:mouse_move, 376, 424, 2, 244, 192] +[:mouse_move, 375, 424, 2, 245, 194] +[:mouse_move, 374, 424, 2, 246, 195] +[:mouse_move, 373, 424, 2, 247, 196] +[:mouse_move, 372, 424, 2, 248, 197] +[:mouse_move, 370, 425, 2, 249, 197] +[:mouse_move, 368, 425, 2, 250, 198] +[:mouse_move, 367, 425, 2, 251, 198] +[:mouse_move, 366, 425, 2, 252, 198] +[:mouse_button_up, 1, 0, 1, 253, 203] +[:mouse_move, 365, 423, 2, 254, 204] +[:mouse_move, 360, 418, 2, 255, 204] +[:mouse_move, 356, 413, 2, 256, 205] +[:mouse_move, 350, 407, 2, 257, 205] +[:mouse_move, 344, 401, 2, 258, 205] +[:mouse_move, 337, 396, 2, 259, 206] +[:mouse_move, 326, 390, 2, 260, 206] +[:mouse_move, 311, 381, 2, 261, 207] +[:mouse_move, 303, 377, 2, 262, 207] +[:mouse_move, 297, 374, 2, 263, 207] +[:mouse_move, 296, 374, 2, 264, 207] +[:mouse_button_pressed, 1, 0, 1, 265, 211] +[:mouse_button_up, 1, 0, 1, 266, 212] +[:mouse_move, 297, 374, 2, 267, 213] +[:mouse_move, 298, 374, 2, 268, 220] +[:mouse_move, 300, 378, 2, 269, 221] +[:mouse_move, 301, 384, 2, 270, 221] +[:mouse_move, 301, 393, 2, 271, 222] +[:mouse_move, 301, 401, 2, 272, 222] +[:mouse_move, 301, 409, 2, 273, 223] +[:mouse_move, 301, 412, 2, 274, 223] +[:mouse_move, 301, 413, 2, 275, 224] +[:mouse_move, 301, 415, 2, 276, 224] +[:mouse_move, 302, 418, 2, 277, 225] +[:mouse_move, 303, 419, 2, 278, 225] +[:mouse_move, 303, 420, 2, 279, 226] +[:mouse_button_pressed, 1, 0, 1, 280, 228] +[:mouse_button_up, 1, 0, 1, 281, 230] +[:mouse_move, 303, 421, 2, 282, 230] +[:mouse_move, 303, 422, 2, 283, 231] +[:mouse_move, 303, 426, 2, 284, 231] +[:mouse_move, 302, 429, 2, 285, 232] +[:mouse_move, 302, 430, 2, 286, 232] +[:mouse_move, 302, 432, 2, 287, 232] +[:mouse_move, 302, 436, 2, 288, 233] +[:mouse_move, 302, 438, 2, 289, 233] +[:mouse_move, 302, 440, 2, 290, 233] +[:mouse_move, 302, 441, 2, 291, 234] +[:mouse_move, 302, 442, 2, 292, 234] +[:mouse_move, 302, 443, 2, 293, 235] +[:mouse_move, 302, 444, 2, 294, 236] +[:mouse_move, 302, 445, 2, 295, 236] +[:mouse_move, 303, 447, 2, 296, 237] +[:mouse_move, 304, 451, 2, 297, 237] +[:mouse_move, 304, 454, 2, 298, 237] +[:mouse_move, 304, 456, 2, 299, 238] +[:mouse_move, 304, 458, 2, 300, 238] +[:mouse_move, 304, 460, 2, 301, 238] +[:mouse_move, 304, 463, 2, 302, 239] +[:mouse_button_pressed, 1, 0, 1, 303, 242] +[:mouse_button_up, 1, 0, 1, 304, 244] +[:mouse_move, 304, 464, 2, 305, 244] +[:mouse_move, 304, 465, 2, 306, 245] +[:mouse_move, 304, 470, 2, 307, 246] +[:mouse_move, 304, 476, 2, 308, 246] +[:mouse_move, 303, 485, 2, 309, 246] +[:mouse_move, 301, 495, 2, 310, 247] +[:mouse_move, 300, 500, 2, 311, 247] +[:mouse_move, 300, 503, 2, 312, 247] +[:mouse_move, 300, 506, 2, 313, 248] +[:mouse_move, 301, 508, 2, 314, 248] +[:mouse_move, 302, 510, 2, 315, 248] +[:mouse_move, 302, 511, 2, 316, 249] +[:mouse_move, 303, 512, 2, 317, 249] +[:mouse_move, 303, 513, 2, 318, 251] +[:mouse_button_pressed, 1, 0, 1, 319, 253] +[:mouse_button_up, 1, 0, 1, 320, 255] +[:mouse_move, 303, 512, 2, 321, 255] +[:mouse_move, 304, 511, 2, 322, 265] +[:mouse_move, 305, 511, 2, 323, 265] +[:mouse_move, 307, 510, 2, 324, 266] +[:mouse_move, 311, 509, 2, 325, 266] +[:mouse_move, 315, 505, 2, 326, 266] +[:mouse_move, 317, 504, 2, 327, 267] +[:mouse_move, 317, 503, 2, 328, 268] +[:mouse_move, 316, 503, 2, 329, 269] +[:mouse_move, 316, 502, 2, 330, 289] +[:mouse_move, 317, 501, 2, 331, 291] +[:mouse_move, 318, 501, 2, 332, 292] +[:mouse_move, 319, 501, 2, 333, 302] +[:mouse_move, 319, 500, 2, 334, 303] +[:key_down_raw, 96, 0, 2, 335, 303] +[:mouse_move, 320, 500, 2, 336, 304] +[:mouse_move, 323, 498, 2, 337, 304] +[:mouse_move, 331, 496, 2, 338, 305] +[:key_up_raw, 96, 0, 2, 339, 305] +[:mouse_move, 341, 493, 2, 340, 305] +[:mouse_move, 351, 489, 2, 341, 305] +[:mouse_move, 363, 484, 2, 342, 306] +[:mouse_move, 372, 482, 2, 343, 306] +[:mouse_move, 384, 479, 2, 344, 306] +[:mouse_move, 395, 479, 2, 345, 307] +[:mouse_move, 402, 477, 2, 346, 307] +[:mouse_move, 406, 475, 2, 347, 308] +[:mouse_move, 403, 475, 2, 348, 308] +[:mouse_move, 397, 473, 2, 349, 309] +[:mouse_move, 394, 467, 2, 350, 311] +[:mouse_move, 393, 467, 2, 351, 311] +[:mouse_move, 397, 466, 2, 352, 312] +[:mouse_move, 398, 465, 2, 353, 313] +[:mouse_move, 399, 465, 2, 354, 313] +[:mouse_move, 399, 464, 2, 355, 313] +[:mouse_move, 400, 464, 2, 356, 314] +[:mouse_move, 400, 463, 2, 357, 316] +[:mouse_move, 401, 463, 2, 358, 318] +[:mouse_move, 401, 462, 2, 359, 319] +[:key_down_raw, 13, 0, 2, 360, 322] diff --git a/samples/13_path_finding_algorithms/05_dijkstra/app/main.rb b/samples/13_path_finding_algorithms/05_dijkstra/app/main.rb index b335447..1223779 100644 --- a/samples/13_path_finding_algorithms/05_dijkstra/app/main.rb +++ b/samples/13_path_finding_algorithms/05_dijkstra/app/main.rb @@ -19,8 +19,8 @@ class Movement_Costs # The next step in the search is calculated def tick defaults - render - input + render + input calc end @@ -37,7 +37,7 @@ class Movement_Costs # Walls are stored in a hash for quick look up when doing the search state.star ||= [1, 5] state.target ||= [8, 4] - state.walls ||= {[1, 1] => true, [2, 1] => true, [3, 1] => true, [1, 2] => true, [2, 2] => true, [3, 2] => true} + state.walls ||= {[1, 1] => true, [2, 1] => true, [3, 1] => true, [1, 2] => true, [2, 2] => true, [3, 2] => true} state.hills ||= { [4, 1] => true, [5, 1] => true, @@ -72,7 +72,7 @@ class Movement_Costs # We store this value, because we want to remember the value even when # the user's cursor is no longer over what they're interacting with, but # they are still clicking down on the mouse. - state.user_input ||= :none + state.user_input ||= :none # Values that are used for the breadth first search # Keeping track of what cells were visited prevents counting cells multiple times @@ -96,7 +96,7 @@ class Movement_Costs # Draws everything onto the screen def render - render_background + render_background render_heat_maps @@ -111,8 +111,8 @@ class Movement_Costs # Draws what the grid looks like with nothing on it def render_background - render_unvisited - render_grid_lines + render_unvisited + render_grid_lines render_labels end @@ -131,7 +131,7 @@ class Movement_Costs end for y in 0..grid.height - outputs.lines << horizontal_line(y) + outputs.lines << horizontal_line(y) outputs.lines << shifted_horizontal_line(y) end end @@ -244,16 +244,16 @@ class Movement_Costs def render_star outputs.sprites << [scale_up(state.star), 'star.png'] outputs.sprites << [move_and_scale_up(state.star), 'star.png'] - end + end # Renders the target on both grids def render_target outputs.sprites << [scale_up(state.target), 'target.png'] outputs.sprites << [move_and_scale_up(state.target), 'target.png'] - end + end def render_hills - state.hills.each_key do |hill| + state.hills.each_key do |hill| outputs.solids << [scale_up(hill), hill_color] outputs.solids << [move_and_scale_up(hill), hill_color] end @@ -261,7 +261,7 @@ class Movement_Costs # Draws the walls on both grids def render_walls - state.walls.each_key do |wall| + state.walls.each_key do |wall| outputs.solids << [scale_up(wall), wall_color] outputs.solids << [move_and_scale_up(wall), wall_color] end @@ -344,7 +344,7 @@ class Movement_Costs # If the mouse was clicked this tick if inputs.mouse.down # Determine what the user is editing and edit the state.user_input variable - determine_input + determine_input end # Process user input based on user_input variable and current mouse position @@ -357,43 +357,43 @@ class Movement_Costs # mouse left click is held def determine_input # If the mouse is over the star in the first grid - if mouse_over_star? + if mouse_over_star? # The user is editing the star from the first grid - state.user_input = :star + state.user_input = :star # If the mouse is over the star in the second grid - elsif mouse_over_star2? + elsif mouse_over_star2? # The user is editing the star from the second grid - state.user_input = :star2 + state.user_input = :star2 # If the mouse is over the target in the first grid - elsif mouse_over_target? + elsif mouse_over_target? # The user is editing the target from the first grid - state.user_input = :target + state.user_input = :target # If the mouse is over the target in the second grid - elsif mouse_over_target2? + elsif mouse_over_target2? # The user is editing the target from the second grid - state.user_input = :target2 + state.user_input = :target2 # If the mouse is over a wall in the first grid - elsif mouse_over_wall? + elsif mouse_over_wall? # The user is removing a wall from the first grid - state.user_input = :remove_wall + state.user_input = :remove_wall # If the mouse is over a wall in the second grid - elsif mouse_over_wall2? + elsif mouse_over_wall2? # The user is removing a wall from the second grid state.user_input = :remove_wall2 # If the mouse is over a hill in the first grid - elsif mouse_over_hill? + elsif mouse_over_hill? # The user is adding a wall from the first grid - state.user_input = :add_wall + state.user_input = :add_wall # If the mouse is over a hill in the second grid - elsif mouse_over_hill2? + elsif mouse_over_hill2? # The user is adding a wall from the second grid state.user_input = :add_wall2 # If the mouse is over the first grid - elsif mouse_over_grid? + elsif mouse_over_grid? # The user is adding a hill from the first grid state.user_input = :add_hill # If the mouse is over the second grid - elsif mouse_over_grid2? + elsif mouse_over_grid2? # The user is adding a hill from the second grid state.user_input = :add_hill2 end @@ -401,26 +401,26 @@ class Movement_Costs # Processes click and drag based on what the user is currently dragging def process_input - if state.user_input == :star - input_star + if state.user_input == :star + input_star elsif state.user_input == :star2 - input_star2 - elsif state.user_input == :target - input_target - elsif state.user_input == :target2 - input_target2 - elsif state.user_input == :remove_wall - input_remove_wall + input_star2 + elsif state.user_input == :target + input_target + elsif state.user_input == :target2 + input_target2 + elsif state.user_input == :remove_wall + input_remove_wall elsif state.user_input == :remove_wall2 - input_remove_wall2 - elsif state.user_input == :add_hill - input_add_hill - elsif state.user_input == :add_hill2 - input_add_hill2 - elsif state.user_input == :add_wall - input_add_wall - elsif state.user_input == :add_wall2 - input_add_wall2 + input_remove_wall2 + elsif state.user_input == :add_hill + input_add_hill + elsif state.user_input == :add_hill2 + input_add_hill2 + elsif state.user_input == :add_wall + input_add_wall + elsif state.user_input == :add_wall2 + input_add_wall2 end end @@ -433,26 +433,26 @@ class Movement_Costs calc_dijkstra end end - + def calc_breadth_first # Sets up the Breadth First Search - breadth_first_search.visited[state.star] = true - breadth_first_search.frontier << state.star + breadth_first_search.visited[state.star] = true + breadth_first_search.frontier << state.star breadth_first_search.came_from[state.star] = nil until breadth_first_search.frontier.empty? return if breadth_first_search.visited.has_key?(state.target) # A step in the search # Takes the next frontier cell - new_frontier = breadth_first_search.frontier.shift + new_frontier = breadth_first_search.frontier.shift # For each of its neighbors - adjacent_neighbors(new_frontier).each do | neighbor | + adjacent_neighbors(new_frontier).each do | neighbor | # That have not been visited and are not walls - unless breadth_first_search.visited.has_key?(neighbor) || state.walls.has_key?(neighbor) + unless breadth_first_search.visited.has_key?(neighbor) || state.walls.has_key?(neighbor) # Add them to the frontier and mark them as visited in the first grid - breadth_first_search.visited[neighbor] = true - breadth_first_search.frontier << neighbor + breadth_first_search.visited[neighbor] = true + breadth_first_search.frontier << neighbor # Remember which cell the neighbor came from breadth_first_search.came_from[neighbor] = new_frontier end @@ -512,12 +512,12 @@ class Movement_Costs # Only resets the search if the star changes position # Called whenever the user is editing the star (puts mouse down on star) def input_star - old_star = state.star.clone + old_star = state.star.clone unless cell_closest_to_mouse == state.target - state.star = cell_closest_to_mouse + state.star = cell_closest_to_mouse end - unless old_star == state.star - reset_search + unless old_star == state.star + reset_search end end @@ -525,12 +525,12 @@ class Movement_Costs # Only resets the search if the star changes position # Called whenever the user is editing the star (puts mouse down on star) def input_star2 - old_star = state.star.clone + old_star = state.star.clone unless cell_closest_to_mouse2 == state.target state.star = cell_closest_to_mouse2 end - unless old_star == state.star - reset_search + unless old_star == state.star + reset_search end end @@ -538,12 +538,12 @@ class Movement_Costs # Only reset_searchs the search if the target changes position # Called whenever the user is editing the target (puts mouse down on target) def input_target - old_target = state.target.clone + old_target = state.target.clone unless cell_closest_to_mouse == state.star state.target = cell_closest_to_mouse end - unless old_target == state.target - reset_search + unless old_target == state.target + reset_search end end @@ -551,12 +551,12 @@ class Movement_Costs # Only reset_searchs the search if the target changes position # Called whenever the user is editing the target (puts mouse down on target) def input_target2 - old_target = state.target.clone + old_target = state.target.clone unless cell_closest_to_mouse2 == state.star state.target = cell_closest_to_mouse2 end - unless old_target == state.target - reset_search + unless old_target == state.target + reset_search end end @@ -565,11 +565,11 @@ class Movement_Costs # The mouse needs to be inside the grid, because we only want to remove walls # the cursor is directly over # Recalculations should only occur when a wall is actually deleted - if mouse_over_grid? + if mouse_over_grid? if state.walls.has_key?(cell_closest_to_mouse) or state.hills.has_key?(cell_closest_to_mouse) - state.walls.delete(cell_closest_to_mouse) - state.hills.delete(cell_closest_to_mouse) - reset_search + state.walls.delete(cell_closest_to_mouse) + state.hills.delete(cell_closest_to_mouse) + reset_search end end end @@ -579,21 +579,21 @@ class Movement_Costs # The mouse needs to be inside the grid, because we only want to remove walls # the cursor is directly over # Recalculations should only occur when a wall is actually deleted - if mouse_over_grid2? + if mouse_over_grid2? if state.walls.has_key?(cell_closest_to_mouse2) or state.hills.has_key?(cell_closest_to_mouse2) - state.walls.delete(cell_closest_to_mouse2) - state.hills.delete(cell_closest_to_mouse2) - reset_search + state.walls.delete(cell_closest_to_mouse2) + state.hills.delete(cell_closest_to_mouse2) + reset_search end end end # Adds a hill in the first grid in the cell the mouse is over def input_add_hill - if mouse_over_grid? + if mouse_over_grid? unless state.hills.has_key?(cell_closest_to_mouse) - state.hills[cell_closest_to_mouse] = true - reset_search + state.hills[cell_closest_to_mouse] = true + reset_search end end end @@ -601,32 +601,32 @@ class Movement_Costs # Adds a hill in the second grid in the cell the mouse is over def input_add_hill2 - if mouse_over_grid2? + if mouse_over_grid2? unless state.hills.has_key?(cell_closest_to_mouse2) - state.hills[cell_closest_to_mouse2] = true - reset_search + state.hills[cell_closest_to_mouse2] = true + reset_search end end end # Adds a wall in the first grid in the cell the mouse is over def input_add_wall - if mouse_over_grid? + if mouse_over_grid? unless state.walls.has_key?(cell_closest_to_mouse) - state.hills.delete(cell_closest_to_mouse) - state.walls[cell_closest_to_mouse] = true - reset_search + state.hills.delete(cell_closest_to_mouse) + state.walls[cell_closest_to_mouse] = true + reset_search end end end # Adds a wall in the second grid in the cell the mouse is over def input_add_wall2 - if mouse_over_grid2? + if mouse_over_grid2? unless state.walls.has_key?(cell_closest_to_mouse2) - state.hills.delete(cell_closest_to_mouse2) - state.walls[cell_closest_to_mouse2] = true - reset_search + state.hills.delete(cell_closest_to_mouse2) + state.walls[cell_closest_to_mouse2] = true + reset_search end end end @@ -649,21 +649,21 @@ class Movement_Costs # Returns a list of adjacent cells # Used to determine what the next cells to be added to the frontier are def adjacent_neighbors(cell) - neighbors = [] + neighbors = [] # Gets all the valid neighbors into the array # From southern neighbor, clockwise - neighbors << [cell.x , cell.y - 1] unless cell.y == 0 - neighbors << [cell.x - 1, cell.y ] unless cell.x == 0 - neighbors << [cell.x , cell.y + 1] unless cell.y == grid.height - 1 - neighbors << [cell.x + 1, cell.y ] unless cell.x == grid.width - 1 + neighbors << [cell.x , cell.y - 1] unless cell.y == 0 + neighbors << [cell.x - 1, cell.y ] unless cell.x == 0 + neighbors << [cell.x , cell.y + 1] unless cell.y == grid.height - 1 + neighbors << [cell.x + 1, cell.y ] unless cell.x == grid.width - 1 # Sorts the neighbors so the rendered path is a zigzag path # Cells in a diagonal direction are given priority # Comment this line to see the difference neighbors = neighbors.sort_by { |neighbor_x, neighbor_y| proximity_to_star(neighbor_x, neighbor_y) } - neighbors + neighbors end # Finds the vertical and horizontal distance of a cell from the star @@ -688,13 +688,13 @@ class Movement_Costs # Finding the cell closest to the mouse helps with this def cell_closest_to_mouse # Closest cell to the mouse in the first grid - x = (inputs.mouse.point.x / grid.cell_size).to_i - y = (inputs.mouse.point.y / grid.cell_size).to_i + x = (inputs.mouse.point.x / grid.cell_size).to_i + y = (inputs.mouse.point.y / grid.cell_size).to_i # Bound x and y to the grid - x = grid.width - 1 if x > grid.width - 1 - y = grid.height - 1 if y > grid.height - 1 + x = grid.width - 1 if x > grid.width - 1 + y = grid.height - 1 if y > grid.height - 1 # Return closest cell - [x, y] + [x, y] end # When the user grabs the star and puts their cursor to the far right @@ -702,17 +702,17 @@ class Movement_Costs # Finding the cell closest to the mouse in the second grid helps with this def cell_closest_to_mouse2 # Closest cell grid to the mouse in the second - x = (inputs.mouse.point.x / grid.cell_size).to_i - y = (inputs.mouse.point.y / grid.cell_size).to_i + x = (inputs.mouse.point.x / grid.cell_size).to_i + y = (inputs.mouse.point.y / grid.cell_size).to_i # Translate the cell to the first grid x -= grid.width + 1 # Bound x and y to the first grid x = 0 if x < 0 y = 0 if y < 0 - x = grid.width - 1 if x > grid.width - 1 - y = grid.height - 1 if y > grid.height - 1 + x = grid.width - 1 if x > grid.width - 1 + y = grid.height - 1 if y > grid.height - 1 # Return closest cell - [x, y] + [x, y] end # Signal that the user is going to be moving the star from the first grid @@ -785,12 +785,12 @@ class Movement_Costs # Light brown def unvisited_color - [221, 212, 213] + [221, 212, 213] end # Camo Green def wall_color - [134, 134, 120] + [134, 134, 120] end # Pastel White @@ -833,7 +833,7 @@ def tick args end # Every tick, new args are passed, and the Dijkstra tick method is called - $movement_costs ||= Movement_Costs.new(args) + $movement_costs ||= Movement_Costs.new $movement_costs.args = args $movement_costs.tick end diff --git a/samples/13_path_finding_algorithms/05_dijkstra/replay.txt b/samples/13_path_finding_algorithms/05_dijkstra/replay.txt new file mode 100644 index 0000000..a459873 --- /dev/null +++ b/samples/13_path_finding_algorithms/05_dijkstra/replay.txt @@ -0,0 +1,686 @@ +replay_version 2.0 +stopped_at 730 +seed 100 +recorded_at 2021-11-20 11:20:27 -0600 +[:mouse_button_up, 1, 0, 1, 1, 1] +[:mouse_move, 782, 97, 2, 2, 14] +[:mouse_move, 782, 98, 2, 3, 15] +[:mouse_move, 782, 99, 2, 4, 15] +[:mouse_move, 782, 100, 2, 5, 16] +[:mouse_move, 780, 102, 2, 6, 16] +[:mouse_move, 773, 111, 2, 7, 17] +[:mouse_move, 768, 123, 2, 8, 17] +[:mouse_move, 759, 142, 2, 9, 18] +[:mouse_move, 740, 166, 2, 10, 18] +[:mouse_move, 718, 196, 2, 11, 19] +[:mouse_move, 699, 232, 2, 12, 19] +[:mouse_move, 686, 272, 2, 13, 20] +[:mouse_move, 673, 314, 2, 14, 20] +[:mouse_move, 648, 355, 2, 15, 21] +[:mouse_move, 594, 404, 2, 16, 21] +[:mouse_move, 562, 427, 2, 17, 22] +[:mouse_move, 532, 446, 2, 18, 22] +[:mouse_move, 509, 458, 2, 19, 23] +[:mouse_move, 490, 464, 2, 20, 23] +[:mouse_move, 482, 466, 2, 21, 23] +[:mouse_move, 481, 466, 2, 22, 24] +[:mouse_move, 481, 460, 2, 23, 25] +[:mouse_move, 490, 451, 2, 24, 26] +[:mouse_move, 501, 443, 2, 25, 26] +[:mouse_move, 506, 441, 2, 26, 26] +[:mouse_move, 506, 442, 2, 27, 29] +[:mouse_move, 507, 442, 2, 28, 31] +[:mouse_move, 508, 442, 2, 29, 32] +[:mouse_move, 509, 442, 2, 30, 37] +[:mouse_move, 510, 442, 2, 31, 48] +[:mouse_move, 507, 442, 2, 32, 63] +[:mouse_move, 500, 444, 2, 33, 63] +[:mouse_move, 488, 446, 2, 34, 64] +[:mouse_move, 476, 447, 2, 35, 64] +[:mouse_move, 466, 449, 2, 36, 65] +[:mouse_move, 459, 450, 2, 37, 65] +[:mouse_move, 449, 452, 2, 38, 66] +[:mouse_move, 440, 453, 2, 39, 66] +[:mouse_move, 433, 454, 2, 40, 67] +[:mouse_move, 432, 454, 2, 41, 67] +[:mouse_move, 436, 455, 2, 42, 69] +[:mouse_move, 442, 455, 2, 43, 69] +[:mouse_move, 446, 455, 2, 44, 70] +[:mouse_move, 450, 455, 2, 45, 70] +[:mouse_move, 456, 448, 2, 46, 70] +[:mouse_move, 458, 437, 2, 47, 71] +[:mouse_move, 458, 422, 2, 48, 72] +[:mouse_move, 451, 402, 2, 49, 72] +[:mouse_move, 440, 376, 2, 50, 72] +[:mouse_move, 414, 334, 2, 51, 73] +[:mouse_move, 393, 303, 2, 52, 74] +[:mouse_move, 378, 280, 2, 53, 74] +[:mouse_move, 367, 265, 2, 54, 75] +[:mouse_move, 358, 255, 2, 55, 75] +[:mouse_move, 353, 251, 2, 56, 75] +[:mouse_move, 349, 248, 2, 57, 76] +[:mouse_move, 348, 248, 2, 58, 76] +[:mouse_move, 345, 249, 2, 59, 77] +[:mouse_move, 344, 249, 2, 60, 78] +[:mouse_move, 338, 246, 2, 61, 79] +[:mouse_move, 332, 240, 2, 62, 79] +[:mouse_move, 328, 231, 2, 63, 80] +[:mouse_move, 326, 222, 2, 64, 80] +[:mouse_move, 326, 214, 2, 65, 81] +[:mouse_move, 331, 208, 2, 66, 81] +[:mouse_move, 340, 204, 2, 67, 82] +[:mouse_move, 348, 202, 2, 68, 82] +[:mouse_move, 357, 202, 2, 69, 83] +[:mouse_move, 363, 202, 2, 70, 84] +[:mouse_move, 365, 202, 2, 71, 84] +[:mouse_move, 366, 202, 2, 72, 84] +[:mouse_move, 374, 203, 2, 73, 85] +[:mouse_move, 380, 204, 2, 74, 85] +[:mouse_move, 382, 204, 2, 75, 86] +[:mouse_move, 383, 204, 2, 76, 86] +[:mouse_button_pressed, 1, 0, 1, 77, 88] +[:mouse_button_up, 1, 0, 1, 78, 89] +[:mouse_move, 384, 204, 2, 79, 99] +[:mouse_move, 384, 205, 2, 80, 100] +[:mouse_move, 389, 210, 2, 81, 101] +[:mouse_move, 394, 214, 2, 82, 101] +[:mouse_move, 399, 220, 2, 83, 101] +[:mouse_move, 405, 228, 2, 84, 102] +[:mouse_move, 410, 242, 2, 85, 103] +[:mouse_move, 416, 261, 2, 86, 103] +[:mouse_move, 422, 276, 2, 87, 104] +[:mouse_move, 428, 284, 2, 88, 104] +[:mouse_move, 430, 287, 2, 89, 104] +[:mouse_move, 431, 288, 2, 90, 105] +[:mouse_move, 433, 290, 2, 91, 105] +[:mouse_move, 434, 295, 2, 92, 106] +[:mouse_move, 435, 306, 2, 93, 106] +[:mouse_move, 436, 311, 2, 94, 107] +[:mouse_move, 436, 312, 2, 95, 108] +[:mouse_move, 438, 314, 2, 96, 112] +[:mouse_move, 441, 320, 2, 97, 113] +[:mouse_move, 447, 341, 2, 98, 113] +[:mouse_move, 453, 376, 2, 99, 114] +[:mouse_move, 456, 413, 2, 100, 114] +[:mouse_move, 456, 445, 2, 101, 115] +[:mouse_move, 455, 475, 2, 102, 115] +[:mouse_move, 450, 498, 2, 103, 116] +[:mouse_move, 446, 519, 2, 104, 116] +[:mouse_move, 446, 541, 2, 105, 117] +[:mouse_move, 452, 559, 2, 106, 117] +[:mouse_move, 458, 569, 2, 107, 117] +[:mouse_move, 464, 573, 2, 108, 118] +[:mouse_move, 468, 573, 2, 109, 119] +[:mouse_move, 471, 570, 2, 110, 119] +[:mouse_move, 474, 559, 2, 111, 120] +[:mouse_move, 476, 539, 2, 112, 120] +[:mouse_move, 483, 527, 2, 113, 120] +[:mouse_move, 489, 519, 2, 114, 121] +[:mouse_move, 493, 515, 2, 115, 121] +[:mouse_move, 493, 511, 2, 116, 122] +[:mouse_move, 493, 505, 2, 117, 122] +[:mouse_move, 493, 499, 2, 118, 123] +[:mouse_move, 490, 496, 2, 119, 123] +[:mouse_move, 488, 493, 2, 120, 124] +[:mouse_move, 487, 493, 2, 121, 124] +[:mouse_move, 484, 493, 2, 122, 125] +[:mouse_move, 482, 493, 2, 123, 125] +[:mouse_move, 479, 494, 2, 124, 126] +[:mouse_move, 474, 495, 2, 125, 126] +[:mouse_move, 470, 499, 2, 126, 127] +[:mouse_move, 470, 503, 2, 127, 127] +[:mouse_move, 470, 506, 2, 128, 128] +[:mouse_button_pressed, 1, 0, 1, 129, 131] +[:mouse_button_up, 1, 0, 1, 130, 132] +[:mouse_move, 470, 503, 2, 131, 135] +[:mouse_move, 470, 495, 2, 132, 135] +[:mouse_move, 470, 488, 2, 133, 135] +[:mouse_move, 472, 478, 2, 134, 136] +[:mouse_move, 473, 470, 2, 135, 137] +[:mouse_move, 474, 459, 2, 136, 137] +[:mouse_move, 474, 450, 2, 137, 138] +[:mouse_move, 474, 445, 2, 138, 138] +[:mouse_move, 472, 441, 2, 139, 138] +[:mouse_move, 470, 439, 2, 140, 139] +[:mouse_move, 467, 438, 2, 141, 139] +[:mouse_move, 465, 438, 2, 142, 140] +[:mouse_move, 464, 438, 2, 143, 140] +[:mouse_move, 463, 438, 2, 144, 141] +[:mouse_move, 460, 438, 2, 145, 141] +[:mouse_move, 459, 438, 2, 146, 142] +[:mouse_button_pressed, 1, 0, 1, 147, 144] +[:mouse_button_up, 1, 0, 1, 148, 145] +[:mouse_move, 459, 439, 2, 149, 153] +[:mouse_move, 459, 438, 2, 150, 164] +[:mouse_move, 458, 434, 2, 151, 164] +[:mouse_move, 458, 426, 2, 152, 165] +[:mouse_move, 458, 414, 2, 153, 165] +[:mouse_move, 461, 400, 2, 154, 166] +[:mouse_move, 461, 397, 2, 155, 166] +[:mouse_move, 461, 396, 2, 156, 166] +[:mouse_move, 461, 395, 2, 157, 167] +[:mouse_button_pressed, 1, 0, 1, 158, 170] +[:mouse_button_up, 1, 0, 1, 159, 171] +[:mouse_move, 461, 394, 2, 160, 174] +[:mouse_move, 461, 391, 2, 161, 175] +[:mouse_move, 461, 387, 2, 162, 175] +[:mouse_move, 461, 381, 2, 163, 176] +[:mouse_move, 461, 379, 2, 164, 176] +[:mouse_move, 461, 378, 2, 165, 177] +[:mouse_move, 461, 377, 2, 166, 177] +[:mouse_move, 461, 375, 2, 167, 179] +[:mouse_move, 461, 374, 2, 168, 179] +[:mouse_move, 461, 373, 2, 169, 180] +[:mouse_move, 461, 372, 2, 170, 181] +[:mouse_move, 461, 370, 2, 171, 181] +[:mouse_move, 460, 365, 2, 172, 182] +[:mouse_move, 460, 362, 2, 173, 182] +[:mouse_move, 460, 359, 2, 174, 182] +[:mouse_move, 460, 358, 2, 175, 184] +[:mouse_move, 459, 356, 2, 176, 185] +[:mouse_move, 459, 355, 2, 177, 186] +[:mouse_move, 459, 352, 2, 178, 186] +[:mouse_move, 459, 351, 2, 179, 187] +[:mouse_move, 458, 350, 2, 180, 187] +[:mouse_move, 458, 349, 2, 181, 187] +[:mouse_move, 457, 352, 2, 182, 191] +[:mouse_move, 456, 369, 2, 183, 192] +[:mouse_move, 456, 381, 2, 184, 192] +[:mouse_move, 456, 393, 2, 185, 193] +[:mouse_move, 460, 412, 2, 186, 193] +[:mouse_move, 466, 429, 2, 187, 193] +[:mouse_move, 471, 448, 2, 188, 194] +[:mouse_move, 472, 464, 2, 189, 194] +[:mouse_move, 473, 477, 2, 190, 195] +[:mouse_move, 474, 488, 2, 191, 196] +[:mouse_move, 474, 497, 2, 192, 196] +[:mouse_move, 474, 499, 2, 193, 196] +[:mouse_move, 472, 504, 2, 194, 197] +[:mouse_move, 470, 513, 2, 195, 197] +[:mouse_move, 470, 516, 2, 196, 197] +[:mouse_move, 470, 517, 2, 197, 198] +[:mouse_move, 470, 519, 2, 198, 199] +[:mouse_move, 470, 521, 2, 199, 199] +[:mouse_move, 470, 522, 2, 200, 200] +[:mouse_move, 470, 523, 2, 201, 201] +[:mouse_move, 467, 521, 2, 202, 203] +[:mouse_move, 464, 518, 2, 203, 203] +[:mouse_move, 462, 515, 2, 204, 204] +[:mouse_move, 461, 511, 2, 205, 205] +[:mouse_button_pressed, 1, 0, 1, 206, 210] +[:mouse_button_up, 1, 0, 1, 207, 211] +[:mouse_move, 462, 511, 2, 208, 218] +[:mouse_move, 465, 510, 2, 209, 218] +[:mouse_move, 470, 508, 2, 210, 218] +[:mouse_move, 475, 505, 2, 211, 219] +[:mouse_move, 483, 502, 2, 212, 219] +[:mouse_move, 493, 498, 2, 213, 220] +[:mouse_move, 506, 491, 2, 214, 221] +[:mouse_move, 517, 479, 2, 215, 221] +[:mouse_move, 521, 471, 2, 216, 221] +[:mouse_move, 523, 467, 2, 217, 222] +[:mouse_move, 523, 464, 2, 218, 222] +[:mouse_move, 522, 464, 2, 219, 227] +[:mouse_move, 521, 464, 2, 220, 227] +[:mouse_move, 518, 464, 2, 221, 228] +[:mouse_move, 513, 460, 2, 222, 228] +[:mouse_move, 513, 459, 2, 223, 228] +[:mouse_move, 512, 459, 2, 224, 229] +[:mouse_move, 512, 458, 2, 225, 229] +[:mouse_button_pressed, 1, 0, 1, 226, 232] +[:mouse_move, 513, 458, 2, 227, 233] +[:mouse_move, 514, 458, 2, 228, 234] +[:mouse_move, 516, 458, 2, 229, 234] +[:mouse_move, 517, 458, 2, 230, 235] +[:mouse_move, 523, 453, 2, 231, 235] +[:mouse_move, 531, 444, 2, 232, 235] +[:mouse_move, 537, 436, 2, 233, 236] +[:mouse_move, 541, 428, 2, 234, 236] +[:mouse_move, 543, 421, 2, 235, 237] +[:mouse_move, 545, 413, 2, 236, 237] +[:mouse_move, 546, 405, 2, 237, 237] +[:mouse_move, 547, 396, 2, 238, 237] +[:mouse_move, 547, 389, 2, 239, 237] +[:mouse_move, 547, 383, 2, 240, 237] +[:mouse_move, 547, 379, 2, 241, 238] +[:mouse_move, 547, 378, 2, 242, 238] +[:mouse_move, 547, 376, 2, 243, 238] +[:mouse_move, 546, 375, 2, 244, 238] +[:mouse_move, 546, 374, 2, 245, 238] +[:mouse_move, 546, 372, 2, 246, 239] +[:mouse_move, 545, 368, 2, 247, 239] +[:mouse_move, 544, 366, 2, 248, 239] +[:mouse_move, 543, 363, 2, 249, 240] +[:mouse_move, 540, 357, 2, 250, 240] +[:mouse_move, 534, 350, 2, 251, 241] +[:mouse_move, 528, 344, 2, 252, 241] +[:mouse_move, 520, 339, 2, 253, 241] +[:mouse_move, 517, 339, 2, 254, 241] +[:mouse_move, 514, 337, 2, 255, 241] +[:mouse_move, 513, 337, 2, 256, 242] +[:mouse_move, 511, 336, 2, 257, 242] +[:mouse_move, 509, 336, 2, 258, 242] +[:mouse_move, 508, 336, 2, 259, 242] +[:mouse_move, 507, 336, 2, 260, 242] +[:mouse_move, 505, 335, 2, 261, 242] +[:mouse_move, 502, 335, 2, 262, 243] +[:mouse_move, 498, 335, 2, 263, 244] +[:mouse_move, 494, 335, 2, 264, 244] +[:mouse_move, 484, 335, 2, 265, 244] +[:mouse_move, 475, 335, 2, 266, 245] +[:mouse_move, 469, 335, 2, 267, 245] +[:mouse_move, 459, 338, 2, 268, 246] +[:mouse_move, 451, 342, 2, 269, 246] +[:mouse_move, 441, 347, 2, 270, 246] +[:mouse_move, 430, 352, 2, 271, 246] +[:mouse_move, 421, 357, 2, 272, 247] +[:mouse_move, 408, 366, 2, 273, 247] +[:mouse_move, 398, 375, 2, 274, 247] +[:mouse_move, 390, 386, 2, 275, 248] +[:mouse_move, 380, 402, 2, 276, 248] +[:mouse_move, 374, 412, 2, 277, 248] +[:mouse_move, 368, 420, 2, 278, 248] +[:mouse_move, 364, 427, 2, 279, 248] +[:mouse_move, 362, 437, 2, 280, 249] +[:mouse_move, 362, 448, 2, 281, 249] +[:mouse_move, 362, 455, 2, 282, 249] +[:mouse_move, 362, 463, 2, 283, 249] +[:mouse_move, 362, 467, 2, 284, 249] +[:mouse_move, 362, 473, 2, 285, 250] +[:mouse_move, 364, 483, 2, 286, 250] +[:mouse_move, 368, 490, 2, 287, 251] +[:mouse_move, 372, 496, 2, 288, 251] +[:mouse_move, 379, 505, 2, 289, 251] +[:mouse_move, 384, 509, 2, 290, 251] +[:mouse_move, 385, 511, 2, 291, 251] +[:mouse_move, 387, 511, 2, 292, 252] +[:mouse_move, 387, 512, 2, 293, 252] +[:mouse_move, 388, 512, 2, 294, 253] +[:mouse_move, 390, 514, 2, 295, 254] +[:mouse_move, 392, 516, 2, 296, 254] +[:mouse_move, 392, 517, 2, 297, 254] +[:mouse_move, 393, 518, 2, 298, 255] +[:mouse_move, 394, 520, 2, 299, 255] +[:mouse_move, 395, 523, 2, 300, 256] +[:mouse_move, 395, 527, 2, 301, 257] +[:mouse_move, 395, 533, 2, 302, 257] +[:mouse_move, 392, 542, 2, 303, 258] +[:mouse_move, 392, 555, 2, 304, 258] +[:mouse_move, 392, 567, 2, 305, 258] +[:mouse_move, 392, 576, 2, 306, 259] +[:mouse_move, 392, 583, 2, 307, 259] +[:mouse_move, 392, 587, 2, 308, 259] +[:mouse_move, 392, 590, 2, 309, 259] +[:mouse_move, 392, 592, 2, 310, 260] +[:mouse_move, 391, 594, 2, 311, 260] +[:mouse_move, 391, 595, 2, 312, 261] +[:mouse_move, 389, 597, 2, 313, 262] +[:mouse_move, 382, 602, 2, 314, 262] +[:mouse_move, 372, 608, 2, 315, 263] +[:mouse_move, 359, 612, 2, 316, 263] +[:mouse_move, 345, 619, 2, 317, 263] +[:mouse_move, 329, 626, 2, 318, 263] +[:mouse_move, 314, 633, 2, 319, 263] +[:mouse_move, 301, 639, 2, 320, 263] +[:mouse_move, 286, 643, 2, 321, 264] +[:mouse_move, 270, 646, 2, 322, 264] +[:mouse_move, 255, 647, 2, 323, 264] +[:mouse_move, 236, 650, 2, 324, 264] +[:mouse_move, 227, 650, 2, 325, 265] +[:mouse_move, 216, 650, 2, 326, 265] +[:mouse_move, 207, 650, 2, 327, 265] +[:mouse_move, 203, 651, 2, 328, 265] +[:mouse_move, 202, 651, 2, 329, 265] +[:mouse_move, 201, 651, 2, 330, 265] +[:mouse_move, 200, 651, 2, 331, 267] +[:mouse_move, 199, 651, 2, 332, 267] +[:mouse_move, 198, 651, 2, 333, 268] +[:mouse_move, 195, 652, 2, 334, 268] +[:mouse_move, 194, 653, 2, 335, 269] +[:mouse_move, 193, 654, 2, 336, 269] +[:mouse_move, 193, 655, 2, 337, 272] +[:mouse_move, 192, 655, 2, 338, 272] +[:mouse_move, 192, 656, 2, 339, 274] +[:mouse_move, 192, 658, 2, 340, 275] +[:mouse_move, 192, 661, 2, 341, 275] +[:mouse_move, 192, 662, 2, 342, 275] +[:mouse_move, 192, 664, 2, 343, 276] +[:mouse_move, 192, 665, 2, 344, 277] +[:mouse_button_up, 1, 0, 1, 345, 329] +[:mouse_move, 192, 664, 2, 346, 337] +[:mouse_move, 193, 664, 2, 347, 354] +[:mouse_move, 195, 663, 2, 348, 355] +[:mouse_move, 201, 662, 2, 349, 355] +[:mouse_move, 211, 660, 2, 350, 356] +[:mouse_move, 227, 659, 2, 351, 357] +[:mouse_move, 283, 651, 2, 352, 357] +[:mouse_move, 348, 641, 2, 353, 358] +[:mouse_move, 431, 632, 2, 354, 358] +[:mouse_move, 522, 622, 2, 355, 359] +[:mouse_move, 605, 609, 2, 356, 359] +[:mouse_move, 661, 603, 2, 357, 360] +[:mouse_move, 687, 599, 2, 358, 361] +[:mouse_move, 702, 596, 2, 359, 361] +[:mouse_move, 708, 595, 2, 360, 362] +[:mouse_move, 711, 593, 2, 361, 362] +[:mouse_move, 712, 592, 2, 362, 364] +[:mouse_move, 714, 590, 2, 363, 364] +[:mouse_move, 715, 589, 2, 364, 365] +[:mouse_move, 715, 587, 2, 365, 365] +[:mouse_move, 713, 584, 2, 366, 366] +[:mouse_move, 712, 584, 2, 367, 367] +[:mouse_move, 711, 583, 2, 368, 368] +[:mouse_move, 712, 582, 2, 369, 369] +[:mouse_move, 716, 579, 2, 370, 370] +[:mouse_move, 719, 578, 2, 371, 371] +[:mouse_move, 740, 571, 2, 372, 372] +[:mouse_move, 757, 569, 2, 373, 372] +[:mouse_move, 764, 568, 2, 374, 372] +[:mouse_move, 764, 567, 2, 375, 374] +[:mouse_button_pressed, 1, 0, 1, 376, 376] +[:mouse_button_up, 1, 0, 1, 377, 377] +[:mouse_move, 764, 571, 2, 378, 390] +[:mouse_move, 764, 579, 2, 379, 391] +[:mouse_move, 764, 584, 2, 380, 391] +[:mouse_move, 763, 586, 2, 381, 392] +[:mouse_move, 760, 592, 2, 382, 393] +[:mouse_move, 755, 600, 2, 383, 393] +[:mouse_move, 752, 606, 2, 384, 393] +[:mouse_move, 750, 607, 2, 385, 394] +[:mouse_move, 750, 608, 2, 386, 395] +[:mouse_move, 750, 610, 2, 387, 396] +[:mouse_move, 750, 614, 2, 388, 396] +[:mouse_move, 750, 615, 2, 389, 396] +[:mouse_move, 750, 617, 2, 390, 397] +[:mouse_move, 750, 618, 2, 391, 398] +[:mouse_move, 750, 620, 2, 392, 399] +[:mouse_move, 749, 622, 2, 393, 400] +[:mouse_button_pressed, 1, 0, 1, 394, 401] +[:mouse_button_up, 1, 0, 1, 395, 403] +[:mouse_move, 749, 623, 2, 396, 408] +[:mouse_move, 750, 623, 2, 397, 410] +[:mouse_move, 754, 624, 2, 398, 410] +[:mouse_move, 760, 625, 2, 399, 411] +[:mouse_move, 769, 628, 2, 400, 411] +[:mouse_move, 785, 630, 2, 401, 412] +[:mouse_move, 791, 631, 2, 402, 413] +[:mouse_move, 792, 631, 2, 403, 414] +[:mouse_move, 793, 631, 2, 404, 414] +[:mouse_move, 794, 631, 2, 405, 415] +[:mouse_move, 795, 631, 2, 406, 415] +[:mouse_move, 796, 631, 2, 407, 416] +[:mouse_move, 798, 631, 2, 408, 417] +[:mouse_move, 799, 631, 2, 409, 422] +[:mouse_move, 799, 630, 2, 410, 423] +[:mouse_move, 800, 627, 2, 411, 426] +[:mouse_move, 802, 621, 2, 412, 427] +[:mouse_move, 804, 609, 2, 413, 427] +[:mouse_move, 806, 601, 2, 414, 428] +[:mouse_move, 804, 595, 2, 415, 429] +[:mouse_move, 799, 591, 2, 416, 430] +[:mouse_move, 796, 591, 2, 417, 430] +[:mouse_move, 792, 591, 2, 418, 430] +[:mouse_move, 786, 593, 2, 419, 431] +[:mouse_move, 775, 597, 2, 420, 432] +[:mouse_move, 766, 600, 2, 421, 433] +[:mouse_move, 763, 600, 2, 422, 434] +[:mouse_move, 762, 600, 2, 423, 434] +[:mouse_move, 761, 599, 2, 424, 435] +[:mouse_move, 759, 592, 2, 425, 435] +[:mouse_move, 756, 578, 2, 426, 436] +[:mouse_move, 755, 571, 2, 427, 437] +[:mouse_move, 755, 566, 2, 428, 437] +[:mouse_button_pressed, 1, 0, 1, 429, 440] +[:mouse_button_up, 1, 0, 1, 430, 442] +[:mouse_move, 755, 567, 2, 431, 443] +[:mouse_move, 756, 567, 2, 432, 444] +[:mouse_move, 756, 568, 2, 433, 446] +[:mouse_move, 756, 573, 2, 434, 446] +[:mouse_move, 756, 582, 2, 435, 447] +[:mouse_move, 756, 592, 2, 436, 448] +[:mouse_move, 758, 599, 2, 437, 448] +[:mouse_move, 758, 604, 2, 438, 449] +[:mouse_move, 759, 607, 2, 439, 449] +[:mouse_move, 760, 610, 2, 440, 450] +[:mouse_move, 760, 611, 2, 441, 451] +[:mouse_move, 760, 612, 2, 442, 451] +[:mouse_move, 760, 613, 2, 443, 452] +[:mouse_move, 760, 614, 2, 444, 452] +[:mouse_move, 760, 615, 2, 445, 454] +[:mouse_move, 759, 616, 2, 446, 455] +[:mouse_move, 759, 617, 2, 447, 455] +[:mouse_move, 759, 618, 2, 448, 456] +[:mouse_move, 759, 619, 2, 449, 457] +[:mouse_move, 759, 621, 2, 450, 459] +[:mouse_move, 758, 621, 2, 451, 460] +[:mouse_move, 758, 622, 2, 452, 463] +[:mouse_move, 758, 623, 2, 453, 464] +[:mouse_move, 759, 623, 2, 454, 467] +[:mouse_move, 759, 624, 2, 455, 468] +[:mouse_move, 767, 624, 2, 456, 468] +[:mouse_move, 776, 625, 2, 457, 469] +[:mouse_move, 787, 627, 2, 458, 469] +[:mouse_move, 795, 629, 2, 459, 470] +[:mouse_move, 797, 630, 2, 460, 470] +[:mouse_move, 798, 630, 2, 461, 471] +[:mouse_button_pressed, 1, 0, 1, 462, 476] +[:mouse_move, 799, 630, 2, 463, 476] +[:mouse_button_up, 1, 0, 1, 464, 478] +[:mouse_move, 799, 625, 2, 465, 478] +[:mouse_move, 800, 615, 2, 466, 479] +[:mouse_move, 801, 602, 2, 467, 480] +[:mouse_move, 801, 590, 2, 468, 481] +[:mouse_move, 801, 580, 2, 469, 481] +[:mouse_move, 801, 571, 2, 470, 482] +[:mouse_move, 801, 570, 2, 471, 482] +[:mouse_move, 801, 569, 2, 472, 483] +[:mouse_move, 801, 568, 2, 473, 485] +[:mouse_move, 802, 567, 2, 474, 487] +[:mouse_move, 803, 567, 2, 475, 488] +[:mouse_button_pressed, 1, 0, 1, 476, 491] +[:mouse_button_up, 1, 0, 1, 477, 493] +[:mouse_move, 804, 567, 2, 478, 494] +[:mouse_move, 811, 567, 2, 479, 495] +[:mouse_move, 822, 567, 2, 480, 495] +[:mouse_move, 837, 567, 2, 481, 496] +[:mouse_move, 850, 567, 2, 482, 496] +[:mouse_move, 861, 567, 2, 483, 497] +[:mouse_move, 873, 568, 2, 484, 497] +[:mouse_move, 875, 568, 2, 485, 498] +[:mouse_move, 876, 568, 2, 486, 500] +[:mouse_move, 877, 568, 2, 487, 501] +[:mouse_move, 877, 569, 2, 488, 501] +[:mouse_move, 868, 570, 2, 489, 516] +[:mouse_move, 850, 574, 2, 490, 516] +[:mouse_move, 835, 577, 2, 491, 517] +[:mouse_move, 818, 577, 2, 492, 517] +[:mouse_move, 810, 577, 2, 493, 518] +[:mouse_move, 810, 578, 2, 494, 519] +[:mouse_move, 813, 578, 2, 495, 520] +[:mouse_move, 816, 578, 2, 496, 521] +[:mouse_move, 819, 578, 2, 497, 521] +[:mouse_move, 820, 578, 2, 498, 522] +[:mouse_button_pressed, 1, 0, 1, 499, 526] +[:mouse_button_up, 1, 0, 1, 500, 527] +[:mouse_move, 822, 579, 2, 501, 529] +[:mouse_move, 823, 581, 2, 502, 530] +[:mouse_move, 824, 581, 2, 503, 531] +[:mouse_move, 825, 581, 2, 504, 531] +[:mouse_move, 829, 581, 2, 505, 531] +[:mouse_move, 836, 581, 2, 506, 532] +[:mouse_move, 843, 580, 2, 507, 533] +[:mouse_move, 852, 577, 2, 508, 534] +[:mouse_move, 862, 574, 2, 509, 534] +[:mouse_move, 864, 574, 2, 510, 535] +[:mouse_move, 865, 574, 2, 511, 541] +[:mouse_button_pressed, 1, 0, 1, 512, 542] +[:mouse_button_up, 1, 0, 1, 513, 544] +[:mouse_move, 866, 581, 2, 514, 545] +[:mouse_move, 868, 587, 2, 515, 545] +[:mouse_move, 870, 592, 2, 516, 546] +[:mouse_move, 871, 595, 2, 517, 546] +[:mouse_move, 873, 598, 2, 518, 547] +[:mouse_move, 874, 602, 2, 519, 548] +[:mouse_move, 875, 608, 2, 520, 548] +[:mouse_move, 875, 610, 2, 521, 549] +[:mouse_move, 875, 613, 2, 522, 549] +[:mouse_move, 875, 616, 2, 523, 550] +[:mouse_move, 875, 617, 2, 524, 551] +[:mouse_move, 875, 618, 2, 525, 552] +[:mouse_move, 874, 620, 2, 526, 553] +[:mouse_move, 872, 625, 2, 527, 553] +[:mouse_move, 871, 627, 2, 528, 554] +[:mouse_move, 871, 628, 2, 529, 554] +[:mouse_move, 871, 629, 2, 530, 555] +[:mouse_move, 870, 630, 2, 531, 556] +[:mouse_button_pressed, 1, 0, 1, 532, 558] +[:mouse_move, 871, 630, 2, 533, 558] +[:mouse_button_up, 1, 0, 1, 534, 560] +[:mouse_move, 869, 630, 2, 535, 564] +[:mouse_move, 864, 631, 2, 536, 565] +[:mouse_move, 857, 632, 2, 537, 566] +[:mouse_move, 845, 633, 2, 538, 567] +[:mouse_move, 830, 635, 2, 539, 567] +[:mouse_move, 815, 636, 2, 540, 568] +[:mouse_move, 800, 636, 2, 541, 568] +[:mouse_move, 782, 636, 2, 542, 569] +[:mouse_move, 773, 636, 2, 543, 570] +[:mouse_move, 764, 636, 2, 544, 570] +[:mouse_move, 757, 636, 2, 545, 571] +[:mouse_move, 748, 636, 2, 546, 571] +[:mouse_move, 741, 634, 2, 547, 572] +[:mouse_move, 734, 634, 2, 548, 573] +[:mouse_move, 728, 634, 2, 549, 574] +[:mouse_move, 720, 634, 2, 550, 574] +[:mouse_move, 713, 633, 2, 551, 575] +[:mouse_move, 723, 632, 2, 552, 579] +[:mouse_move, 734, 629, 2, 553, 580] +[:mouse_move, 745, 626, 2, 554, 581] +[:mouse_move, 761, 623, 2, 555, 581] +[:mouse_move, 784, 617, 2, 556, 582] +[:mouse_move, 811, 610, 2, 557, 582] +[:mouse_move, 834, 601, 2, 558, 583] +[:mouse_move, 850, 594, 2, 559, 584] +[:mouse_move, 857, 590, 2, 560, 584] +[:mouse_move, 858, 589, 2, 561, 585] +[:mouse_move, 858, 588, 2, 562, 585] +[:mouse_move, 858, 587, 2, 563, 586] +[:mouse_move, 858, 586, 2, 564, 587] +[:mouse_move, 858, 585, 2, 565, 588] +[:mouse_move, 858, 584, 2, 566, 593] +[:mouse_button_pressed, 1, 0, 1, 567, 595] +[:mouse_button_up, 1, 0, 1, 568, 597] +[:mouse_move, 851, 587, 2, 569, 599] +[:mouse_move, 840, 590, 2, 570, 599] +[:mouse_move, 825, 594, 2, 571, 600] +[:mouse_move, 803, 600, 2, 572, 600] +[:mouse_move, 777, 605, 2, 573, 601] +[:mouse_move, 751, 607, 2, 574, 602] +[:mouse_move, 729, 611, 2, 575, 602] +[:mouse_move, 713, 614, 2, 576, 603] +[:mouse_move, 701, 615, 2, 577, 603] +[:mouse_move, 695, 615, 2, 578, 604] +[:mouse_move, 694, 616, 2, 579, 605] +[:mouse_move, 692, 615, 2, 580, 605] +[:mouse_move, 690, 614, 2, 581, 606] +[:mouse_move, 689, 614, 2, 582, 607] +[:mouse_move, 688, 613, 2, 583, 607] +[:mouse_move, 688, 610, 2, 584, 608] +[:mouse_move, 687, 605, 2, 585, 608] +[:mouse_move, 686, 598, 2, 586, 609] +[:mouse_move, 686, 589, 2, 587, 610] +[:mouse_move, 686, 582, 2, 588, 610] +[:mouse_move, 687, 576, 2, 589, 611] +[:mouse_move, 688, 576, 2, 590, 611] +[:mouse_move, 688, 575, 2, 591, 612] +[:mouse_move, 689, 574, 2, 592, 613] +[:mouse_move, 689, 573, 2, 593, 613] +[:mouse_move, 690, 573, 2, 594, 614] +[:mouse_button_pressed, 1, 0, 1, 595, 615] +[:mouse_move, 690, 572, 2, 596, 616] +[:mouse_button_up, 1, 0, 1, 597, 617] +[:mouse_move, 690, 573, 2, 598, 617] +[:mouse_move, 690, 574, 2, 599, 619] +[:mouse_move, 690, 575, 2, 600, 620] +[:mouse_move, 690, 576, 2, 601, 621] +[:mouse_move, 690, 578, 2, 602, 621] +[:mouse_move, 690, 579, 2, 603, 622] +[:mouse_move, 690, 583, 2, 604, 622] +[:mouse_move, 691, 594, 2, 605, 622] +[:mouse_move, 693, 605, 2, 606, 623] +[:mouse_move, 696, 614, 2, 607, 624] +[:mouse_move, 698, 619, 2, 608, 625] +[:mouse_move, 699, 621, 2, 609, 625] +[:mouse_move, 700, 622, 2, 610, 626] +[:mouse_move, 701, 622, 2, 611, 634] +[:mouse_move, 702, 622, 2, 612, 649] +[:mouse_move, 702, 621, 2, 613, 656] +[:mouse_move, 705, 620, 2, 614, 656] +[:mouse_move, 718, 614, 2, 615, 657] +[:mouse_move, 750, 600, 2, 616, 657] +[:mouse_move, 811, 576, 2, 617, 658] +[:mouse_move, 895, 538, 2, 618, 659] +[:mouse_move, 984, 489, 2, 619, 659] +[:mouse_move, 1076, 432, 2, 620, 660] +[:mouse_move, 1151, 376, 2, 621, 661] +[:mouse_move, 1205, 336, 2, 622, 661] +[:mouse_move, 1232, 312, 2, 623, 662] +[:mouse_move, 1244, 292, 2, 624, 662] +[:mouse_move, 1244, 286, 2, 625, 663] +[:mouse_move, 1243, 284, 2, 626, 663] +[:mouse_move, 1244, 284, 2, 627, 667] +[:key_down_raw, 96, 0, 2, 628, 675] +[:mouse_move, 1243, 284, 2, 629, 676] +[:mouse_move, 1243, 283, 2, 630, 676] +[:mouse_move, 1243, 282, 2, 631, 676] +[:mouse_move, 1243, 281, 2, 632, 677] +[:key_up_raw, 96, 0, 2, 633, 677] +[:mouse_move, 1243, 280, 2, 634, 677] +[:mouse_move, 1242, 279, 2, 635, 678] +[:mouse_move, 1242, 277, 2, 636, 678] +[:mouse_move, 1242, 274, 2, 637, 679] +[:mouse_move, 1241, 271, 2, 638, 679] +[:mouse_move, 1239, 268, 2, 639, 680] +[:mouse_move, 1237, 264, 2, 640, 680] +[:mouse_move, 1233, 261, 2, 641, 681] +[:mouse_move, 1231, 259, 2, 642, 682] +[:mouse_move, 1231, 258, 2, 643, 682] +[:mouse_move, 1230, 256, 2, 644, 683] +[:mouse_move, 1229, 255, 2, 645, 683] +[:mouse_move, 1227, 252, 2, 646, 684] +[:mouse_move, 1222, 247, 2, 647, 685] +[:mouse_move, 1219, 244, 2, 648, 685] +[:mouse_move, 1217, 242, 2, 649, 685] +[:mouse_move, 1216, 241, 2, 650, 686] +[:mouse_move, 1214, 240, 2, 651, 686] +[:mouse_move, 1206, 237, 2, 652, 687] +[:mouse_move, 1194, 232, 2, 653, 688] +[:mouse_move, 1176, 228, 2, 654, 688] +[:mouse_move, 1161, 224, 2, 655, 688] +[:mouse_move, 1157, 224, 2, 656, 689] +[:mouse_move, 1154, 222, 2, 657, 689] +[:mouse_move, 1148, 217, 2, 658, 690] +[:mouse_move, 1139, 205, 2, 659, 691] +[:mouse_move, 1127, 186, 2, 660, 691] +[:mouse_move, 1118, 165, 2, 661, 691] +[:mouse_move, 1109, 140, 2, 662, 692] +[:mouse_move, 1105, 120, 2, 663, 692] +[:mouse_move, 1107, 107, 2, 664, 693] +[:mouse_move, 1108, 105, 2, 665, 693] +[:mouse_move, 1108, 104, 2, 666, 694] +[:mouse_move, 1100, 103, 2, 667, 697] +[:mouse_move, 1085, 101, 2, 668, 697] +[:mouse_move, 1067, 99, 2, 669, 698] +[:mouse_move, 1051, 96, 2, 670, 698] +[:mouse_move, 1026, 94, 2, 671, 698] +[:mouse_move, 988, 90, 2, 672, 699] +[:mouse_move, 919, 86, 2, 673, 700] +[:mouse_move, 868, 83, 2, 674, 700] +[:mouse_move, 822, 83, 2, 675, 701] +[:mouse_move, 796, 85, 2, 676, 701] +[:mouse_move, 787, 87, 2, 677, 701] +[:mouse_move, 786, 88, 2, 678, 702] +[:mouse_move, 787, 88, 2, 679, 710] +[:mouse_move, 789, 88, 2, 680, 718] +[:mouse_move, 790, 89, 2, 681, 720] +[:key_down_raw, 13, 0, 2, 682, 730] diff --git a/samples/13_path_finding_algorithms/06_heuristic/app/main.rb b/samples/13_path_finding_algorithms/06_heuristic/app/main.rb index af466a5..ad4c5ce 100644 --- a/samples/13_path_finding_algorithms/06_heuristic/app/main.rb +++ b/samples/13_path_finding_algorithms/06_heuristic/app/main.rb @@ -10,13 +10,13 @@ class Heuristic_With_Walls def tick defaults - render - input + render + input # If animation is playing, and max steps have not been reached # Move the search a step forward if state.play && state.current_step < state.max_steps # Variable that tells the program what step to recalculate up to - state.current_step += 1 + state.current_step += 1 move_searches_one_step_forward end end @@ -38,7 +38,7 @@ class Heuristic_With_Walls # We store this value, because we want to remember the value even when # the user's cursor is no longer over what they're interacting with, but # they are still clicking down on the mouse. - state.user_input ||= :none + state.user_input ||= :none # These variables allow the breadth first search to take place # Came_from is a hash with a key of a cell and a value of the cell that was expanded from to find the key. @@ -63,7 +63,7 @@ class Heuristic_With_Walls # Unless the current step has a value unless state.current_step # Set the current step to 10 - state.current_step = 10 + state.current_step = 10 # And calculate the searches up to step 10 recalculate_searches end @@ -73,7 +73,7 @@ class Heuristic_With_Walls # This step is roughly the grid's width * height # When anim_steps equals max_steps no more calculations will occur # and the slider will be at the end - state.max_steps = grid.width * grid.height + state.max_steps = grid.width * grid.height # Whether the animation should play or not # If true, every tick moves anim_steps forward one @@ -166,7 +166,7 @@ class Heuristic_With_Walls # If the mouse was clicked this tick if inputs.mouse.down # Determine what the user is editing and appropriately edit the state.user_input variable - determine_input + determine_input end # Process user input based on user_input variable and current mouse position @@ -179,35 +179,35 @@ class Heuristic_With_Walls if mouse_over_slider? state.user_input = :slider # If the mouse is over the star in the first grid - elsif bfs_mouse_over_star? + elsif bfs_mouse_over_star? # The user is editing the star from the first grid - state.user_input = :bfs_star + state.user_input = :bfs_star # If the mouse is over the star in the second grid - elsif heuristic_mouse_over_star? + elsif heuristic_mouse_over_star? # The user is editing the star from the second grid - state.user_input = :heuristic_star + state.user_input = :heuristic_star # If the mouse is over the target in the first grid - elsif bfs_mouse_over_target? + elsif bfs_mouse_over_target? # The user is editing the target from the first grid - state.user_input = :bfs_target + state.user_input = :bfs_target # If the mouse is over the target in the second grid - elsif heuristic_mouse_over_target? + elsif heuristic_mouse_over_target? # The user is editing the target from the second grid - state.user_input = :heuristic_target + state.user_input = :heuristic_target # If the mouse is over a wall in the first grid - elsif bfs_mouse_over_wall? + elsif bfs_mouse_over_wall? # The user is removing a wall from the first grid - state.user_input = :bfs_remove_wall + state.user_input = :bfs_remove_wall # If the mouse is over a wall in the second grid - elsif heuristic_mouse_over_wall? + elsif heuristic_mouse_over_wall? # The user is removing a wall from the second grid state.user_input = :heuristic_remove_wall # If the mouse is over the first grid - elsif bfs_mouse_over_grid? + elsif bfs_mouse_over_grid? # The user is adding a wall from the first grid state.user_input = :bfs_add_wall # If the mouse is over the second grid - elsif heuristic_mouse_over_grid? + elsif heuristic_mouse_over_grid? # The user is adding a wall from the second grid state.user_input = :heuristic_add_wall end @@ -217,22 +217,22 @@ class Heuristic_With_Walls def process_input if state.user_input == :slider process_input_slider - elsif state.user_input == :bfs_star - process_input_bfs_star + elsif state.user_input == :bfs_star + process_input_bfs_star elsif state.user_input == :heuristic_star - process_input_heuristic_star - elsif state.user_input == :bfs_target - process_input_bfs_target - elsif state.user_input == :heuristic_target - process_input_heuristic_target - elsif state.user_input == :bfs_remove_wall - process_input_bfs_remove_wall + process_input_heuristic_star + elsif state.user_input == :bfs_target + process_input_bfs_target + elsif state.user_input == :heuristic_target + process_input_heuristic_target + elsif state.user_input == :bfs_remove_wall + process_input_bfs_remove_wall elsif state.user_input == :heuristic_remove_wall - process_input_heuristic_remove_wall - elsif state.user_input == :bfs_add_wall - process_input_bfs_add_wall - elsif state.user_input == :heuristic_add_wall - process_input_heuristic_add_wall + process_input_heuristic_remove_wall + elsif state.user_input == :bfs_add_wall + process_input_bfs_add_wall + elsif state.user_input == :heuristic_add_wall + process_input_heuristic_add_wall end end @@ -309,7 +309,7 @@ class Heuristic_With_Walls # The horizontal grid lines for y in 0..grid.height - outputs.lines << bfs_horizontal_line(y) + outputs.lines << bfs_horizontal_line(y) end end @@ -324,10 +324,10 @@ class Heuristic_With_Walls # The horizontal grid lines for y in 0..grid.height - outputs.lines << heuristic_horizontal_line(y) + outputs.lines << heuristic_horizontal_line(y) end end - + # Returns a vertical line for a column of the first grid def bfs_vertical_line column bfs_scale_up([column, 0, column, grid.height]) @@ -362,7 +362,7 @@ class Heuristic_With_Walls def render_bfs_target outputs.sprites << [bfs_scale_up(grid.target), 'target.png'] end - + # Renders the target on the second grid def render_heuristic_target outputs.sprites << [heuristic_scale_up(grid.target), 'target.png'] @@ -370,14 +370,14 @@ class Heuristic_With_Walls # Renders the walls on the first grid def render_bfs_walls - grid.walls.each_key do | wall | + grid.walls.each_key do | wall | outputs.solids << [bfs_scale_up(wall), wall_color] end end # Renders the walls on the second grid def render_heuristic_walls - grid.walls.each_key do | wall | + grid.walls.each_key do | wall | outputs.solids << [heuristic_scale_up(wall), wall_color] end end @@ -398,14 +398,14 @@ class Heuristic_With_Walls # Renders the frontier cells on the first grid def render_bfs_frontier - bfs.frontier.each do | frontier_cell | + bfs.frontier.each do | frontier_cell | outputs.solids << [bfs_scale_up(frontier_cell), frontier_color, 200] end end # Renders the frontier cells on the second grid def render_heuristic_frontier - heuristic.frontier.each do | frontier_cell | + heuristic.frontier.each do | frontier_cell | outputs.solids << [heuristic_scale_up(frontier_cell), frontier_color, 200] end end @@ -489,14 +489,14 @@ class Heuristic_With_Walls # Checks and handles input for the buttons # Called when the mouse is lifted def input_buttons - input_left_button - input_center_button - input_right_button + input_left_button + input_center_button + input_right_button end # Checks if the previous step button is clicked # If it is, it pauses the animation and moves the search one step backward - def input_left_button + def input_left_button if left_button_clicked? state.play = false state.current_step -= 1 @@ -508,7 +508,7 @@ class Heuristic_With_Walls # Inverses whether the animation is playing or not when clicked def input_center_button if center_button_clicked? || inputs.keyboard.key_down.space - state.play = !state.play + state.play = !state.play end end @@ -516,8 +516,8 @@ class Heuristic_With_Walls # If it is, it pauses the animation and moves the search one step forward def input_right_button if right_button_clicked? - state.play = false - state.current_step += 1 + state.play = false + state.current_step += 1 move_searches_one_step_forward end end @@ -598,12 +598,12 @@ class Heuristic_With_Walls # on the slider # Changes the step of the search to be animated def process_input_slider - state.play = false + state.play = false mouse_x = inputs.mouse.point.x # Bounds the mouse_x to the closest x value on the slider line - mouse_x = slider.x if mouse_x < slider.x - mouse_x = slider.x + slider.w if mouse_x > slider.x + slider.w + mouse_x = slider.x if mouse_x < slider.x + mouse_x = slider.x + slider.w if mouse_x > slider.x + slider.w # Sets the current search step to the one represented by the mouse x value # The slider's circle moves due to the render_slider method using anim_steps @@ -616,12 +616,12 @@ class Heuristic_With_Walls # Only resets the search if the star changes position # Called whenever the user is editing the star (puts mouse down on star) def process_input_bfs_star - old_star = grid.star.clone + old_star = grid.star.clone unless bfs_cell_closest_to_mouse == grid.target - grid.star = bfs_cell_closest_to_mouse + grid.star = bfs_cell_closest_to_mouse end - unless old_star == grid.star - recalculate_searches + unless old_star == grid.star + recalculate_searches end end @@ -629,12 +629,12 @@ class Heuristic_With_Walls # Only resets the search if the star changes position # Called whenever the user is editing the star (puts mouse down on star) def process_input_heuristic_star - old_star = grid.star.clone + old_star = grid.star.clone unless heuristic_cell_closest_to_mouse == grid.target grid.star = heuristic_cell_closest_to_mouse end - unless old_star == grid.star - recalculate_searches + unless old_star == grid.star + recalculate_searches end end @@ -642,12 +642,12 @@ class Heuristic_With_Walls # Only recalculate_searchess the search if the target changes position # Called whenever the user is editing the target (puts mouse down on target) def process_input_bfs_target - old_target = grid.target.clone + old_target = grid.target.clone unless bfs_cell_closest_to_mouse == grid.star grid.target = bfs_cell_closest_to_mouse end - unless old_target == grid.target - recalculate_searches + unless old_target == grid.target + recalculate_searches end end @@ -655,12 +655,12 @@ class Heuristic_With_Walls # Only recalculate_searchess the search if the target changes position # Called whenever the user is editing the target (puts mouse down on target) def process_input_heuristic_target - old_target = grid.target.clone + old_target = grid.target.clone unless heuristic_cell_closest_to_mouse == grid.star grid.target = heuristic_cell_closest_to_mouse end - unless old_target == grid.target - recalculate_searches + unless old_target == grid.target + recalculate_searches end end @@ -669,10 +669,10 @@ class Heuristic_With_Walls # The mouse needs to be inside the grid, because we only want to remove walls # the cursor is directly over # Recalculations should only occur when a wall is actually deleted - if bfs_mouse_over_grid? + if bfs_mouse_over_grid? if grid.walls.has_key?(bfs_cell_closest_to_mouse) - grid.walls.delete(bfs_cell_closest_to_mouse) - recalculate_searches + grid.walls.delete(bfs_cell_closest_to_mouse) + recalculate_searches end end end @@ -682,29 +682,29 @@ class Heuristic_With_Walls # The mouse needs to be inside the grid, because we only want to remove walls # the cursor is directly over # Recalculations should only occur when a wall is actually deleted - if heuristic_mouse_over_grid? + if heuristic_mouse_over_grid? if grid.walls.has_key?(heuristic_cell_closest_to_mouse) - grid.walls.delete(heuristic_cell_closest_to_mouse) - recalculate_searches + grid.walls.delete(heuristic_cell_closest_to_mouse) + recalculate_searches end end end # Adds a wall in the first grid in the cell the mouse is over def process_input_bfs_add_wall - if bfs_mouse_over_grid? + if bfs_mouse_over_grid? unless grid.walls.has_key?(bfs_cell_closest_to_mouse) - grid.walls[bfs_cell_closest_to_mouse] = true - recalculate_searches + grid.walls[bfs_cell_closest_to_mouse] = true + recalculate_searches end end end # Adds a wall in the second grid in the cell the mouse is over def process_input_heuristic_add_wall - if heuristic_mouse_over_grid? + if heuristic_mouse_over_grid? unless grid.walls.has_key?(heuristic_cell_closest_to_mouse) - grid.walls[heuristic_cell_closest_to_mouse] = true - recalculate_searches + grid.walls[heuristic_cell_closest_to_mouse] = true + recalculate_searches end end end @@ -714,13 +714,13 @@ class Heuristic_With_Walls # Finding the cell closest to the mouse helps with this def bfs_cell_closest_to_mouse # Closest cell to the mouse in the first grid - x = (inputs.mouse.point.x / grid.cell_size).to_i - y = (inputs.mouse.point.y / grid.cell_size).to_i + x = (inputs.mouse.point.x / grid.cell_size).to_i + y = (inputs.mouse.point.y / grid.cell_size).to_i # Bound x and y to the grid - x = grid.width - 1 if x > grid.width - 1 - y = grid.height - 1 if y > grid.height - 1 + x = grid.width - 1 if x > grid.width - 1 + y = grid.height - 1 if y > grid.height - 1 # Return closest cell - [x, y] + [x, y] end # When the user grabs the star and puts their cursor to the far right @@ -728,17 +728,17 @@ class Heuristic_With_Walls # Finding the cell closest to the mouse in the second grid helps with this def heuristic_cell_closest_to_mouse # Closest cell grid to the mouse in the second - x = (inputs.mouse.point.x / grid.cell_size).to_i - y = (inputs.mouse.point.y / grid.cell_size).to_i + x = (inputs.mouse.point.x / grid.cell_size).to_i + y = (inputs.mouse.point.y / grid.cell_size).to_i # Translate the cell to the first grid x -= grid.width + 1 # Bound x and y to the first grid x = 0 if x < 0 y = 0 if y < 0 - x = grid.width - 1 if x > grid.width - 1 - y = grid.height - 1 if y > grid.height - 1 + x = grid.width - 1 if x > grid.width - 1 + y = grid.height - 1 if y > grid.height - 1 # Return closest cell - [x, y] + [x, y] end def recalculate_searches @@ -763,22 +763,22 @@ class Heuristic_With_Walls return if bfs.came_from.has_key?(grid.target) # Only runs at the beginning of the search as setup. - if bfs.came_from.empty? - bfs.frontier << grid.star - bfs.came_from[grid.star] = nil + if bfs.came_from.empty? + bfs.frontier << grid.star + bfs.came_from[grid.star] = nil end # A step in the search - unless bfs.frontier.empty? + unless bfs.frontier.empty? # Takes the next frontier cell - new_frontier = bfs.frontier.shift + new_frontier = bfs.frontier.shift # For each of its neighbors - adjacent_neighbors(new_frontier).each do |neighbor| + adjacent_neighbors(new_frontier).each do |neighbor| # That have not been visited and are not walls - unless bfs.came_from.has_key?(neighbor) || grid.walls.has_key?(neighbor) + unless bfs.came_from.has_key?(neighbor) || grid.walls.has_key?(neighbor) # Add them to the frontier and mark them as visited - bfs.frontier << neighbor - bfs.came_from[neighbor] = new_frontier + bfs.frontier << neighbor + bfs.came_from[neighbor] = new_frontier end end end @@ -833,12 +833,12 @@ class Heuristic_With_Walls # Get the next cell to explore from new_frontier = heuristic.frontier.shift # For each of its neighbors - adjacent_neighbors(new_frontier).each do |neighbor| + adjacent_neighbors(new_frontier).each do |neighbor| # That have not been visited and are not walls - unless heuristic.came_from.has_key?(neighbor) || grid.walls.has_key?(neighbor) + unless heuristic.came_from.has_key?(neighbor) || grid.walls.has_key?(neighbor) # Add them to the frontier and mark them as visited - heuristic.frontier << neighbor - heuristic.came_from[neighbor] = new_frontier + heuristic.frontier << neighbor + heuristic.came_from[neighbor] = new_frontier end end end @@ -882,16 +882,16 @@ class Heuristic_With_Walls # Returns a list of adjacent cells # Used to determine what the next cells to be added to the frontier are def adjacent_neighbors(cell) - neighbors = [] + neighbors = [] # Gets all the valid neighbors into the array # From southern neighbor, clockwise - neighbors << [cell.x , cell.y - 1] unless cell.y == 0 - neighbors << [cell.x - 1, cell.y ] unless cell.x == 0 - neighbors << [cell.x , cell.y + 1] unless cell.y == grid.height - 1 - neighbors << [cell.x + 1, cell.y ] unless cell.x == grid.width - 1 + neighbors << [cell.x , cell.y - 1] unless cell.y == 0 + neighbors << [cell.x - 1, cell.y ] unless cell.x == 0 + neighbors << [cell.x , cell.y + 1] unless cell.y == grid.height - 1 + neighbors << [cell.x + 1, cell.y ] unless cell.x == grid.width - 1 - neighbors + neighbors end # Finds the vertical and horizontal distance of a cell from the star @@ -940,7 +940,7 @@ class Heuristic_With_Walls def wall_color [134, 134, 120] # Camo Green end - + def visited_color [204, 191, 179] # Dark Brown end @@ -948,7 +948,7 @@ class Heuristic_With_Walls def frontier_color [103, 136, 204] # Blue end - + def path_color [231, 230, 228] # Pastel White end @@ -969,7 +969,7 @@ def tick args end # Every tick, new args are passed, and the Breadth First Search tick is called - $heuristic_with_walls ||= Heuristic_With_Walls.new(args) + $heuristic_with_walls ||= Heuristic_With_Walls.new $heuristic_with_walls.args = args $heuristic_with_walls.tick end diff --git a/samples/13_path_finding_algorithms/06_heuristic/replay.txt b/samples/13_path_finding_algorithms/06_heuristic/replay.txt new file mode 100644 index 0000000..1683449 --- /dev/null +++ b/samples/13_path_finding_algorithms/06_heuristic/replay.txt @@ -0,0 +1,719 @@ +replay_version 2.0 +stopped_at 1004 +seed 100 +recorded_at 2021-11-20 11:21:45 -0600 +[:mouse_button_up, 1, 0, 1, 1, 3] +[:mouse_move, 767, 87, 2, 2, 22] +[:mouse_move, 742, 87, 2, 3, 22] +[:mouse_move, 713, 87, 2, 4, 23] +[:mouse_move, 685, 87, 2, 5, 24] +[:mouse_move, 656, 87, 2, 6, 25] +[:mouse_move, 633, 87, 2, 7, 26] +[:mouse_move, 616, 87, 2, 8, 27] +[:mouse_move, 603, 85, 2, 9, 28] +[:mouse_move, 587, 77, 2, 10, 29] +[:mouse_move, 567, 69, 2, 11, 30] +[:mouse_move, 543, 60, 2, 12, 31] +[:mouse_move, 528, 55, 2, 13, 31] +[:mouse_move, 517, 53, 2, 14, 32] +[:mouse_move, 513, 51, 2, 15, 33] +[:mouse_move, 511, 50, 2, 16, 34] +[:mouse_move, 506, 49, 2, 17, 35] +[:mouse_move, 501, 48, 2, 18, 36] +[:mouse_move, 497, 46, 2, 19, 36] +[:mouse_move, 496, 46, 2, 20, 37] +[:mouse_move, 495, 46, 2, 21, 38] +[:mouse_move, 490, 46, 2, 22, 39] +[:mouse_move, 483, 46, 2, 23, 40] +[:mouse_move, 470, 46, 2, 24, 41] +[:mouse_move, 461, 46, 2, 25, 41] +[:mouse_move, 456, 46, 2, 26, 42] +[:mouse_move, 457, 46, 2, 27, 55] +[:mouse_button_pressed, 1, 0, 1, 28, 58] +[:mouse_move, 458, 46, 2, 29, 59] +[:mouse_move, 460, 46, 2, 30, 62] +[:mouse_move, 461, 46, 2, 31, 62] +[:mouse_move, 463, 46, 2, 32, 63] +[:mouse_move, 464, 46, 2, 33, 64] +[:mouse_move, 465, 46, 2, 34, 64] +[:mouse_move, 466, 46, 2, 35, 65] +[:mouse_move, 467, 46, 2, 36, 65] +[:mouse_move, 469, 46, 2, 37, 66] +[:mouse_move, 470, 46, 2, 38, 66] +[:mouse_move, 472, 46, 2, 39, 67] +[:mouse_move, 473, 46, 2, 40, 67] +[:mouse_move, 474, 46, 2, 41, 68] +[:mouse_move, 477, 46, 2, 42, 68] +[:mouse_move, 479, 46, 2, 43, 68] +[:mouse_move, 480, 46, 2, 44, 69] +[:mouse_move, 481, 46, 2, 45, 70] +[:mouse_move, 483, 46, 2, 46, 71] +[:mouse_move, 484, 46, 2, 47, 71] +[:mouse_move, 485, 46, 2, 48, 71] +[:mouse_move, 487, 46, 2, 49, 72] +[:mouse_move, 489, 46, 2, 50, 72] +[:mouse_move, 492, 46, 2, 51, 72] +[:mouse_move, 496, 46, 2, 52, 72] +[:mouse_move, 502, 47, 2, 53, 73] +[:mouse_move, 507, 47, 2, 54, 73] +[:mouse_move, 513, 47, 2, 55, 73] +[:mouse_move, 519, 47, 2, 56, 73] +[:mouse_move, 521, 47, 2, 57, 74] +[:mouse_move, 524, 47, 2, 58, 74] +[:mouse_move, 527, 47, 2, 59, 74] +[:mouse_move, 531, 47, 2, 60, 74] +[:mouse_move, 535, 47, 2, 61, 75] +[:mouse_move, 539, 47, 2, 62, 75] +[:mouse_move, 542, 47, 2, 63, 75] +[:mouse_move, 544, 47, 2, 64, 75] +[:mouse_move, 546, 47, 2, 65, 76] +[:mouse_move, 550, 47, 2, 66, 76] +[:mouse_move, 552, 47, 2, 67, 76] +[:mouse_move, 553, 47, 2, 68, 76] +[:mouse_move, 555, 47, 2, 69, 76] +[:mouse_move, 556, 47, 2, 70, 77] +[:mouse_move, 557, 47, 2, 71, 77] +[:mouse_move, 558, 47, 2, 72, 77] +[:mouse_move, 561, 47, 2, 73, 77] +[:mouse_move, 563, 47, 2, 74, 78] +[:mouse_move, 564, 47, 2, 75, 78] +[:mouse_move, 566, 47, 2, 76, 78] +[:mouse_move, 570, 47, 2, 77, 78] +[:mouse_move, 571, 47, 2, 78, 78] +[:mouse_move, 572, 47, 2, 79, 79] +[:mouse_move, 573, 47, 2, 80, 79] +[:mouse_move, 575, 47, 2, 81, 79] +[:mouse_move, 581, 47, 2, 82, 80] +[:mouse_move, 582, 47, 2, 83, 80] +[:mouse_move, 585, 47, 2, 84, 80] +[:mouse_move, 586, 47, 2, 85, 80] +[:mouse_move, 588, 47, 2, 86, 80] +[:mouse_move, 589, 47, 2, 87, 81] +[:mouse_move, 591, 47, 2, 88, 81] +[:mouse_move, 593, 47, 2, 89, 81] +[:mouse_move, 594, 47, 2, 90, 81] +[:mouse_move, 595, 47, 2, 91, 81] +[:mouse_move, 596, 47, 2, 92, 82] +[:mouse_move, 600, 47, 2, 93, 82] +[:mouse_move, 602, 47, 2, 94, 82] +[:mouse_move, 607, 47, 2, 95, 82] +[:mouse_move, 611, 46, 2, 96, 82] +[:mouse_move, 613, 46, 2, 97, 82] +[:mouse_move, 614, 46, 2, 98, 83] +[:mouse_move, 617, 46, 2, 99, 83] +[:mouse_move, 621, 46, 2, 100, 83] +[:mouse_move, 623, 46, 2, 101, 83] +[:mouse_move, 625, 46, 2, 102, 83] +[:mouse_move, 626, 46, 2, 103, 83] +[:mouse_move, 627, 46, 2, 104, 84] +[:mouse_move, 629, 46, 2, 105, 84] +[:mouse_move, 632, 46, 2, 106, 84] +[:mouse_move, 634, 46, 2, 107, 84] +[:mouse_move, 636, 46, 2, 108, 84] +[:mouse_move, 637, 46, 2, 109, 84] +[:mouse_move, 639, 45, 2, 110, 85] +[:mouse_move, 641, 45, 2, 111, 85] +[:mouse_move, 643, 45, 2, 112, 85] +[:mouse_move, 646, 44, 2, 113, 85] +[:mouse_move, 648, 43, 2, 114, 85] +[:mouse_move, 650, 43, 2, 115, 85] +[:mouse_move, 652, 43, 2, 116, 85] +[:mouse_move, 654, 43, 2, 117, 86] +[:mouse_move, 661, 42, 2, 118, 86] +[:mouse_move, 667, 42, 2, 119, 86] +[:mouse_move, 676, 42, 2, 120, 86] +[:mouse_move, 682, 42, 2, 121, 86] +[:mouse_move, 691, 41, 2, 122, 86] +[:mouse_move, 694, 41, 2, 123, 86] +[:mouse_move, 697, 41, 2, 124, 87] +[:mouse_move, 700, 41, 2, 125, 87] +[:mouse_move, 703, 41, 2, 126, 87] +[:mouse_move, 704, 41, 2, 127, 87] +[:mouse_move, 706, 41, 2, 128, 87] +[:mouse_move, 707, 41, 2, 129, 87] +[:mouse_move, 709, 41, 2, 130, 87] +[:mouse_move, 710, 41, 2, 131, 87] +[:mouse_move, 713, 41, 2, 132, 88] +[:mouse_move, 717, 41, 2, 133, 88] +[:mouse_move, 721, 41, 2, 134, 88] +[:mouse_move, 725, 41, 2, 135, 88] +[:mouse_move, 726, 41, 2, 136, 88] +[:mouse_move, 728, 41, 2, 137, 88] +[:mouse_move, 732, 41, 2, 138, 88] +[:mouse_move, 742, 41, 2, 139, 88] +[:mouse_move, 754, 43, 2, 140, 89] +[:mouse_move, 769, 45, 2, 141, 89] +[:mouse_move, 772, 45, 2, 142, 89] +[:mouse_move, 776, 45, 2, 143, 89] +[:mouse_move, 777, 45, 2, 144, 89] +[:mouse_move, 778, 45, 2, 145, 91] +[:mouse_move, 778, 44, 2, 146, 91] +[:mouse_move, 779, 44, 2, 147, 91] +[:mouse_move, 780, 44, 2, 148, 91] +[:mouse_move, 781, 44, 2, 149, 91] +[:mouse_move, 782, 44, 2, 150, 92] +[:mouse_move, 784, 44, 2, 151, 92] +[:mouse_move, 785, 44, 2, 152, 92] +[:mouse_move, 786, 44, 2, 153, 92] +[:mouse_move, 787, 44, 2, 154, 92] +[:mouse_move, 788, 44, 2, 155, 92] +[:mouse_move, 789, 44, 2, 156, 93] +[:mouse_move, 790, 44, 2, 157, 93] +[:mouse_move, 790, 43, 2, 158, 93] +[:mouse_move, 791, 43, 2, 159, 93] +[:mouse_move, 792, 43, 2, 160, 93] +[:mouse_move, 793, 43, 2, 161, 93] +[:mouse_move, 791, 43, 2, 162, 94] +[:mouse_move, 790, 43, 2, 163, 95] +[:mouse_move, 785, 43, 2, 164, 95] +[:mouse_move, 775, 43, 2, 165, 95] +[:mouse_move, 762, 43, 2, 166, 95] +[:mouse_move, 745, 43, 2, 167, 95] +[:mouse_move, 727, 43, 2, 168, 95] +[:mouse_move, 704, 43, 2, 169, 95] +[:mouse_move, 680, 43, 2, 170, 95] +[:mouse_move, 653, 43, 2, 171, 95] +[:mouse_move, 628, 43, 2, 172, 95] +[:mouse_move, 606, 43, 2, 173, 96] +[:mouse_move, 589, 43, 2, 174, 96] +[:mouse_move, 577, 43, 2, 175, 96] +[:mouse_move, 568, 43, 2, 176, 96] +[:mouse_move, 558, 43, 2, 177, 96] +[:mouse_move, 552, 43, 2, 178, 96] +[:mouse_move, 544, 43, 2, 179, 96] +[:mouse_move, 532, 43, 2, 180, 97] +[:mouse_move, 523, 43, 2, 181, 97] +[:mouse_move, 517, 43, 2, 182, 97] +[:mouse_move, 512, 43, 2, 183, 97] +[:mouse_move, 508, 43, 2, 184, 97] +[:mouse_move, 506, 43, 2, 185, 98] +[:mouse_move, 503, 43, 2, 186, 98] +[:mouse_move, 501, 43, 2, 187, 98] +[:mouse_move, 500, 43, 2, 188, 98] +[:mouse_move, 498, 43, 2, 189, 98] +[:mouse_move, 495, 43, 2, 190, 99] +[:mouse_move, 492, 43, 2, 191, 99] +[:mouse_move, 489, 43, 2, 192, 99] +[:mouse_move, 485, 43, 2, 193, 99] +[:mouse_move, 480, 43, 2, 194, 100] +[:mouse_move, 476, 43, 2, 195, 100] +[:mouse_move, 472, 43, 2, 196, 100] +[:mouse_move, 471, 43, 2, 197, 101] +[:mouse_move, 470, 43, 2, 198, 102] +[:mouse_move, 469, 43, 2, 199, 102] +[:mouse_move, 468, 43, 2, 200, 103] +[:mouse_move, 467, 43, 2, 201, 105] +[:mouse_move, 467, 44, 2, 202, 111] +[:mouse_move, 468, 43, 2, 203, 114] +[:mouse_move, 469, 43, 2, 204, 115] +[:mouse_move, 474, 43, 2, 205, 115] +[:mouse_move, 479, 43, 2, 206, 116] +[:mouse_move, 482, 43, 2, 207, 116] +[:mouse_move, 484, 42, 2, 208, 117] +[:mouse_move, 486, 42, 2, 209, 118] +[:mouse_move, 488, 42, 2, 210, 118] +[:mouse_move, 490, 42, 2, 211, 118] +[:mouse_move, 492, 42, 2, 212, 118] +[:mouse_move, 493, 42, 2, 213, 120] +[:mouse_button_up, 1, 0, 1, 214, 123] +[:mouse_move, 495, 47, 2, 215, 127] +[:mouse_move, 498, 56, 2, 216, 128] +[:mouse_move, 500, 63, 2, 217, 128] +[:mouse_move, 500, 71, 2, 218, 129] +[:mouse_move, 500, 73, 2, 219, 129] +[:mouse_move, 500, 75, 2, 220, 130] +[:mouse_move, 499, 78, 2, 221, 131] +[:mouse_move, 497, 80, 2, 222, 131] +[:mouse_move, 495, 82, 2, 223, 132] +[:mouse_move, 494, 83, 2, 224, 132] +[:mouse_move, 493, 83, 2, 225, 133] +[:mouse_move, 493, 84, 2, 226, 141] +[:mouse_move, 498, 90, 2, 227, 141] +[:mouse_move, 506, 95, 2, 228, 142] +[:mouse_move, 509, 98, 2, 229, 142] +[:mouse_move, 510, 98, 2, 230, 143] +[:mouse_move, 509, 98, 2, 231, 147] +[:mouse_move, 507, 98, 2, 232, 148] +[:mouse_move, 506, 97, 2, 233, 151] +[:mouse_button_pressed, 1, 0, 1, 234, 152] +[:mouse_button_up, 1, 0, 1, 235, 154] +[:mouse_button_pressed, 1, 0, 1, 236, 170] +[:mouse_move, 507, 97, 2, 237, 170] +[:mouse_button_up, 1, 0, 1, 238, 173] +[:mouse_button_pressed, 1, 0, 1, 239, 174] +[:mouse_button_up, 1, 0, 1, 240, 178] +[:mouse_button_pressed, 1, 0, 1, 241, 180] +[:mouse_button_up, 1, 0, 1, 242, 183] +[:mouse_button_pressed, 1, 0, 1, 243, 185] +[:mouse_button_up, 1, 0, 1, 244, 189] +[:mouse_button_pressed, 1, 0, 1, 245, 190] +[:mouse_button_up, 1, 0, 1, 246, 195] +[:mouse_button_pressed, 1, 0, 1, 247, 196] +[:mouse_button_up, 1, 0, 1, 248, 199] +[:mouse_button_pressed, 1, 0, 1, 249, 201] +[:mouse_button_up, 1, 0, 1, 250, 203] +[:mouse_move, 508, 97, 2, 251, 205] +[:mouse_button_pressed, 1, 0, 1, 252, 205] +[:mouse_button_up, 1, 0, 1, 253, 209] +[:mouse_button_pressed, 1, 0, 1, 254, 210] +[:mouse_button_up, 1, 0, 1, 255, 214] +[:mouse_button_pressed, 1, 0, 1, 256, 215] +[:mouse_button_up, 1, 0, 1, 257, 219] +[:mouse_button_pressed, 1, 0, 1, 258, 222] +[:mouse_button_up, 1, 0, 1, 259, 226] +[:mouse_move, 508, 98, 2, 260, 226] +[:mouse_button_pressed, 1, 0, 1, 261, 229] +[:mouse_button_up, 1, 0, 1, 262, 232] +[:mouse_move, 509, 98, 2, 263, 235] +[:mouse_move, 509, 97, 2, 264, 237] +[:mouse_move, 515, 96, 2, 265, 238] +[:mouse_move, 529, 94, 2, 266, 239] +[:mouse_move, 573, 93, 2, 267, 240] +[:mouse_move, 609, 93, 2, 268, 242] +[:mouse_move, 639, 93, 2, 269, 242] +[:mouse_move, 663, 93, 2, 270, 243] +[:mouse_move, 680, 93, 2, 271, 244] +[:mouse_move, 691, 93, 2, 272, 245] +[:mouse_move, 695, 93, 2, 273, 246] +[:mouse_move, 696, 93, 2, 274, 247] +[:mouse_move, 698, 93, 2, 275, 248] +[:mouse_move, 701, 94, 2, 276, 249] +[:mouse_move, 702, 94, 2, 277, 250] +[:mouse_move, 703, 94, 2, 278, 251] +[:mouse_move, 705, 94, 2, 279, 256] +[:mouse_move, 707, 94, 2, 280, 256] +[:mouse_move, 712, 94, 2, 281, 257] +[:mouse_move, 718, 94, 2, 282, 258] +[:mouse_move, 727, 94, 2, 283, 259] +[:mouse_move, 734, 94, 2, 284, 260] +[:mouse_move, 736, 94, 2, 285, 261] +[:mouse_move, 737, 94, 2, 286, 265] +[:mouse_move, 738, 94, 2, 287, 271] +[:mouse_button_pressed, 1, 0, 1, 288, 272] +[:mouse_button_up, 1, 0, 1, 289, 275] +[:mouse_button_pressed, 1, 0, 1, 290, 280] +[:mouse_button_up, 1, 0, 1, 291, 284] +[:mouse_move, 739, 94, 2, 292, 287] +[:mouse_button_pressed, 1, 0, 1, 293, 288] +[:mouse_button_up, 1, 0, 1, 294, 292] +[:mouse_button_pressed, 1, 0, 1, 295, 296] +[:mouse_button_up, 1, 0, 1, 296, 300] +[:mouse_button_pressed, 1, 0, 1, 297, 303] +[:mouse_button_up, 1, 0, 1, 298, 306] +[:mouse_move, 740, 94, 2, 299, 308] +[:mouse_button_pressed, 1, 0, 1, 300, 309] +[:mouse_button_up, 1, 0, 1, 301, 312] +[:mouse_button_pressed, 1, 0, 1, 302, 317] +[:mouse_button_up, 1, 0, 1, 303, 319] +[:mouse_move, 733, 100, 2, 304, 321] +[:mouse_move, 716, 115, 2, 305, 322] +[:mouse_move, 694, 133, 2, 306, 322] +[:mouse_move, 669, 152, 2, 307, 323] +[:mouse_move, 645, 172, 2, 308, 324] +[:mouse_move, 618, 207, 2, 309, 325] +[:mouse_move, 602, 229, 2, 310, 325] +[:mouse_move, 586, 244, 2, 311, 326] +[:mouse_move, 571, 255, 2, 312, 326] +[:mouse_move, 560, 263, 2, 313, 327] +[:mouse_move, 558, 268, 2, 314, 328] +[:mouse_move, 557, 274, 2, 315, 329] +[:mouse_move, 559, 279, 2, 316, 329] +[:mouse_move, 559, 284, 2, 317, 329] +[:mouse_move, 553, 295, 2, 318, 330] +[:mouse_move, 538, 310, 2, 319, 331] +[:mouse_move, 515, 328, 2, 320, 332] +[:mouse_move, 476, 357, 2, 321, 332] +[:mouse_move, 448, 381, 2, 322, 333] +[:mouse_move, 423, 406, 2, 323, 333] +[:mouse_move, 404, 428, 2, 324, 334] +[:mouse_move, 381, 448, 2, 325, 335] +[:mouse_move, 354, 469, 2, 326, 336] +[:mouse_move, 325, 492, 2, 327, 336] +[:mouse_move, 297, 512, 2, 328, 337] +[:mouse_move, 274, 526, 2, 329, 337] +[:mouse_move, 252, 535, 2, 330, 338] +[:mouse_move, 237, 544, 2, 331, 339] +[:mouse_move, 227, 553, 2, 332, 340] +[:mouse_move, 226, 555, 2, 333, 340] +[:mouse_move, 226, 556, 2, 334, 341] +[:mouse_move, 228, 557, 2, 335, 342] +[:mouse_move, 239, 558, 2, 336, 343] +[:mouse_move, 266, 563, 2, 337, 343] +[:mouse_move, 303, 568, 2, 338, 344] +[:mouse_move, 333, 575, 2, 339, 344] +[:mouse_move, 356, 581, 2, 340, 345] +[:mouse_move, 375, 587, 2, 341, 346] +[:mouse_move, 390, 591, 2, 342, 347] +[:mouse_move, 407, 598, 2, 343, 347] +[:mouse_move, 414, 600, 2, 344, 348] +[:mouse_move, 415, 600, 2, 345, 348] +[:mouse_move, 416, 601, 2, 346, 349] +[:mouse_move, 419, 602, 2, 347, 350] +[:mouse_move, 420, 602, 2, 348, 350] +[:mouse_button_pressed, 1, 0, 1, 349, 352] +[:mouse_button_up, 1, 0, 1, 350, 354] +[:mouse_move, 421, 602, 2, 351, 354] +[:mouse_move, 422, 602, 2, 352, 356] +[:mouse_move, 422, 603, 2, 353, 370] +[:mouse_move, 422, 602, 2, 354, 373] +[:mouse_move, 423, 595, 2, 355, 374] +[:mouse_move, 426, 589, 2, 356, 374] +[:mouse_move, 429, 583, 2, 357, 375] +[:mouse_move, 429, 582, 2, 358, 376] +[:mouse_move, 424, 580, 2, 359, 377] +[:mouse_move, 416, 580, 2, 360, 378] +[:mouse_move, 410, 579, 2, 361, 378] +[:mouse_move, 406, 577, 2, 362, 379] +[:mouse_move, 401, 575, 2, 363, 380] +[:mouse_move, 392, 573, 2, 364, 380] +[:mouse_move, 381, 571, 2, 365, 381] +[:mouse_move, 369, 571, 2, 366, 382] +[:mouse_move, 354, 571, 2, 367, 382] +[:mouse_move, 333, 571, 2, 368, 383] +[:mouse_move, 306, 571, 2, 369, 383] +[:mouse_move, 281, 576, 2, 370, 384] +[:mouse_move, 249, 585, 2, 371, 385] +[:mouse_move, 230, 586, 2, 372, 385] +[:mouse_move, 213, 590, 2, 373, 386] +[:mouse_move, 201, 593, 2, 374, 386] +[:mouse_move, 192, 597, 2, 375, 387] +[:mouse_move, 188, 599, 2, 376, 388] +[:mouse_move, 186, 601, 2, 377, 388] +[:mouse_move, 185, 601, 2, 378, 391] +[:mouse_move, 183, 599, 2, 379, 391] +[:mouse_move, 183, 598, 2, 380, 393] +[:mouse_move, 184, 596, 2, 381, 393] +[:mouse_move, 188, 594, 2, 382, 394] +[:mouse_move, 199, 591, 2, 383, 395] +[:mouse_move, 221, 586, 2, 384, 395] +[:mouse_move, 246, 578, 2, 385, 395] +[:mouse_move, 262, 574, 2, 386, 396] +[:mouse_move, 266, 573, 2, 387, 397] +[:mouse_move, 271, 573, 2, 388, 398] +[:mouse_move, 279, 573, 2, 389, 398] +[:mouse_move, 285, 573, 2, 390, 399] +[:mouse_move, 293, 574, 2, 391, 399] +[:mouse_move, 302, 576, 2, 392, 400] +[:mouse_move, 316, 580, 2, 393, 401] +[:mouse_move, 333, 583, 2, 394, 402] +[:mouse_move, 351, 583, 2, 395, 402] +[:mouse_move, 363, 583, 2, 396, 403] +[:mouse_move, 369, 583, 2, 397, 403] +[:mouse_move, 379, 583, 2, 398, 404] +[:mouse_move, 385, 583, 2, 399, 404] +[:mouse_move, 390, 583, 2, 400, 405] +[:mouse_move, 392, 583, 2, 401, 406] +[:mouse_move, 394, 583, 2, 402, 406] +[:mouse_move, 395, 583, 2, 403, 407] +[:mouse_move, 395, 580, 2, 404, 408] +[:mouse_move, 395, 578, 2, 405, 408] +[:mouse_move, 395, 572, 2, 406, 409] +[:mouse_move, 396, 565, 2, 407, 410] +[:mouse_move, 402, 560, 2, 408, 410] +[:mouse_move, 404, 559, 2, 409, 411] +[:mouse_move, 405, 559, 2, 410, 413] +[:mouse_move, 406, 559, 2, 411, 414] +[:mouse_move, 407, 560, 2, 412, 416] +[:mouse_move, 407, 561, 2, 413, 417] +[:mouse_move, 408, 561, 2, 414, 418] +[:mouse_move, 409, 563, 2, 415, 419] +[:mouse_move, 410, 564, 2, 416, 420] +[:mouse_move, 411, 565, 2, 417, 421] +[:mouse_move, 411, 566, 2, 418, 423] +[:mouse_button_pressed, 1, 0, 1, 419, 424] +[:mouse_button_up, 1, 0, 1, 420, 425] +[:mouse_move, 411, 562, 2, 421, 426] +[:mouse_move, 411, 547, 2, 422, 426] +[:mouse_move, 411, 532, 2, 423, 427] +[:mouse_move, 417, 513, 2, 424, 427] +[:mouse_move, 421, 503, 2, 425, 428] +[:mouse_move, 424, 496, 2, 426, 429] +[:mouse_move, 425, 494, 2, 427, 430] +[:mouse_move, 425, 493, 2, 428, 430] +[:mouse_move, 426, 492, 2, 429, 432] +[:mouse_move, 426, 493, 2, 430, 436] +[:mouse_move, 426, 494, 2, 431, 437] +[:mouse_move, 426, 495, 2, 432, 438] +[:mouse_move, 426, 496, 2, 433, 438] +[:mouse_move, 425, 498, 2, 434, 440] +[:mouse_move, 423, 503, 2, 435, 441] +[:mouse_move, 422, 506, 2, 436, 441] +[:mouse_move, 422, 507, 2, 437, 442] +[:mouse_move, 422, 508, 2, 438, 446] +[:mouse_move, 422, 514, 2, 439, 447] +[:mouse_move, 421, 525, 2, 440, 448] +[:mouse_move, 418, 533, 2, 441, 448] +[:mouse_move, 416, 536, 2, 442, 449] +[:mouse_move, 415, 537, 2, 443, 449] +[:mouse_move, 415, 538, 2, 444, 450] +[:mouse_button_pressed, 1, 0, 1, 445, 455] +[:mouse_move, 414, 538, 2, 446, 456] +[:mouse_button_up, 1, 0, 1, 447, 456] +[:mouse_move, 412, 535, 2, 448, 456] +[:mouse_move, 409, 529, 2, 449, 456] +[:mouse_move, 408, 514, 2, 450, 457] +[:mouse_move, 408, 502, 2, 451, 458] +[:mouse_move, 411, 497, 2, 452, 458] +[:mouse_move, 413, 492, 2, 453, 459] +[:mouse_move, 415, 491, 2, 454, 460] +[:mouse_move, 415, 490, 2, 455, 460] +[:mouse_move, 415, 489, 2, 456, 461] +[:mouse_move, 416, 489, 2, 457, 461] +[:mouse_move, 416, 488, 2, 458, 462] +[:mouse_move, 416, 487, 2, 459, 464] +[:mouse_button_pressed, 1, 0, 1, 460, 465] +[:mouse_button_up, 1, 0, 1, 461, 468] +[:mouse_move, 417, 487, 2, 462, 470] +[:mouse_move, 417, 486, 2, 463, 471] +[:mouse_move, 418, 486, 2, 464, 471] +[:mouse_move, 418, 485, 2, 465, 472] +[:mouse_move, 418, 483, 2, 466, 473] +[:mouse_move, 418, 478, 2, 467, 474] +[:mouse_move, 418, 473, 2, 468, 474] +[:mouse_move, 419, 471, 2, 469, 475] +[:mouse_move, 420, 470, 2, 470, 475] +[:mouse_move, 420, 469, 2, 471, 477] +[:mouse_move, 420, 468, 2, 472, 477] +[:mouse_move, 421, 467, 2, 473, 479] +[:mouse_move, 421, 464, 2, 474, 479] +[:mouse_move, 421, 462, 2, 475, 480] +[:mouse_move, 422, 460, 2, 476, 480] +[:mouse_button_pressed, 1, 0, 1, 477, 482] +[:mouse_button_up, 1, 0, 1, 478, 484] +[:mouse_move, 422, 459, 2, 479, 484] +[:mouse_move, 422, 451, 2, 480, 484] +[:mouse_move, 424, 443, 2, 481, 485] +[:mouse_move, 428, 436, 2, 482, 486] +[:mouse_move, 431, 431, 2, 483, 487] +[:mouse_move, 433, 428, 2, 484, 487] +[:mouse_move, 435, 424, 2, 485, 488] +[:mouse_move, 435, 422, 2, 486, 488] +[:mouse_move, 435, 420, 2, 487, 489] +[:mouse_move, 435, 419, 2, 488, 490] +[:mouse_move, 435, 418, 2, 489, 490] +[:mouse_button_pressed, 1, 0, 1, 490, 494] +[:mouse_button_up, 1, 0, 1, 491, 497] +[:mouse_move, 435, 415, 2, 492, 501] +[:mouse_move, 435, 408, 2, 493, 502] +[:mouse_move, 435, 401, 2, 494, 503] +[:mouse_move, 435, 398, 2, 495, 503] +[:mouse_move, 435, 396, 2, 496, 504] +[:mouse_move, 435, 395, 2, 497, 504] +[:mouse_move, 435, 394, 2, 498, 507] +[:mouse_move, 434, 393, 2, 499, 507] +[:mouse_move, 434, 389, 2, 500, 508] +[:mouse_move, 433, 388, 2, 501, 509] +[:mouse_move, 433, 385, 2, 502, 509] +[:mouse_move, 433, 384, 2, 503, 510] +[:mouse_button_pressed, 1, 0, 1, 504, 514] +[:mouse_button_up, 1, 0, 1, 505, 516] +[:mouse_move, 433, 383, 2, 506, 517] +[:mouse_move, 433, 377, 2, 507, 518] +[:mouse_move, 433, 372, 2, 508, 518] +[:mouse_move, 433, 365, 2, 509, 519] +[:mouse_move, 433, 360, 2, 510, 520] +[:mouse_move, 433, 353, 2, 511, 520] +[:mouse_move, 433, 346, 2, 512, 520] +[:mouse_move, 432, 338, 2, 513, 521] +[:mouse_move, 431, 331, 2, 514, 522] +[:mouse_move, 431, 328, 2, 515, 523] +[:mouse_move, 431, 326, 2, 516, 523] +[:mouse_move, 431, 325, 2, 517, 524] +[:mouse_move, 430, 324, 2, 518, 524] +[:mouse_button_pressed, 1, 0, 1, 519, 528] +[:mouse_button_up, 1, 0, 1, 520, 531] +[:mouse_move, 430, 323, 2, 521, 533] +[:mouse_move, 430, 322, 2, 522, 534] +[:mouse_move, 430, 321, 2, 523, 534] +[:mouse_move, 429, 319, 2, 524, 535] +[:mouse_move, 428, 316, 2, 525, 536] +[:mouse_move, 428, 315, 2, 526, 537] +[:mouse_move, 428, 314, 2, 527, 540] +[:mouse_move, 428, 313, 2, 528, 540] +[:mouse_move, 427, 309, 2, 529, 540] +[:mouse_move, 427, 308, 2, 530, 541] +[:mouse_move, 426, 306, 2, 531, 542] +[:mouse_move, 426, 304, 2, 532, 543] +[:mouse_move, 426, 303, 2, 533, 543] +[:mouse_button_pressed, 1, 0, 1, 534, 544] +[:mouse_button_up, 1, 0, 1, 535, 546] +[:mouse_move, 426, 302, 2, 536, 548] +[:mouse_move, 426, 299, 2, 537, 548] +[:mouse_move, 426, 294, 2, 538, 549] +[:mouse_move, 426, 288, 2, 539, 550] +[:mouse_move, 426, 282, 2, 540, 550] +[:mouse_move, 426, 276, 2, 541, 550] +[:mouse_move, 426, 273, 2, 542, 551] +[:mouse_move, 426, 272, 2, 543, 552] +[:mouse_move, 426, 271, 2, 544, 553] +[:mouse_button_pressed, 1, 0, 1, 545, 556] +[:mouse_button_up, 1, 0, 1, 546, 557] +[:mouse_move, 426, 269, 2, 547, 558] +[:mouse_move, 426, 266, 2, 548, 559] +[:mouse_move, 426, 263, 2, 549, 559] +[:mouse_move, 426, 258, 2, 550, 560] +[:mouse_move, 425, 256, 2, 551, 561] +[:mouse_move, 424, 251, 2, 552, 561] +[:mouse_move, 424, 246, 2, 553, 562] +[:mouse_move, 424, 244, 2, 554, 563] +[:mouse_move, 424, 241, 2, 555, 563] +[:mouse_move, 424, 238, 2, 556, 563] +[:mouse_move, 423, 236, 2, 557, 564] +[:mouse_move, 423, 235, 2, 558, 565] +[:mouse_button_pressed, 1, 0, 1, 559, 568] +[:mouse_button_up, 1, 0, 1, 560, 569] +[:mouse_move, 423, 233, 2, 561, 570] +[:mouse_move, 423, 228, 2, 562, 570] +[:mouse_move, 423, 224, 2, 563, 571] +[:mouse_move, 423, 218, 2, 564, 572] +[:mouse_move, 423, 214, 2, 565, 572] +[:mouse_move, 423, 210, 2, 566, 573] +[:mouse_move, 423, 209, 2, 567, 573] +[:mouse_move, 423, 208, 2, 568, 574] +[:mouse_move, 423, 207, 2, 569, 575] +[:mouse_move, 423, 206, 2, 570, 577] +[:mouse_button_pressed, 1, 0, 1, 571, 582] +[:mouse_button_up, 1, 0, 1, 572, 583] +[:mouse_move, 423, 205, 2, 573, 586] +[:mouse_move, 423, 204, 2, 574, 587] +[:mouse_move, 423, 201, 2, 575, 587] +[:mouse_move, 423, 197, 2, 576, 588] +[:mouse_move, 422, 195, 2, 577, 589] +[:mouse_move, 422, 191, 2, 578, 589] +[:mouse_move, 422, 189, 2, 579, 589] +[:mouse_move, 422, 188, 2, 580, 590] +[:mouse_move, 422, 187, 2, 581, 591] +[:mouse_move, 422, 186, 2, 582, 592] +[:mouse_move, 422, 188, 2, 583, 606] +[:mouse_move, 422, 193, 2, 584, 607] +[:mouse_move, 423, 202, 2, 585, 608] +[:mouse_move, 425, 216, 2, 586, 609] +[:mouse_move, 426, 223, 2, 587, 609] +[:mouse_move, 426, 225, 2, 588, 609] +[:mouse_button_pressed, 1, 0, 1, 589, 613] +[:mouse_button_up, 1, 0, 1, 590, 615] +[:mouse_move, 426, 224, 2, 591, 615] +[:mouse_move, 424, 220, 2, 592, 615] +[:mouse_move, 424, 209, 2, 593, 616] +[:mouse_move, 421, 192, 2, 594, 617] +[:mouse_move, 419, 182, 2, 595, 617] +[:mouse_move, 418, 180, 2, 596, 618] +[:mouse_move, 418, 179, 2, 597, 618] +[:mouse_button_pressed, 1, 0, 1, 598, 624] +[:mouse_button_up, 1, 0, 1, 599, 625] +[:mouse_move, 418, 178, 2, 600, 626] +[:mouse_move, 418, 174, 2, 601, 627] +[:mouse_move, 418, 171, 2, 602, 628] +[:mouse_move, 418, 164, 2, 603, 628] +[:mouse_move, 417, 161, 2, 604, 629] +[:mouse_move, 415, 156, 2, 605, 630] +[:mouse_move, 415, 155, 2, 606, 631] +[:mouse_move, 415, 154, 2, 607, 633] +[:mouse_move, 415, 153, 2, 608, 634] +[:mouse_move, 415, 152, 2, 609, 635] +[:mouse_move, 416, 151, 2, 610, 635] +[:mouse_move, 416, 150, 2, 611, 636] +[:mouse_move, 416, 149, 2, 612, 637] +[:mouse_move, 417, 147, 2, 613, 638] +[:mouse_move, 418, 144, 2, 614, 639] +[:mouse_move, 418, 142, 2, 615, 640] +[:mouse_move, 419, 141, 2, 616, 640] +[:mouse_move, 419, 139, 2, 617, 641] +[:mouse_move, 420, 138, 2, 618, 642] +[:mouse_move, 420, 137, 2, 619, 642] +[:mouse_button_pressed, 1, 0, 1, 620, 643] +[:mouse_button_up, 1, 0, 1, 621, 645] +[:mouse_move, 420, 138, 2, 622, 649] +[:mouse_move, 420, 141, 2, 623, 650] +[:mouse_move, 421, 142, 2, 624, 651] +[:mouse_move, 421, 147, 2, 625, 652] +[:mouse_move, 421, 148, 2, 626, 653] +[:mouse_move, 421, 149, 2, 627, 653] +[:mouse_move, 421, 148, 2, 628, 674] +[:mouse_move, 420, 147, 2, 629, 675] +[:mouse_move, 420, 146, 2, 630, 675] +[:mouse_move, 420, 142, 2, 631, 677] +[:mouse_move, 422, 139, 2, 632, 677] +[:mouse_move, 422, 138, 2, 633, 681] +[:mouse_move, 421, 138, 2, 634, 686] +[:mouse_move, 441, 132, 2, 635, 691] +[:mouse_move, 483, 120, 2, 636, 692] +[:mouse_move, 539, 103, 2, 637, 693] +[:mouse_move, 590, 85, 2, 638, 693] +[:mouse_move, 658, 61, 2, 639, 694] +[:mouse_move, 677, 52, 2, 640, 694] +[:mouse_move, 725, 34, 2, 641, 695] +[:mouse_move, 739, 30, 2, 642, 696] +[:mouse_move, 775, 26, 2, 643, 697] +[:mouse_move, 791, 26, 2, 644, 697] +[:mouse_move, 796, 26, 2, 645, 698] +[:mouse_move, 801, 25, 2, 646, 699] +[:mouse_move, 802, 25, 2, 647, 700] +[:mouse_move, 803, 25, 2, 648, 701] +[:mouse_move, 804, 25, 2, 649, 702] +[:mouse_move, 804, 28, 2, 650, 703] +[:mouse_move, 804, 33, 2, 651, 704] +[:mouse_move, 793, 48, 2, 652, 705] +[:mouse_move, 787, 54, 2, 653, 705] +[:mouse_move, 769, 66, 2, 654, 706] +[:mouse_move, 766, 69, 2, 655, 707] +[:mouse_move, 759, 75, 2, 656, 708] +[:mouse_move, 756, 78, 2, 657, 708] +[:mouse_move, 754, 82, 2, 658, 709] +[:mouse_move, 750, 88, 2, 659, 710] +[:mouse_move, 747, 97, 2, 660, 710] +[:mouse_move, 747, 98, 2, 661, 711] +[:mouse_move, 747, 100, 2, 662, 712] +[:mouse_move, 747, 101, 2, 663, 717] +[:mouse_button_pressed, 1, 0, 1, 664, 717] +[:mouse_button_up, 1, 0, 1, 665, 720] +[:mouse_button_pressed, 1, 0, 1, 666, 723] +[:mouse_button_up, 1, 0, 1, 667, 727] +[:mouse_button_pressed, 1, 0, 1, 668, 731] +[:mouse_move, 747, 100, 2, 669, 731] +[:mouse_button_up, 1, 0, 1, 670, 734] +[:mouse_button_pressed, 1, 0, 1, 671, 737] +[:mouse_button_up, 1, 0, 1, 672, 741] +[:mouse_button_pressed, 1, 0, 1, 673, 744] +[:mouse_button_up, 1, 0, 1, 674, 747] +[:mouse_button_pressed, 1, 0, 1, 675, 751] +[:mouse_button_up, 1, 0, 1, 676, 753] +[:mouse_button_pressed, 1, 0, 1, 677, 757] +[:mouse_move, 748, 100, 2, 678, 757] +[:mouse_button_up, 1, 0, 1, 679, 760] +[:mouse_button_pressed, 1, 0, 1, 680, 764] +[:mouse_button_up, 1, 0, 1, 681, 766] +[:mouse_button_pressed, 1, 0, 1, 682, 769] +[:mouse_button_up, 1, 0, 1, 683, 772] +[:mouse_button_pressed, 1, 0, 1, 684, 775] +[:mouse_button_up, 1, 0, 1, 685, 778] +[:mouse_move, 748, 99, 2, 686, 779] +[:mouse_move, 749, 99, 2, 687, 781] +[:mouse_button_pressed, 1, 0, 1, 688, 781] +[:mouse_button_up, 1, 0, 1, 689, 785] +[:mouse_button_pressed, 1, 0, 1, 690, 788] +[:mouse_button_up, 1, 0, 1, 691, 790] +[:mouse_button_pressed, 1, 0, 1, 692, 795] +[:mouse_button_up, 1, 0, 1, 693, 797] +[:mouse_button_pressed, 1, 0, 1, 694, 800] +[:mouse_button_up, 1, 0, 1, 695, 802] +[:mouse_move, 748, 99, 2, 696, 802] +[:mouse_move, 738, 99, 2, 697, 803] +[:mouse_move, 729, 99, 2, 698, 803] +[:mouse_move, 709, 99, 2, 699, 804] +[:mouse_move, 689, 96, 2, 700, 805] +[:mouse_move, 674, 95, 2, 701, 806] +[:mouse_move, 654, 92, 2, 702, 806] +[:mouse_move, 629, 90, 2, 703, 806] +[:mouse_move, 623, 90, 2, 704, 807] +[:mouse_move, 611, 90, 2, 705, 808] +[:mouse_move, 610, 90, 2, 706, 808] +[:mouse_move, 609, 90, 2, 707, 809] +[:mouse_move, 611, 90, 2, 708, 811] +[:mouse_button_pressed, 1, 0, 1, 709, 811] +[:mouse_move, 612, 90, 2, 710, 811] +[:mouse_button_up, 1, 0, 1, 711, 813] +[:mouse_move, 613, 90, 2, 712, 813] +[:key_down_raw, 96, 0, 2, 713, 986] +[:key_up_raw, 96, 0, 2, 714, 987] +[:key_down_raw, 13, 0, 2, 715, 1004] diff --git a/samples/13_path_finding_algorithms/07_heuristic_with_walls/app/main.rb b/samples/13_path_finding_algorithms/07_heuristic_with_walls/app/main.rb index 5fc0804..2dc3e74 100644 --- a/samples/13_path_finding_algorithms/07_heuristic_with_walls/app/main.rb +++ b/samples/13_path_finding_algorithms/07_heuristic_with_walls/app/main.rb @@ -10,13 +10,13 @@ class Heuristic def tick defaults - render - input + render + input # If animation is playing, and max steps have not been reached # Move the search a step forward if state.play && state.current_step < state.max_steps # Variable that tells the program what step to recalculate up to - state.current_step += 1 + state.current_step += 1 move_searches_one_step_forward end end @@ -71,7 +71,7 @@ class Heuristic # We store this value, because we want to remember the value even when # the user's cursor is no longer over what they're interacting with, but # they are still clicking down on the mouse. - state.user_input ||= :none + state.user_input ||= :none # These variables allow the breadth first search to take place # Came_from is a hash with a key of a cell and a value of the cell that was expanded from to find the key. @@ -96,7 +96,7 @@ class Heuristic # Unless the current step has a value unless state.current_step # Set the current step to 10 - state.current_step = 10 + state.current_step = 10 # And calculate the searches up to step 10 recalculate_searches end @@ -106,7 +106,7 @@ class Heuristic # This step is roughly the grid's width * height # When anim_steps equals max_steps no more calculations will occur # and the slider will be at the end - state.max_steps = grid.width * grid.height + state.max_steps = grid.width * grid.height # Whether the animation should play or not # If true, every tick moves anim_steps forward one @@ -199,7 +199,7 @@ class Heuristic # If the mouse was clicked this tick if inputs.mouse.down # Determine what the user is editing and appropriately edit the state.user_input variable - determine_input + determine_input end # Process user input based on user_input variable and current mouse position @@ -212,35 +212,35 @@ class Heuristic if mouse_over_slider? state.user_input = :slider # If the mouse is over the star in the first grid - elsif bfs_mouse_over_star? + elsif bfs_mouse_over_star? # The user is editing the star from the first grid - state.user_input = :bfs_star + state.user_input = :bfs_star # If the mouse is over the star in the second grid - elsif heuristic_mouse_over_star? + elsif heuristic_mouse_over_star? # The user is editing the star from the second grid - state.user_input = :heuristic_star + state.user_input = :heuristic_star # If the mouse is over the target in the first grid - elsif bfs_mouse_over_target? + elsif bfs_mouse_over_target? # The user is editing the target from the first grid - state.user_input = :bfs_target + state.user_input = :bfs_target # If the mouse is over the target in the second grid - elsif heuristic_mouse_over_target? + elsif heuristic_mouse_over_target? # The user is editing the target from the second grid - state.user_input = :heuristic_target + state.user_input = :heuristic_target # If the mouse is over a wall in the first grid - elsif bfs_mouse_over_wall? + elsif bfs_mouse_over_wall? # The user is removing a wall from the first grid - state.user_input = :bfs_remove_wall + state.user_input = :bfs_remove_wall # If the mouse is over a wall in the second grid - elsif heuristic_mouse_over_wall? + elsif heuristic_mouse_over_wall? # The user is removing a wall from the second grid state.user_input = :heuristic_remove_wall # If the mouse is over the first grid - elsif bfs_mouse_over_grid? + elsif bfs_mouse_over_grid? # The user is adding a wall from the first grid state.user_input = :bfs_add_wall # If the mouse is over the second grid - elsif heuristic_mouse_over_grid? + elsif heuristic_mouse_over_grid? # The user is adding a wall from the second grid state.user_input = :heuristic_add_wall end @@ -250,22 +250,22 @@ class Heuristic def process_input if state.user_input == :slider process_input_slider - elsif state.user_input == :bfs_star - process_input_bfs_star + elsif state.user_input == :bfs_star + process_input_bfs_star elsif state.user_input == :heuristic_star - process_input_heuristic_star - elsif state.user_input == :bfs_target - process_input_bfs_target - elsif state.user_input == :heuristic_target - process_input_heuristic_target - elsif state.user_input == :bfs_remove_wall - process_input_bfs_remove_wall + process_input_heuristic_star + elsif state.user_input == :bfs_target + process_input_bfs_target + elsif state.user_input == :heuristic_target + process_input_heuristic_target + elsif state.user_input == :bfs_remove_wall + process_input_bfs_remove_wall elsif state.user_input == :heuristic_remove_wall - process_input_heuristic_remove_wall - elsif state.user_input == :bfs_add_wall - process_input_bfs_add_wall - elsif state.user_input == :heuristic_add_wall - process_input_heuristic_add_wall + process_input_heuristic_remove_wall + elsif state.user_input == :bfs_add_wall + process_input_bfs_add_wall + elsif state.user_input == :heuristic_add_wall + process_input_heuristic_add_wall end end @@ -342,7 +342,7 @@ class Heuristic # The horizontal grid lines for y in 0..grid.height - outputs.lines << bfs_horizontal_line(y) + outputs.lines << bfs_horizontal_line(y) end end @@ -357,10 +357,10 @@ class Heuristic # The horizontal grid lines for y in 0..grid.height - outputs.lines << heuristic_horizontal_line(y) + outputs.lines << heuristic_horizontal_line(y) end end - + # Returns a vertical line for a column of the first grid def bfs_vertical_line column bfs_scale_up([column, 0, column, grid.height]) @@ -395,7 +395,7 @@ class Heuristic def render_bfs_target outputs.sprites << [bfs_scale_up(grid.target), 'target.png'] end - + # Renders the target on the second grid def render_heuristic_target outputs.sprites << [heuristic_scale_up(grid.target), 'target.png'] @@ -403,14 +403,14 @@ class Heuristic # Renders the walls on the first grid def render_bfs_walls - grid.walls.each_key do | wall | + grid.walls.each_key do | wall | outputs.solids << [bfs_scale_up(wall), wall_color] end end # Renders the walls on the second grid def render_heuristic_walls - grid.walls.each_key do | wall | + grid.walls.each_key do | wall | outputs.solids << [heuristic_scale_up(wall), wall_color] end end @@ -431,14 +431,14 @@ class Heuristic # Renders the frontier cells on the first grid def render_bfs_frontier - bfs.frontier.each do | frontier_cell | + bfs.frontier.each do | frontier_cell | outputs.solids << [bfs_scale_up(frontier_cell), frontier_color, 200] end end # Renders the frontier cells on the second grid def render_heuristic_frontier - heuristic.frontier.each do | frontier_cell | + heuristic.frontier.each do | frontier_cell | outputs.solids << [heuristic_scale_up(frontier_cell), frontier_color, 200] end end @@ -522,14 +522,14 @@ class Heuristic # Checks and handles input for the buttons # Called when the mouse is lifted def input_buttons - input_left_button - input_center_button - input_right_button + input_left_button + input_center_button + input_right_button end # Checks if the previous step button is clicked # If it is, it pauses the animation and moves the search one step backward - def input_left_button + def input_left_button if left_button_clicked? state.play = false state.current_step -= 1 @@ -541,7 +541,7 @@ class Heuristic # Inverses whether the animation is playing or not when clicked def input_center_button if center_button_clicked? || inputs.keyboard.key_down.space - state.play = !state.play + state.play = !state.play end end @@ -549,8 +549,8 @@ class Heuristic # If it is, it pauses the animation and moves the search one step forward def input_right_button if right_button_clicked? - state.play = false - state.current_step += 1 + state.play = false + state.current_step += 1 move_searches_one_step_forward end end @@ -631,12 +631,12 @@ class Heuristic # on the slider # Changes the step of the search to be animated def process_input_slider - state.play = false + state.play = false mouse_x = inputs.mouse.point.x # Bounds the mouse_x to the closest x value on the slider line - mouse_x = slider.x if mouse_x < slider.x - mouse_x = slider.x + slider.w if mouse_x > slider.x + slider.w + mouse_x = slider.x if mouse_x < slider.x + mouse_x = slider.x + slider.w if mouse_x > slider.x + slider.w # Sets the current search step to the one represented by the mouse x value # The slider's circle moves due to the render_slider method using anim_steps @@ -649,12 +649,12 @@ class Heuristic # Only resets the search if the star changes position # Called whenever the user is editing the star (puts mouse down on star) def process_input_bfs_star - old_star = grid.star.clone + old_star = grid.star.clone unless bfs_cell_closest_to_mouse == grid.target - grid.star = bfs_cell_closest_to_mouse + grid.star = bfs_cell_closest_to_mouse end - unless old_star == grid.star - recalculate_searches + unless old_star == grid.star + recalculate_searches end end @@ -662,12 +662,12 @@ class Heuristic # Only resets the search if the star changes position # Called whenever the user is editing the star (puts mouse down on star) def process_input_heuristic_star - old_star = grid.star.clone + old_star = grid.star.clone unless heuristic_cell_closest_to_mouse == grid.target grid.star = heuristic_cell_closest_to_mouse end - unless old_star == grid.star - recalculate_searches + unless old_star == grid.star + recalculate_searches end end @@ -675,12 +675,12 @@ class Heuristic # Only recalculate_searchess the search if the target changes position # Called whenever the user is editing the target (puts mouse down on target) def process_input_bfs_target - old_target = grid.target.clone + old_target = grid.target.clone unless bfs_cell_closest_to_mouse == grid.star grid.target = bfs_cell_closest_to_mouse end - unless old_target == grid.target - recalculate_searches + unless old_target == grid.target + recalculate_searches end end @@ -688,12 +688,12 @@ class Heuristic # Only recalculate_searchess the search if the target changes position # Called whenever the user is editing the target (puts mouse down on target) def process_input_heuristic_target - old_target = grid.target.clone + old_target = grid.target.clone unless heuristic_cell_closest_to_mouse == grid.star grid.target = heuristic_cell_closest_to_mouse end - unless old_target == grid.target - recalculate_searches + unless old_target == grid.target + recalculate_searches end end @@ -702,10 +702,10 @@ class Heuristic # The mouse needs to be inside the grid, because we only want to remove walls # the cursor is directly over # Recalculations should only occur when a wall is actually deleted - if bfs_mouse_over_grid? + if bfs_mouse_over_grid? if grid.walls.has_key?(bfs_cell_closest_to_mouse) - grid.walls.delete(bfs_cell_closest_to_mouse) - recalculate_searches + grid.walls.delete(bfs_cell_closest_to_mouse) + recalculate_searches end end end @@ -715,29 +715,29 @@ class Heuristic # The mouse needs to be inside the grid, because we only want to remove walls # the cursor is directly over # Recalculations should only occur when a wall is actually deleted - if heuristic_mouse_over_grid? + if heuristic_mouse_over_grid? if grid.walls.has_key?(heuristic_cell_closest_to_mouse) - grid.walls.delete(heuristic_cell_closest_to_mouse) - recalculate_searches + grid.walls.delete(heuristic_cell_closest_to_mouse) + recalculate_searches end end end # Adds a wall in the first grid in the cell the mouse is over def process_input_bfs_add_wall - if bfs_mouse_over_grid? + if bfs_mouse_over_grid? unless grid.walls.has_key?(bfs_cell_closest_to_mouse) - grid.walls[bfs_cell_closest_to_mouse] = true - recalculate_searches + grid.walls[bfs_cell_closest_to_mouse] = true + recalculate_searches end end end # Adds a wall in the second grid in the cell the mouse is over def process_input_heuristic_add_wall - if heuristic_mouse_over_grid? + if heuristic_mouse_over_grid? unless grid.walls.has_key?(heuristic_cell_closest_to_mouse) - grid.walls[heuristic_cell_closest_to_mouse] = true - recalculate_searches + grid.walls[heuristic_cell_closest_to_mouse] = true + recalculate_searches end end end @@ -747,13 +747,13 @@ class Heuristic # Finding the cell closest to the mouse helps with this def bfs_cell_closest_to_mouse # Closest cell to the mouse in the first grid - x = (inputs.mouse.point.x / grid.cell_size).to_i - y = (inputs.mouse.point.y / grid.cell_size).to_i + x = (inputs.mouse.point.x / grid.cell_size).to_i + y = (inputs.mouse.point.y / grid.cell_size).to_i # Bound x and y to the grid - x = grid.width - 1 if x > grid.width - 1 - y = grid.height - 1 if y > grid.height - 1 + x = grid.width - 1 if x > grid.width - 1 + y = grid.height - 1 if y > grid.height - 1 # Return closest cell - [x, y] + [x, y] end # When the user grabs the star and puts their cursor to the far right @@ -761,17 +761,17 @@ class Heuristic # Finding the cell closest to the mouse in the second grid helps with this def heuristic_cell_closest_to_mouse # Closest cell grid to the mouse in the second - x = (inputs.mouse.point.x / grid.cell_size).to_i - y = (inputs.mouse.point.y / grid.cell_size).to_i + x = (inputs.mouse.point.x / grid.cell_size).to_i + y = (inputs.mouse.point.y / grid.cell_size).to_i # Translate the cell to the first grid x -= grid.width + 1 # Bound x and y to the first grid x = 0 if x < 0 y = 0 if y < 0 - x = grid.width - 1 if x > grid.width - 1 - y = grid.height - 1 if y > grid.height - 1 + x = grid.width - 1 if x > grid.width - 1 + y = grid.height - 1 if y > grid.height - 1 # Return closest cell - [x, y] + [x, y] end def recalculate_searches @@ -796,22 +796,22 @@ class Heuristic return if bfs.came_from.has_key?(grid.target) # Only runs at the beginning of the search as setup. - if bfs.came_from.empty? - bfs.frontier << grid.star - bfs.came_from[grid.star] = nil + if bfs.came_from.empty? + bfs.frontier << grid.star + bfs.came_from[grid.star] = nil end # A step in the search - unless bfs.frontier.empty? + unless bfs.frontier.empty? # Takes the next frontier cell - new_frontier = bfs.frontier.shift + new_frontier = bfs.frontier.shift # For each of its neighbors - adjacent_neighbors(new_frontier).each do |neighbor| + adjacent_neighbors(new_frontier).each do |neighbor| # That have not been visited and are not walls - unless bfs.came_from.has_key?(neighbor) || grid.walls.has_key?(neighbor) + unless bfs.came_from.has_key?(neighbor) || grid.walls.has_key?(neighbor) # Add them to the frontier and mark them as visited - bfs.frontier << neighbor - bfs.came_from[neighbor] = new_frontier + bfs.frontier << neighbor + bfs.came_from[neighbor] = new_frontier end end end @@ -866,12 +866,12 @@ class Heuristic # Get the next cell to explore from new_frontier = heuristic.frontier.shift # For each of its neighbors - adjacent_neighbors(new_frontier).each do |neighbor| + adjacent_neighbors(new_frontier).each do |neighbor| # That have not been visited and are not walls - unless heuristic.came_from.has_key?(neighbor) || grid.walls.has_key?(neighbor) + unless heuristic.came_from.has_key?(neighbor) || grid.walls.has_key?(neighbor) # Add them to the frontier and mark them as visited - heuristic.frontier << neighbor - heuristic.came_from[neighbor] = new_frontier + heuristic.frontier << neighbor + heuristic.came_from[neighbor] = new_frontier end end end @@ -915,16 +915,16 @@ class Heuristic # Returns a list of adjacent cells # Used to determine what the next cells to be added to the frontier are def adjacent_neighbors(cell) - neighbors = [] + neighbors = [] # Gets all the valid neighbors into the array # From southern neighbor, clockwise - neighbors << [cell.x , cell.y - 1] unless cell.y == 0 - neighbors << [cell.x - 1, cell.y ] unless cell.x == 0 - neighbors << [cell.x , cell.y + 1] unless cell.y == grid.height - 1 - neighbors << [cell.x + 1, cell.y ] unless cell.x == grid.width - 1 + neighbors << [cell.x , cell.y - 1] unless cell.y == 0 + neighbors << [cell.x - 1, cell.y ] unless cell.x == 0 + neighbors << [cell.x , cell.y + 1] unless cell.y == grid.height - 1 + neighbors << [cell.x + 1, cell.y ] unless cell.x == grid.width - 1 - neighbors + neighbors end # Finds the vertical and horizontal distance of a cell from the star @@ -973,7 +973,7 @@ class Heuristic def wall_color [134, 134, 120] # Camo Green end - + def visited_color [204, 191, 179] # Dark Brown end @@ -981,7 +981,7 @@ class Heuristic def frontier_color [103, 136, 204] # Blue end - + def path_color [231, 230, 228] # Pastel White end @@ -1002,7 +1002,7 @@ def tick args end # Every tick, new args are passed, and the Breadth First Search tick is called - $heuristic ||= Heuristic.new(args) + $heuristic ||= Heuristic.new $heuristic.args = args $heuristic.tick end diff --git a/samples/13_path_finding_algorithms/07_heuristic_with_walls/replay.txt b/samples/13_path_finding_algorithms/07_heuristic_with_walls/replay.txt new file mode 100644 index 0000000..4c5a2a6 --- /dev/null +++ b/samples/13_path_finding_algorithms/07_heuristic_with_walls/replay.txt @@ -0,0 +1,352 @@ +replay_version 2.0 +stopped_at 637 +seed 100 +recorded_at 2021-11-20 11:23:35 -0600 +[:mouse_button_up, 1, 0, 1, 1, 2] +[:mouse_move, 777, 81, 2, 2, 5] +[:mouse_move, 778, 83, 2, 3, 23] +[:mouse_move, 778, 91, 2, 4, 24] +[:mouse_move, 778, 97, 2, 5, 25] +[:mouse_move, 778, 101, 2, 6, 26] +[:mouse_move, 777, 106, 2, 7, 26] +[:mouse_move, 774, 112, 2, 8, 27] +[:mouse_move, 769, 116, 2, 9, 28] +[:mouse_move, 765, 119, 2, 10, 29] +[:mouse_move, 763, 120, 2, 11, 29] +[:mouse_move, 762, 120, 2, 12, 30] +[:mouse_move, 761, 121, 2, 13, 31] +[:mouse_move, 761, 122, 2, 14, 32] +[:mouse_move, 760, 123, 2, 15, 32] +[:mouse_move, 760, 124, 2, 16, 33] +[:mouse_move, 759, 125, 2, 17, 34] +[:mouse_move, 758, 126, 2, 18, 36] +[:mouse_move, 757, 126, 2, 19, 37] +[:mouse_move, 754, 127, 2, 20, 38] +[:mouse_move, 753, 127, 2, 21, 39] +[:mouse_move, 752, 127, 2, 22, 40] +[:mouse_move, 753, 127, 2, 23, 56] +[:mouse_move, 752, 127, 2, 24, 65] +[:mouse_move, 745, 127, 2, 25, 66] +[:mouse_move, 737, 127, 2, 26, 67] +[:mouse_move, 726, 125, 2, 27, 68] +[:mouse_move, 716, 122, 2, 28, 68] +[:mouse_move, 709, 120, 2, 29, 69] +[:mouse_move, 697, 117, 2, 30, 70] +[:mouse_move, 691, 115, 2, 31, 71] +[:mouse_move, 689, 114, 2, 32, 72] +[:mouse_move, 686, 113, 2, 33, 72] +[:mouse_move, 686, 112, 2, 34, 73] +[:mouse_move, 685, 112, 2, 35, 74] +[:mouse_move, 684, 112, 2, 36, 75] +[:mouse_move, 683, 112, 2, 37, 76] +[:mouse_move, 682, 111, 2, 38, 77] +[:mouse_move, 679, 110, 2, 39, 77] +[:mouse_move, 674, 108, 2, 40, 78] +[:mouse_move, 665, 104, 2, 41, 79] +[:mouse_move, 660, 101, 2, 42, 80] +[:mouse_move, 657, 101, 2, 43, 81] +[:mouse_move, 657, 100, 2, 44, 89] +[:mouse_button_pressed, 1, 0, 1, 45, 109] +[:mouse_button_up, 1, 0, 1, 46, 113] +[:mouse_button_pressed, 1, 0, 1, 47, 228] +[:mouse_button_up, 1, 0, 1, 48, 229] +[:mouse_move, 657, 99, 2, 49, 240] +[:mouse_move, 656, 96, 2, 50, 240] +[:mouse_move, 655, 95, 2, 51, 240] +[:mouse_move, 654, 94, 2, 52, 241] +[:mouse_move, 654, 87, 2, 53, 242] +[:mouse_move, 654, 80, 2, 54, 242] +[:mouse_move, 654, 74, 2, 55, 242] +[:mouse_move, 654, 69, 2, 56, 242] +[:mouse_move, 654, 67, 2, 57, 243] +[:mouse_move, 654, 63, 2, 58, 243] +[:mouse_move, 654, 62, 2, 59, 244] +[:mouse_move, 653, 61, 2, 60, 244] +[:mouse_move, 651, 61, 2, 61, 245] +[:mouse_move, 648, 60, 2, 62, 246] +[:mouse_move, 645, 60, 2, 63, 246] +[:mouse_move, 637, 57, 2, 64, 246] +[:mouse_move, 633, 55, 2, 65, 246] +[:mouse_move, 626, 53, 2, 66, 247] +[:mouse_move, 620, 51, 2, 67, 247] +[:mouse_move, 593, 47, 2, 68, 247] +[:mouse_move, 580, 45, 2, 69, 248] +[:mouse_move, 577, 45, 2, 70, 248] +[:mouse_move, 576, 45, 2, 71, 248] +[:mouse_move, 576, 44, 2, 72, 251] +[:mouse_button_pressed, 1, 0, 1, 73, 251] +[:mouse_button_up, 1, 0, 1, 74, 253] +[:mouse_move, 577, 44, 2, 75, 257] +[:mouse_move, 578, 45, 2, 76, 257] +[:mouse_move, 584, 45, 2, 77, 258] +[:mouse_move, 594, 47, 2, 78, 258] +[:mouse_move, 606, 48, 2, 79, 258] +[:mouse_move, 619, 50, 2, 80, 259] +[:mouse_move, 627, 50, 2, 81, 259] +[:mouse_move, 629, 50, 2, 82, 259] +[:mouse_move, 630, 50, 2, 83, 259] +[:mouse_move, 631, 50, 2, 84, 260] +[:mouse_move, 632, 50, 2, 85, 261] +[:mouse_button_pressed, 1, 0, 1, 86, 263] +[:mouse_move, 629, 50, 2, 87, 264] +[:mouse_move, 624, 50, 2, 88, 264] +[:mouse_move, 617, 50, 2, 89, 264] +[:mouse_move, 612, 50, 2, 90, 264] +[:mouse_move, 609, 50, 2, 91, 264] +[:mouse_move, 607, 50, 2, 92, 264] +[:mouse_move, 603, 49, 2, 93, 264] +[:mouse_move, 600, 49, 2, 94, 264] +[:mouse_move, 597, 48, 2, 95, 265] +[:mouse_move, 595, 48, 2, 96, 265] +[:mouse_move, 594, 48, 2, 97, 265] +[:mouse_move, 593, 48, 2, 98, 265] +[:mouse_move, 592, 48, 2, 99, 265] +[:mouse_move, 590, 48, 2, 100, 265] +[:mouse_move, 587, 48, 2, 101, 265] +[:mouse_move, 582, 48, 2, 102, 265] +[:mouse_move, 575, 48, 2, 103, 265] +[:mouse_move, 571, 47, 2, 104, 265] +[:mouse_move, 568, 47, 2, 105, 265] +[:mouse_move, 567, 47, 2, 106, 266] +[:mouse_move, 566, 47, 2, 107, 266] +[:mouse_move, 565, 46, 2, 108, 266] +[:mouse_move, 564, 46, 2, 109, 266] +[:mouse_move, 563, 46, 2, 110, 266] +[:mouse_move, 562, 46, 2, 111, 266] +[:mouse_move, 561, 46, 2, 112, 266] +[:mouse_move, 560, 46, 2, 113, 267] +[:mouse_move, 559, 46, 2, 114, 267] +[:mouse_move, 558, 46, 2, 115, 267] +[:mouse_move, 555, 46, 2, 116, 268] +[:mouse_move, 551, 46, 2, 117, 268] +[:mouse_move, 549, 46, 2, 118, 268] +[:mouse_move, 548, 46, 2, 119, 268] +[:mouse_move, 547, 46, 2, 120, 268] +[:mouse_move, 546, 46, 2, 121, 269] +[:mouse_move, 545, 46, 2, 122, 269] +[:mouse_move, 540, 46, 2, 123, 269] +[:mouse_move, 534, 46, 2, 124, 269] +[:mouse_move, 531, 46, 2, 125, 269] +[:mouse_move, 527, 46, 2, 126, 269] +[:mouse_move, 525, 46, 2, 127, 269] +[:mouse_button_up, 1, 0, 1, 128, 276] +[:mouse_move, 526, 47, 2, 129, 287] +[:mouse_move, 527, 47, 2, 130, 288] +[:mouse_move, 528, 48, 2, 131, 290] +[:mouse_move, 531, 51, 2, 132, 290] +[:mouse_move, 534, 54, 2, 133, 290] +[:mouse_move, 539, 61, 2, 134, 291] +[:mouse_move, 548, 71, 2, 135, 291] +[:mouse_move, 558, 81, 2, 136, 292] +[:mouse_move, 570, 94, 2, 137, 292] +[:mouse_move, 585, 110, 2, 138, 293] +[:mouse_move, 595, 123, 2, 139, 293] +[:mouse_move, 607, 136, 2, 140, 293] +[:mouse_move, 618, 146, 2, 141, 294] +[:mouse_move, 626, 154, 2, 142, 295] +[:mouse_move, 632, 161, 2, 143, 295] +[:mouse_move, 633, 162, 2, 144, 296] +[:mouse_move, 633, 163, 2, 145, 296] +[:mouse_move, 634, 164, 2, 146, 296] +[:mouse_move, 634, 165, 2, 147, 297] +[:mouse_move, 635, 168, 2, 148, 297] +[:mouse_move, 635, 172, 2, 149, 298] +[:mouse_move, 635, 178, 2, 150, 299] +[:mouse_move, 635, 182, 2, 151, 299] +[:mouse_move, 635, 183, 2, 152, 299] +[:mouse_move, 635, 184, 2, 153, 300] +[:mouse_move, 634, 187, 2, 154, 300] +[:mouse_move, 632, 191, 2, 155, 301] +[:mouse_move, 629, 193, 2, 156, 301] +[:mouse_move, 627, 194, 2, 157, 302] +[:mouse_move, 625, 194, 2, 158, 302] +[:mouse_move, 625, 195, 2, 159, 303] +[:mouse_move, 624, 195, 2, 160, 304] +[:mouse_move, 619, 195, 2, 161, 305] +[:mouse_move, 608, 195, 2, 162, 305] +[:mouse_move, 597, 194, 2, 163, 305] +[:mouse_move, 584, 188, 2, 164, 306] +[:mouse_move, 572, 180, 2, 165, 307] +[:mouse_move, 563, 173, 2, 166, 307] +[:mouse_move, 556, 166, 2, 167, 308] +[:mouse_move, 550, 160, 2, 168, 308] +[:mouse_move, 548, 157, 2, 169, 308] +[:mouse_move, 547, 154, 2, 170, 309] +[:mouse_move, 542, 149, 2, 171, 309] +[:mouse_move, 538, 142, 2, 172, 310] +[:mouse_move, 533, 134, 2, 173, 310] +[:mouse_move, 531, 132, 2, 174, 311] +[:mouse_move, 530, 132, 2, 175, 311] +[:mouse_move, 530, 131, 2, 176, 312] +[:mouse_move, 528, 129, 2, 177, 312] +[:mouse_move, 524, 127, 2, 178, 312] +[:mouse_move, 523, 126, 2, 179, 313] +[:mouse_move, 522, 126, 2, 180, 314] +[:mouse_move, 520, 124, 2, 181, 314] +[:mouse_move, 512, 118, 2, 182, 315] +[:mouse_move, 502, 112, 2, 183, 316] +[:mouse_move, 498, 108, 2, 184, 316] +[:mouse_move, 495, 107, 2, 185, 317] +[:mouse_move, 495, 106, 2, 186, 317] +[:mouse_move, 493, 105, 2, 187, 317] +[:mouse_move, 493, 104, 2, 188, 318] +[:mouse_move, 492, 104, 2, 189, 318] +[:mouse_move, 492, 103, 2, 190, 319] +[:mouse_button_pressed, 1, 0, 1, 191, 326] +[:mouse_button_up, 1, 0, 1, 192, 328] +[:mouse_button_pressed, 1, 0, 1, 193, 339] +[:mouse_button_up, 1, 0, 1, 194, 342] +[:mouse_button_pressed, 1, 0, 1, 195, 343] +[:mouse_button_up, 1, 0, 1, 196, 344] +[:mouse_button_pressed, 1, 0, 1, 197, 345] +[:mouse_button_up, 1, 0, 1, 198, 347] +[:mouse_move, 493, 103, 2, 199, 348] +[:mouse_move, 497, 103, 2, 200, 348] +[:mouse_move, 507, 103, 2, 201, 348] +[:mouse_move, 522, 103, 2, 202, 349] +[:mouse_move, 542, 103, 2, 203, 349] +[:mouse_move, 566, 103, 2, 204, 350] +[:mouse_move, 595, 103, 2, 205, 350] +[:mouse_move, 627, 103, 2, 206, 351] +[:mouse_move, 655, 103, 2, 207, 351] +[:mouse_move, 678, 103, 2, 208, 352] +[:mouse_move, 693, 103, 2, 209, 352] +[:mouse_move, 698, 103, 2, 210, 353] +[:mouse_move, 699, 103, 2, 211, 353] +[:mouse_move, 702, 103, 2, 212, 354] +[:mouse_move, 704, 103, 2, 213, 354] +[:mouse_move, 708, 103, 2, 214, 354] +[:mouse_move, 709, 103, 2, 215, 355] +[:mouse_move, 711, 103, 2, 216, 356] +[:mouse_move, 714, 103, 2, 217, 357] +[:mouse_move, 715, 103, 2, 218, 357] +[:mouse_move, 719, 103, 2, 219, 357] +[:mouse_move, 721, 103, 2, 220, 358] +[:mouse_move, 723, 103, 2, 221, 359] +[:mouse_move, 724, 103, 2, 222, 359] +[:mouse_move, 725, 103, 2, 223, 364] +[:mouse_move, 729, 101, 2, 224, 365] +[:mouse_move, 732, 101, 2, 225, 365] +[:mouse_move, 734, 100, 2, 226, 366] +[:mouse_move, 735, 99, 2, 227, 367] +[:mouse_button_pressed, 1, 0, 1, 228, 368] +[:mouse_button_up, 1, 0, 1, 229, 371] +[:mouse_button_pressed, 1, 0, 1, 230, 373] +[:mouse_button_up, 1, 0, 1, 231, 375] +[:mouse_button_pressed, 1, 0, 1, 232, 378] +[:mouse_button_up, 1, 0, 1, 233, 380] +[:mouse_button_pressed, 1, 0, 1, 234, 383] +[:mouse_button_up, 1, 0, 1, 235, 385] +[:mouse_button_pressed, 1, 0, 1, 236, 387] +[:mouse_button_up, 1, 0, 1, 237, 389] +[:mouse_move, 736, 99, 2, 238, 390] +[:mouse_button_pressed, 1, 0, 1, 239, 392] +[:mouse_button_up, 1, 0, 1, 240, 395] +[:mouse_button_pressed, 1, 0, 1, 241, 432] +[:mouse_button_up, 1, 0, 1, 242, 434] +[:mouse_move, 736, 103, 2, 243, 446] +[:mouse_move, 736, 113, 2, 244, 446] +[:mouse_move, 734, 125, 2, 245, 447] +[:mouse_move, 732, 140, 2, 246, 447] +[:mouse_move, 726, 158, 2, 247, 448] +[:mouse_move, 718, 174, 2, 248, 448] +[:mouse_move, 712, 193, 2, 249, 448] +[:mouse_move, 709, 203, 2, 250, 449] +[:mouse_move, 709, 208, 2, 251, 449] +[:mouse_move, 708, 211, 2, 252, 450] +[:mouse_move, 708, 212, 2, 253, 451] +[:mouse_move, 708, 213, 2, 254, 451] +[:mouse_move, 707, 215, 2, 255, 451] +[:mouse_move, 704, 217, 2, 256, 452] +[:mouse_move, 700, 221, 2, 257, 452] +[:mouse_move, 698, 223, 2, 258, 453] +[:mouse_move, 697, 223, 2, 259, 454] +[:mouse_move, 699, 223, 2, 260, 455] +[:mouse_move, 700, 222, 2, 261, 455] +[:mouse_move, 701, 222, 2, 262, 456] +[:mouse_move, 702, 222, 2, 263, 456] +[:mouse_move, 702, 221, 2, 264, 457] +[:mouse_button_pressed, 1, 0, 1, 265, 458] +[:mouse_button_up, 1, 0, 1, 266, 459] +[:mouse_move, 695, 221, 2, 267, 468] +[:mouse_move, 684, 221, 2, 268, 469] +[:mouse_move, 673, 221, 2, 269, 469] +[:mouse_move, 663, 221, 2, 270, 470] +[:mouse_move, 656, 221, 2, 271, 470] +[:mouse_move, 655, 221, 2, 272, 471] +[:mouse_button_pressed, 1, 0, 1, 273, 475] +[:mouse_button_up, 1, 0, 1, 274, 476] +[:mouse_move, 657, 218, 2, 275, 479] +[:mouse_move, 661, 213, 2, 276, 479] +[:mouse_move, 670, 201, 2, 277, 479] +[:mouse_move, 679, 190, 2, 278, 479] +[:mouse_move, 687, 178, 2, 279, 480] +[:mouse_move, 695, 165, 2, 280, 481] +[:mouse_move, 703, 151, 2, 281, 481] +[:mouse_move, 712, 139, 2, 282, 482] +[:mouse_move, 720, 129, 2, 283, 482] +[:mouse_move, 727, 121, 2, 284, 482] +[:mouse_move, 735, 111, 2, 285, 483] +[:mouse_move, 737, 108, 2, 286, 483] +[:mouse_move, 739, 105, 2, 287, 484] +[:mouse_move, 739, 104, 2, 288, 484] +[:mouse_move, 740, 103, 2, 289, 485] +[:mouse_move, 740, 102, 2, 290, 485] +[:mouse_move, 740, 101, 2, 291, 486] +[:mouse_move, 740, 100, 2, 292, 488] +[:mouse_button_pressed, 1, 0, 1, 293, 489] +[:mouse_move, 740, 99, 2, 294, 490] +[:mouse_button_up, 1, 0, 1, 295, 491] +[:mouse_button_pressed, 1, 0, 1, 296, 493] +[:mouse_move, 740, 100, 2, 297, 493] +[:mouse_button_up, 1, 0, 1, 298, 496] +[:mouse_button_pressed, 1, 0, 1, 299, 498] +[:mouse_button_up, 1, 0, 1, 300, 500] +[:mouse_button_pressed, 1, 0, 1, 301, 502] +[:mouse_button_up, 1, 0, 1, 302, 505] +[:mouse_button_pressed, 1, 0, 1, 303, 508] +[:mouse_button_up, 1, 0, 1, 304, 509] +[:mouse_button_pressed, 1, 0, 1, 305, 511] +[:mouse_button_up, 1, 0, 1, 306, 514] +[:mouse_button_pressed, 1, 0, 1, 307, 516] +[:mouse_button_up, 1, 0, 1, 308, 518] +[:mouse_button_pressed, 1, 0, 1, 309, 520] +[:mouse_button_up, 1, 0, 1, 310, 522] +[:mouse_button_pressed, 1, 0, 1, 311, 524] +[:mouse_button_up, 1, 0, 1, 312, 526] +[:mouse_move, 738, 100, 2, 313, 528] +[:mouse_move, 732, 101, 2, 314, 528] +[:mouse_move, 715, 101, 2, 315, 529] +[:mouse_move, 690, 101, 2, 316, 529] +[:mouse_move, 677, 101, 2, 317, 530] +[:mouse_move, 666, 101, 2, 318, 530] +[:mouse_move, 662, 101, 2, 319, 531] +[:mouse_move, 661, 101, 2, 320, 531] +[:mouse_button_pressed, 1, 0, 1, 321, 534] +[:mouse_button_up, 1, 0, 1, 322, 536] +[:mouse_move, 660, 100, 2, 323, 550] +[:mouse_move, 661, 100, 2, 324, 550] +[:mouse_move, 662, 100, 2, 325, 553] +[:key_down_raw, 96, 0, 2, 326, 615] +[:key_up_raw, 96, 0, 2, 327, 616] +[:mouse_move, 660, 102, 2, 328, 625] +[:mouse_move, 657, 104, 2, 329, 626] +[:mouse_move, 655, 107, 2, 330, 626] +[:mouse_move, 653, 110, 2, 331, 626] +[:mouse_move, 653, 117, 2, 332, 626] +[:mouse_move, 655, 122, 2, 333, 626] +[:mouse_move, 658, 124, 2, 334, 627] +[:mouse_move, 664, 126, 2, 335, 627] +[:mouse_move, 671, 128, 2, 336, 627] +[:mouse_move, 681, 133, 2, 337, 627] +[:mouse_move, 693, 141, 2, 338, 628] +[:mouse_move, 710, 154, 2, 339, 628] +[:mouse_move, 731, 167, 2, 340, 628] +[:mouse_move, 753, 176, 2, 341, 628] +[:mouse_move, 772, 181, 2, 342, 629] +[:mouse_move, 786, 182, 2, 343, 629] +[:mouse_move, 791, 184, 2, 344, 629] +[:mouse_move, 790, 185, 2, 345, 629] +[:mouse_move, 789, 187, 2, 346, 630] +[:mouse_move, 788, 187, 2, 347, 630] +[:key_down_raw, 13, 0, 2, 348, 637] diff --git a/samples/13_path_finding_algorithms/08_a_star/app/main.rb b/samples/13_path_finding_algorithms/08_a_star/app/main.rb index e9fcb8c..eaf7e09 100644 --- a/samples/13_path_finding_algorithms/08_a_star/app/main.rb +++ b/samples/13_path_finding_algorithms/08_a_star/app/main.rb @@ -11,8 +11,8 @@ class A_Star_Algorithm def tick defaults - render - input + render + input if dijkstra.came_from.empty? calc_searches @@ -65,7 +65,7 @@ class A_Star_Algorithm # We store this value, because we want to remember the value even when # the user's cursor is no longer over what they're interacting with, but # they are still clicking down on the mouse. - state.user_input ||= :none + state.user_input ||= :none # These variables allow the breadth first search to take place # Came_from is a hash with a key of a cell and a value of the cell that was expanded from to find the key. @@ -143,7 +143,7 @@ class A_Star_Algorithm # If the mouse was clicked this tick if inputs.mouse.down # Determine what the user is editing and appropriately edit the state.user_input variable - determine_input + determine_input end # Process user input based on user_input variable and current mouse position @@ -154,51 +154,51 @@ class A_Star_Algorithm # This method is called when the mouse is clicked down def determine_input # If the mouse is over the star in the first grid - if dijkstra_mouse_over_star? + if dijkstra_mouse_over_star? # The user is editing the star from the first grid - state.user_input = :dijkstra_star + state.user_input = :dijkstra_star # If the mouse is over the star in the second grid - elsif greedy_mouse_over_star? + elsif greedy_mouse_over_star? # The user is editing the star from the second grid - state.user_input = :greedy_star + state.user_input = :greedy_star # If the mouse is over the star in the third grid - elsif a_star_mouse_over_star? + elsif a_star_mouse_over_star? # The user is editing the star from the third grid - state.user_input = :a_star_star + state.user_input = :a_star_star # If the mouse is over the target in the first grid - elsif dijkstra_mouse_over_target? + elsif dijkstra_mouse_over_target? # The user is editing the target from the first grid - state.user_input = :dijkstra_target + state.user_input = :dijkstra_target # If the mouse is over the target in the second grid - elsif greedy_mouse_over_target? + elsif greedy_mouse_over_target? # The user is editing the target from the second grid - state.user_input = :greedy_target + state.user_input = :greedy_target # If the mouse is over the target in the third grid - elsif a_star_mouse_over_target? + elsif a_star_mouse_over_target? # The user is editing the target from the third grid - state.user_input = :a_star_target + state.user_input = :a_star_target # If the mouse is over a wall in the first grid - elsif dijkstra_mouse_over_wall? + elsif dijkstra_mouse_over_wall? # The user is removing a wall from the first grid - state.user_input = :dijkstra_remove_wall + state.user_input = :dijkstra_remove_wall # If the mouse is over a wall in the second grid - elsif greedy_mouse_over_wall? + elsif greedy_mouse_over_wall? # The user is removing a wall from the second grid state.user_input = :greedy_remove_wall # If the mouse is over a wall in the third grid - elsif a_star_mouse_over_wall? + elsif a_star_mouse_over_wall? # The user is removing a wall from the third grid state.user_input = :a_star_remove_wall # If the mouse is over the first grid - elsif dijkstra_mouse_over_grid? + elsif dijkstra_mouse_over_grid? # The user is adding a wall from the first grid state.user_input = :dijkstra_add_wall # If the mouse is over the second grid - elsif greedy_mouse_over_grid? + elsif greedy_mouse_over_grid? # The user is adding a wall from the second grid state.user_input = :greedy_add_wall # If the mouse is over the third grid - elsif a_star_mouse_over_grid? + elsif a_star_mouse_over_grid? # The user is adding a wall from the third grid state.user_input = :a_star_add_wall end @@ -206,30 +206,30 @@ class A_Star_Algorithm # Processes click and drag based on what the user is currently dragging def process_input - if state.user_input == :dijkstra_star - process_input_dijkstra_star + if state.user_input == :dijkstra_star + process_input_dijkstra_star elsif state.user_input == :greedy_star - process_input_greedy_star + process_input_greedy_star elsif state.user_input == :a_star_star - process_input_a_star_star - elsif state.user_input == :dijkstra_target - process_input_dijkstra_target - elsif state.user_input == :greedy_target - process_input_greedy_target - elsif state.user_input == :a_star_target - process_input_a_star_target - elsif state.user_input == :dijkstra_remove_wall - process_input_dijkstra_remove_wall + process_input_a_star_star + elsif state.user_input == :dijkstra_target + process_input_dijkstra_target + elsif state.user_input == :greedy_target + process_input_greedy_target + elsif state.user_input == :a_star_target + process_input_a_star_target + elsif state.user_input == :dijkstra_remove_wall + process_input_dijkstra_remove_wall elsif state.user_input == :greedy_remove_wall - process_input_greedy_remove_wall + process_input_greedy_remove_wall elsif state.user_input == :a_star_remove_wall - process_input_a_star_remove_wall - elsif state.user_input == :dijkstra_add_wall - process_input_dijkstra_add_wall - elsif state.user_input == :greedy_add_wall - process_input_greedy_add_wall - elsif state.user_input == :a_star_add_wall - process_input_a_star_add_wall + process_input_a_star_remove_wall + elsif state.user_input == :dijkstra_add_wall + process_input_dijkstra_add_wall + elsif state.user_input == :greedy_add_wall + process_input_greedy_add_wall + elsif state.user_input == :a_star_add_wall + process_input_a_star_add_wall end end @@ -244,7 +244,7 @@ class A_Star_Algorithm # The horizontal grid lines for y in 0..grid.height - outputs.lines << dijkstra_horizontal_line(y) + outputs.lines << dijkstra_horizontal_line(y) end end @@ -259,7 +259,7 @@ class A_Star_Algorithm # The horizontal grid lines for y in 0..grid.height - outputs.lines << greedy_horizontal_line(y) + outputs.lines << greedy_horizontal_line(y) end end @@ -274,10 +274,10 @@ class A_Star_Algorithm # The horizontal grid lines for y in 0..grid.height - outputs.lines << a_star_horizontal_line(y) + outputs.lines << a_star_horizontal_line(y) end end - + # Returns a vertical line for a column of the first grid def dijkstra_vertical_line column dijkstra_scale_up([column, 0, column, grid.height]) @@ -327,7 +327,7 @@ class A_Star_Algorithm def render_dijkstra_target outputs.sprites << [dijkstra_scale_up(grid.target), 'target.png'] end - + # Renders the target on the second grid def render_greedy_target outputs.sprites << [greedy_scale_up(grid.target), 'target.png'] @@ -340,21 +340,21 @@ class A_Star_Algorithm # Renders the walls on the first grid def render_dijkstra_walls - grid.walls.each_key do | wall | + grid.walls.each_key do | wall | outputs.solids << [dijkstra_scale_up(wall), wall_color] end end # Renders the walls on the second grid def render_greedy_walls - grid.walls.each_key do | wall | + grid.walls.each_key do | wall | outputs.solids << [greedy_scale_up(wall), wall_color] end end # Renders the walls on the third grid def render_a_star_walls - grid.walls.each_key do | wall | + grid.walls.each_key do | wall | outputs.solids << [a_star_scale_up(wall), wall_color] end end @@ -554,12 +554,12 @@ class A_Star_Algorithm # Only resets the search if the star changes position # Called whenever the user is editing the star (puts mouse down on star) def process_input_dijkstra_star - old_star = grid.star.clone + old_star = grid.star.clone unless dijkstra_cell_closest_to_mouse == grid.target - grid.star = dijkstra_cell_closest_to_mouse + grid.star = dijkstra_cell_closest_to_mouse end - unless old_star == grid.star - reset_searches + unless old_star == grid.star + reset_searches end end @@ -567,12 +567,12 @@ class A_Star_Algorithm # Only resets the search if the star changes position # Called whenever the user is editing the star (puts mouse down on star) def process_input_greedy_star - old_star = grid.star.clone + old_star = grid.star.clone unless greedy_cell_closest_to_mouse == grid.target grid.star = greedy_cell_closest_to_mouse end - unless old_star == grid.star - reset_searches + unless old_star == grid.star + reset_searches end end @@ -580,12 +580,12 @@ class A_Star_Algorithm # Only resets the search if the star changes position # Called whenever the user is editing the star (puts mouse down on star) def process_input_a_star_star - old_star = grid.star.clone + old_star = grid.star.clone unless a_star_cell_closest_to_mouse == grid.target grid.star = a_star_cell_closest_to_mouse end - unless old_star == grid.star - reset_searches + unless old_star == grid.star + reset_searches end end @@ -593,12 +593,12 @@ class A_Star_Algorithm # Only reset_searchess the search if the target changes position # Called whenever the user is editing the target (puts mouse down on target) def process_input_dijkstra_target - old_target = grid.target.clone + old_target = grid.target.clone unless dijkstra_cell_closest_to_mouse == grid.star grid.target = dijkstra_cell_closest_to_mouse end - unless old_target == grid.target - reset_searches + unless old_target == grid.target + reset_searches end end @@ -606,12 +606,12 @@ class A_Star_Algorithm # Only reset_searchess the search if the target changes position # Called whenever the user is editing the target (puts mouse down on target) def process_input_greedy_target - old_target = grid.target.clone + old_target = grid.target.clone unless greedy_cell_closest_to_mouse == grid.star grid.target = greedy_cell_closest_to_mouse end - unless old_target == grid.target - reset_searches + unless old_target == grid.target + reset_searches end end @@ -619,12 +619,12 @@ class A_Star_Algorithm # Only reset_searchess the search if the target changes position # Called whenever the user is editing the target (puts mouse down on target) def process_input_a_star_target - old_target = grid.target.clone + old_target = grid.target.clone unless a_star_cell_closest_to_mouse == grid.star grid.target = a_star_cell_closest_to_mouse end - unless old_target == grid.target - reset_searches + unless old_target == grid.target + reset_searches end end @@ -633,10 +633,10 @@ class A_Star_Algorithm # The mouse needs to be inside the grid, because we only want to remove walls # the cursor is directly over # Recalculations should only occur when a wall is actually deleted - if dijkstra_mouse_over_grid? + if dijkstra_mouse_over_grid? if grid.walls.has_key?(dijkstra_cell_closest_to_mouse) - grid.walls.delete(dijkstra_cell_closest_to_mouse) - reset_searches + grid.walls.delete(dijkstra_cell_closest_to_mouse) + reset_searches end end end @@ -646,10 +646,10 @@ class A_Star_Algorithm # The mouse needs to be inside the grid, because we only want to remove walls # the cursor is directly over # Recalculations should only occur when a wall is actually deleted - if greedy_mouse_over_grid? + if greedy_mouse_over_grid? if grid.walls.has_key?(greedy_cell_closest_to_mouse) - grid.walls.delete(greedy_cell_closest_to_mouse) - reset_searches + grid.walls.delete(greedy_cell_closest_to_mouse) + reset_searches end end end @@ -659,40 +659,40 @@ class A_Star_Algorithm # The mouse needs to be inside the grid, because we only want to remove walls # the cursor is directly over # Recalculations should only occur when a wall is actually deleted - if a_star_mouse_over_grid? + if a_star_mouse_over_grid? if grid.walls.has_key?(a_star_cell_closest_to_mouse) - grid.walls.delete(a_star_cell_closest_to_mouse) - reset_searches + grid.walls.delete(a_star_cell_closest_to_mouse) + reset_searches end end end # Adds a wall in the first grid in the cell the mouse is over def process_input_dijkstra_add_wall - if dijkstra_mouse_over_grid? + if dijkstra_mouse_over_grid? unless grid.walls.has_key?(dijkstra_cell_closest_to_mouse) - grid.walls[dijkstra_cell_closest_to_mouse] = true - reset_searches + grid.walls[dijkstra_cell_closest_to_mouse] = true + reset_searches end end end # Adds a wall in the second grid in the cell the mouse is over def process_input_greedy_add_wall - if greedy_mouse_over_grid? + if greedy_mouse_over_grid? unless grid.walls.has_key?(greedy_cell_closest_to_mouse) - grid.walls[greedy_cell_closest_to_mouse] = true - reset_searches + grid.walls[greedy_cell_closest_to_mouse] = true + reset_searches end end end # Adds a wall in the third grid in the cell the mouse is over def process_input_a_star_add_wall - if a_star_mouse_over_grid? + if a_star_mouse_over_grid? unless grid.walls.has_key?(a_star_cell_closest_to_mouse) - grid.walls[a_star_cell_closest_to_mouse] = true - reset_searches + grid.walls[a_star_cell_closest_to_mouse] = true + reset_searches end end end @@ -702,13 +702,13 @@ class A_Star_Algorithm # Finding the cell closest to the mouse helps with this def dijkstra_cell_closest_to_mouse # Closest cell to the mouse in the first grid - x = (inputs.mouse.point.x / grid.cell_size).to_i - y = (inputs.mouse.point.y / grid.cell_size).to_i + x = (inputs.mouse.point.x / grid.cell_size).to_i + y = (inputs.mouse.point.y / grid.cell_size).to_i # Bound x and y to the grid - x = grid.width - 1 if x > grid.width - 1 - y = grid.height - 1 if y > grid.height - 1 + x = grid.width - 1 if x > grid.width - 1 + y = grid.height - 1 if y > grid.height - 1 # Return closest cell - [x, y] + [x, y] end # When the user grabs the star and puts their cursor to the far right @@ -716,17 +716,17 @@ class A_Star_Algorithm # Finding the cell closest to the mouse in the second grid helps with this def greedy_cell_closest_to_mouse # Closest cell grid to the mouse in the second - x = (inputs.mouse.point.x / grid.cell_size).to_i - y = (inputs.mouse.point.y / grid.cell_size).to_i + x = (inputs.mouse.point.x / grid.cell_size).to_i + y = (inputs.mouse.point.y / grid.cell_size).to_i # Translate the cell to the first grid x -= grid.width + 1 # Bound x and y to the first grid x = 0 if x < 0 y = 0 if y < 0 - x = grid.width - 1 if x > grid.width - 1 - y = grid.height - 1 if y > grid.height - 1 + x = grid.width - 1 if x > grid.width - 1 + y = grid.height - 1 if y > grid.height - 1 # Return closest cell - [x, y] + [x, y] end # When the user grabs the star and puts their cursor to the far right @@ -734,17 +734,17 @@ class A_Star_Algorithm # Finding the cell closest to the mouse in the third grid helps with this def a_star_cell_closest_to_mouse # Closest cell grid to the mouse in the second - x = (inputs.mouse.point.x / grid.cell_size).to_i - y = (inputs.mouse.point.y / grid.cell_size).to_i + x = (inputs.mouse.point.x / grid.cell_size).to_i + y = (inputs.mouse.point.y / grid.cell_size).to_i # Translate the cell to the first grid x -= (grid.width + 1) * 2 # Bound x and y to the first grid x = 0 if x < 0 y = 0 if y < 0 - x = grid.width - 1 if x > grid.width - 1 - y = grid.height - 1 if y > grid.height - 1 + x = grid.width - 1 if x > grid.width - 1 + y = grid.height - 1 if y > grid.height - 1 # Return closest cell - [x, y] + [x, y] end def reset_searches @@ -772,21 +772,21 @@ class A_Star_Algorithm def calc_dijkstra # Sets up the search to begin from the star - dijkstra.frontier << grid.star - dijkstra.came_from[grid.star] = nil - dijkstra.cost_so_far[grid.star] = 0 + dijkstra.frontier << grid.star + dijkstra.came_from[grid.star] = nil + dijkstra.cost_so_far[grid.star] = 0 # Until the target is found or there are no more cells to explore from until dijkstra.came_from.has_key?(grid.target) or dijkstra.frontier.empty? # Take the next frontier cell. The first element is the cell, the second is the priority. new_frontier = dijkstra.frontier.shift#[0] # For each of its neighbors - adjacent_neighbors(new_frontier).each do | neighbor | + adjacent_neighbors(new_frontier).each do | neighbor | # That have not been visited and are not walls - unless dijkstra.came_from.has_key?(neighbor) or grid.walls.has_key?(neighbor) + unless dijkstra.came_from.has_key?(neighbor) or grid.walls.has_key?(neighbor) # Add them to the frontier and mark them as visited dijkstra.frontier << neighbor - dijkstra.came_from[neighbor] = new_frontier + dijkstra.came_from[neighbor] = new_frontier dijkstra.cost_so_far[neighbor] = dijkstra.cost_so_far[new_frontier] + 1 end end @@ -807,20 +807,20 @@ class A_Star_Algorithm def calc_greedy # Sets up the search to begin from the star - greedy.frontier << grid.star - greedy.came_from[grid.star] = nil + greedy.frontier << grid.star + greedy.came_from[grid.star] = nil # Until the target is found or there are no more cells to explore from until greedy.came_from.has_key?(grid.target) or greedy.frontier.empty? # Take the next frontier cell - new_frontier = greedy.frontier.shift + new_frontier = greedy.frontier.shift # For each of its neighbors - adjacent_neighbors(new_frontier).each do | neighbor | + adjacent_neighbors(new_frontier).each do | neighbor | # That have not been visited and are not walls - unless greedy.came_from.has_key?(neighbor) or grid.walls.has_key?(neighbor) + unless greedy.came_from.has_key?(neighbor) or grid.walls.has_key?(neighbor) # Add them to the frontier and mark them as visited - greedy.frontier << neighbor - greedy.came_from[neighbor] = new_frontier + greedy.frontier << neighbor + greedy.came_from[neighbor] = new_frontier end end # Sort the frontier so that cells that are in a zigzag pattern are prioritized over those in an line @@ -850,12 +850,12 @@ class A_Star_Algorithm current_frontier = a_star.frontier.shift # For each of that cells neighbors - adjacent_neighbors(current_frontier).each do | neighbor | + adjacent_neighbors(current_frontier).each do | neighbor | # That have not been visited and are not walls - unless a_star.came_from.has_key?(neighbor) or grid.walls.has_key?(neighbor) + unless a_star.came_from.has_key?(neighbor) or grid.walls.has_key?(neighbor) # Add them to the frontier and mark them as visited - a_star.frontier << neighbor - a_star.came_from[neighbor] = current_frontier + a_star.frontier << neighbor + a_star.came_from[neighbor] = current_frontier a_star.cost_so_far[neighbor] = a_star.cost_so_far[current_frontier] + 1 end end @@ -937,16 +937,16 @@ class A_Star_Algorithm # Returns a list of adjacent cells # Used to determine what the next cells to be added to the frontier are def adjacent_neighbors(cell) - neighbors = [] + neighbors = [] # Gets all the valid neighbors into the array # From southern neighbor, clockwise - neighbors << [cell.x , cell.y - 1] unless cell.y == 0 - neighbors << [cell.x - 1, cell.y ] unless cell.x == 0 - neighbors << [cell.x , cell.y + 1] unless cell.y == grid.height - 1 - neighbors << [cell.x + 1, cell.y ] unless cell.x == grid.width - 1 + neighbors << [cell.x , cell.y - 1] unless cell.y == 0 + neighbors << [cell.x - 1, cell.y ] unless cell.x == 0 + neighbors << [cell.x , cell.y + 1] unless cell.y == grid.height - 1 + neighbors << [cell.x + 1, cell.y ] unless cell.x == grid.width - 1 - neighbors + neighbors end # Finds the vertical and horizontal distance of a cell from the star @@ -991,11 +991,11 @@ class A_Star_Algorithm def wall_color [134, 134, 120] # Camo Green end - + def visited_color [204, 191, 179] # Dark Brown end - + def path_color [231, 230, 228] # Pastel White end @@ -1018,7 +1018,7 @@ def tick args end # Every tick, new args are passed, and the Breadth First Search tick is called - $a_star_algorithm ||= A_Star_Algorithm.new(args) + $a_star_algorithm ||= A_Star_Algorithm.new $a_star_algorithm.args = args $a_star_algorithm.tick end diff --git a/samples/13_path_finding_algorithms/08_a_star/replay.txt b/samples/13_path_finding_algorithms/08_a_star/replay.txt new file mode 100644 index 0000000..001a564 --- /dev/null +++ b/samples/13_path_finding_algorithms/08_a_star/replay.txt @@ -0,0 +1,434 @@ +replay_version 2.0 +stopped_at 341 +seed 100 +recorded_at 2021-11-20 11:24:45 -0600 +[:mouse_button_up, 1, 0, 1, 1, 1] +[:mouse_move, 769, 97, 2, 2, 8] +[:mouse_move, 763, 101, 2, 3, 8] +[:mouse_move, 755, 109, 2, 4, 8] +[:mouse_move, 748, 123, 2, 5, 8] +[:mouse_move, 746, 148, 2, 6, 9] +[:mouse_move, 742, 180, 2, 7, 9] +[:mouse_move, 733, 215, 2, 8, 9] +[:mouse_move, 719, 278, 2, 9, 9] +[:mouse_move, 712, 336, 2, 10, 9] +[:mouse_move, 701, 397, 2, 11, 10] +[:mouse_move, 685, 440, 2, 12, 10] +[:mouse_move, 667, 472, 2, 13, 10] +[:mouse_move, 654, 493, 2, 14, 10] +[:mouse_move, 644, 506, 2, 15, 11] +[:mouse_move, 637, 514, 2, 16, 11] +[:mouse_move, 635, 516, 2, 17, 11] +[:mouse_move, 634, 517, 2, 18, 11] +[:mouse_move, 630, 518, 2, 19, 12] +[:mouse_move, 624, 524, 2, 20, 12] +[:mouse_move, 619, 537, 2, 21, 12] +[:mouse_move, 612, 553, 2, 22, 13] +[:mouse_move, 609, 561, 2, 23, 13] +[:mouse_move, 608, 565, 2, 24, 13] +[:mouse_move, 613, 565, 2, 25, 14] +[:mouse_move, 627, 565, 2, 26, 14] +[:mouse_move, 641, 565, 2, 27, 14] +[:mouse_move, 654, 565, 2, 28, 14] +[:mouse_move, 658, 565, 2, 29, 15] +[:mouse_move, 659, 565, 2, 30, 15] +[:mouse_move, 662, 565, 2, 31, 15] +[:mouse_move, 667, 566, 2, 32, 15] +[:mouse_move, 671, 566, 2, 33, 16] +[:mouse_move, 676, 566, 2, 34, 16] +[:mouse_move, 685, 566, 2, 35, 16] +[:mouse_move, 701, 565, 2, 36, 16] +[:mouse_move, 719, 562, 2, 37, 17] +[:mouse_move, 731, 560, 2, 38, 17] +[:mouse_move, 744, 559, 2, 39, 17] +[:mouse_move, 750, 559, 2, 40, 17] +[:mouse_move, 757, 559, 2, 41, 17] +[:mouse_move, 763, 559, 2, 42, 17] +[:mouse_move, 767, 559, 2, 43, 18] +[:mouse_move, 769, 559, 2, 44, 18] +[:mouse_move, 770, 558, 2, 45, 18] +[:mouse_move, 774, 557, 2, 46, 18] +[:mouse_move, 784, 555, 2, 47, 18] +[:mouse_move, 796, 551, 2, 48, 19] +[:mouse_move, 804, 550, 2, 49, 19] +[:mouse_move, 810, 548, 2, 50, 19] +[:mouse_move, 814, 547, 2, 51, 20] +[:mouse_move, 817, 547, 2, 52, 20] +[:mouse_move, 818, 547, 2, 53, 20] +[:mouse_move, 819, 547, 2, 54, 20] +[:mouse_move, 819, 546, 2, 55, 20] +[:mouse_move, 819, 545, 2, 56, 20] +[:mouse_move, 820, 545, 2, 57, 21] +[:mouse_move, 820, 544, 2, 58, 21] +[:mouse_move, 820, 543, 2, 59, 21] +[:mouse_move, 820, 542, 2, 60, 22] +[:mouse_move, 820, 541, 2, 61, 22] +[:mouse_move, 820, 540, 2, 62, 23] +[:mouse_move, 819, 540, 2, 63, 23] +[:mouse_button_pressed, 1, 0, 1, 64, 24] +[:mouse_button_up, 1, 0, 1, 65, 25] +[:mouse_move, 820, 540, 2, 66, 29] +[:mouse_move, 820, 541, 2, 67, 29] +[:mouse_move, 820, 542, 2, 68, 29] +[:mouse_move, 820, 543, 2, 69, 30] +[:mouse_move, 819, 543, 2, 70, 31] +[:mouse_move, 818, 543, 2, 71, 31] +[:mouse_move, 817, 542, 2, 72, 31] +[:mouse_move, 816, 542, 2, 73, 32] +[:mouse_move, 812, 542, 2, 74, 32] +[:mouse_move, 808, 542, 2, 75, 32] +[:mouse_move, 802, 542, 2, 76, 33] +[:mouse_move, 796, 542, 2, 77, 33] +[:mouse_move, 790, 542, 2, 78, 33] +[:mouse_move, 784, 540, 2, 79, 33] +[:mouse_move, 783, 540, 2, 80, 34] +[:mouse_move, 782, 538, 2, 81, 34] +[:mouse_move, 782, 533, 2, 82, 34] +[:mouse_move, 785, 525, 2, 83, 34] +[:mouse_move, 788, 512, 2, 84, 34] +[:mouse_move, 791, 494, 2, 85, 35] +[:mouse_move, 791, 469, 2, 86, 35] +[:mouse_move, 785, 442, 2, 87, 35] +[:mouse_move, 776, 417, 2, 88, 35] +[:mouse_move, 767, 398, 2, 89, 36] +[:mouse_move, 759, 381, 2, 90, 36] +[:mouse_move, 747, 365, 2, 91, 36] +[:mouse_move, 737, 356, 2, 92, 36] +[:mouse_move, 718, 345, 2, 93, 36] +[:mouse_move, 702, 337, 2, 94, 37] +[:mouse_move, 693, 333, 2, 95, 37] +[:mouse_move, 689, 331, 2, 96, 37] +[:mouse_move, 688, 331, 2, 97, 38] +[:mouse_move, 687, 331, 2, 98, 38] +[:mouse_move, 686, 342, 2, 99, 38] +[:mouse_move, 684, 352, 2, 100, 39] +[:mouse_move, 682, 359, 2, 101, 39] +[:mouse_move, 682, 362, 2, 102, 39] +[:mouse_move, 682, 364, 2, 103, 40] +[:mouse_move, 683, 364, 2, 104, 40] +[:mouse_move, 686, 364, 2, 105, 40] +[:mouse_move, 688, 363, 2, 106, 40] +[:mouse_move, 692, 362, 2, 107, 40] +[:mouse_move, 698, 362, 2, 108, 41] +[:mouse_move, 702, 362, 2, 109, 41] +[:mouse_move, 705, 362, 2, 110, 41] +[:mouse_move, 706, 362, 2, 111, 42] +[:mouse_move, 706, 361, 2, 112, 42] +[:mouse_move, 707, 361, 2, 113, 42] +[:mouse_move, 708, 360, 2, 114, 42] +[:mouse_move, 709, 359, 2, 115, 43] +[:mouse_move, 709, 358, 2, 116, 43] +[:mouse_move, 710, 358, 2, 117, 43] +[:mouse_button_pressed, 1, 0, 1, 118, 44] +[:mouse_button_up, 1, 0, 1, 119, 45] +[:mouse_move, 710, 357, 2, 120, 56] +[:mouse_move, 713, 357, 2, 121, 56] +[:mouse_move, 715, 357, 2, 122, 57] +[:mouse_move, 716, 357, 2, 123, 57] +[:mouse_move, 717, 357, 2, 124, 57] +[:mouse_move, 719, 357, 2, 125, 58] +[:mouse_move, 720, 357, 2, 126, 58] +[:mouse_move, 720, 356, 2, 127, 59] +[:mouse_move, 721, 356, 2, 128, 59] +[:mouse_move, 723, 356, 2, 129, 59] +[:mouse_move, 724, 356, 2, 130, 59] +[:mouse_move, 727, 356, 2, 131, 59] +[:mouse_move, 728, 356, 2, 132, 59] +[:mouse_move, 730, 356, 2, 133, 60] +[:mouse_move, 731, 355, 2, 134, 60] +[:mouse_move, 732, 355, 2, 135, 60] +[:mouse_move, 734, 355, 2, 136, 60] +[:mouse_move, 735, 355, 2, 137, 60] +[:mouse_button_pressed, 1, 0, 1, 138, 62] +[:mouse_move, 737, 358, 2, 139, 63] +[:mouse_move, 739, 364, 2, 140, 63] +[:mouse_move, 739, 372, 2, 141, 63] +[:mouse_move, 739, 381, 2, 142, 64] +[:mouse_move, 740, 390, 2, 143, 64] +[:mouse_move, 742, 403, 2, 144, 64] +[:mouse_move, 744, 415, 2, 145, 64] +[:mouse_move, 744, 426, 2, 146, 64] +[:mouse_move, 745, 438, 2, 147, 64] +[:mouse_move, 746, 445, 2, 148, 64] +[:mouse_move, 747, 449, 2, 149, 64] +[:mouse_move, 747, 450, 2, 150, 64] +[:mouse_move, 747, 451, 2, 151, 64] +[:mouse_move, 748, 452, 2, 152, 64] +[:mouse_move, 749, 452, 2, 153, 64] +[:mouse_move, 750, 452, 2, 154, 64] +[:mouse_move, 751, 452, 2, 155, 64] +[:mouse_move, 753, 454, 2, 156, 64] +[:mouse_move, 754, 455, 2, 157, 64] +[:mouse_move, 756, 456, 2, 158, 64] +[:mouse_move, 759, 459, 2, 159, 64] +[:mouse_move, 765, 465, 2, 160, 64] +[:mouse_move, 769, 469, 2, 161, 64] +[:mouse_move, 773, 474, 2, 162, 64] +[:mouse_move, 776, 479, 2, 163, 64] +[:mouse_move, 781, 486, 2, 164, 64] +[:mouse_move, 782, 490, 2, 165, 65] +[:mouse_move, 783, 494, 2, 166, 65] +[:mouse_move, 783, 498, 2, 167, 65] +[:mouse_move, 784, 506, 2, 168, 65] +[:mouse_move, 786, 515, 2, 169, 65] +[:mouse_move, 789, 526, 2, 170, 65] +[:mouse_move, 791, 534, 2, 171, 65] +[:mouse_move, 795, 549, 2, 172, 65] +[:mouse_move, 798, 556, 2, 173, 65] +[:mouse_move, 799, 561, 2, 174, 65] +[:mouse_move, 799, 564, 2, 175, 65] +[:mouse_move, 801, 570, 2, 176, 65] +[:mouse_move, 802, 577, 2, 177, 65] +[:mouse_move, 804, 583, 2, 178, 65] +[:mouse_move, 804, 587, 2, 179, 65] +[:mouse_move, 805, 590, 2, 180, 65] +[:mouse_move, 807, 594, 2, 181, 65] +[:mouse_move, 809, 598, 2, 182, 65] +[:mouse_move, 811, 601, 2, 183, 65] +[:mouse_move, 812, 602, 2, 184, 65] +[:mouse_move, 812, 603, 2, 185, 65] +[:mouse_move, 813, 604, 2, 186, 65] +[:mouse_move, 814, 604, 2, 187, 65] +[:mouse_move, 817, 599, 2, 188, 65] +[:mouse_move, 819, 595, 2, 189, 65] +[:mouse_move, 820, 594, 2, 190, 65] +[:mouse_move, 819, 594, 2, 191, 77] +[:mouse_button_up, 1, 0, 1, 192, 77] +[:mouse_move, 818, 594, 2, 193, 77] +[:mouse_move, 817, 594, 2, 194, 78] +[:mouse_move, 816, 594, 2, 195, 79] +[:mouse_move, 815, 593, 2, 196, 109] +[:mouse_move, 812, 592, 2, 197, 109] +[:mouse_move, 808, 592, 2, 198, 109] +[:mouse_move, 799, 591, 2, 199, 109] +[:mouse_move, 780, 588, 2, 200, 110] +[:mouse_move, 758, 584, 2, 201, 110] +[:mouse_move, 738, 584, 2, 202, 110] +[:mouse_move, 724, 584, 2, 203, 110] +[:mouse_move, 710, 584, 2, 204, 110] +[:mouse_move, 691, 583, 2, 205, 111] +[:mouse_move, 668, 579, 2, 206, 111] +[:mouse_move, 647, 577, 2, 207, 111] +[:mouse_move, 630, 577, 2, 208, 111] +[:mouse_move, 610, 577, 2, 209, 112] +[:mouse_move, 602, 577, 2, 210, 112] +[:mouse_move, 597, 576, 2, 211, 112] +[:mouse_move, 595, 575, 2, 212, 112] +[:mouse_move, 603, 575, 2, 213, 114] +[:mouse_move, 626, 575, 2, 214, 114] +[:mouse_move, 651, 575, 2, 215, 114] +[:mouse_move, 680, 579, 2, 216, 114] +[:mouse_move, 723, 583, 2, 217, 114] +[:mouse_move, 745, 585, 2, 218, 114] +[:mouse_move, 756, 585, 2, 219, 115] +[:mouse_move, 758, 585, 2, 220, 115] +[:mouse_move, 759, 585, 2, 221, 115] +[:mouse_move, 760, 584, 2, 222, 115] +[:mouse_move, 761, 584, 2, 223, 116] +[:mouse_move, 764, 584, 2, 224, 116] +[:mouse_move, 767, 584, 2, 225, 116] +[:mouse_move, 769, 584, 2, 226, 116] +[:mouse_move, 773, 584, 2, 227, 117] +[:mouse_move, 791, 588, 2, 228, 117] +[:mouse_move, 803, 596, 2, 229, 117] +[:mouse_move, 807, 599, 2, 230, 118] +[:mouse_move, 808, 599, 2, 231, 118] +[:mouse_move, 809, 599, 2, 232, 119] +[:mouse_move, 812, 599, 2, 233, 120] +[:mouse_move, 813, 599, 2, 234, 120] +[:mouse_move, 814, 599, 2, 235, 120] +[:mouse_move, 815, 599, 2, 236, 122] +[:mouse_move, 816, 598, 2, 237, 122] +[:mouse_move, 817, 598, 2, 238, 123] +[:mouse_button_pressed, 1, 0, 1, 239, 123] +[:mouse_move, 805, 598, 2, 240, 124] +[:mouse_move, 777, 598, 2, 241, 124] +[:mouse_move, 748, 598, 2, 242, 124] +[:mouse_move, 722, 598, 2, 243, 124] +[:mouse_move, 692, 598, 2, 244, 124] +[:mouse_move, 668, 598, 2, 245, 124] +[:mouse_move, 648, 598, 2, 246, 125] +[:mouse_move, 624, 598, 2, 247, 125] +[:mouse_move, 615, 598, 2, 248, 125] +[:mouse_move, 610, 598, 2, 249, 125] +[:mouse_move, 609, 598, 2, 250, 125] +[:mouse_move, 607, 598, 2, 251, 125] +[:mouse_move, 606, 598, 2, 252, 125] +[:mouse_move, 604, 595, 2, 253, 127] +[:mouse_move, 598, 590, 2, 254, 128] +[:mouse_move, 592, 584, 2, 255, 128] +[:mouse_move, 588, 581, 2, 256, 129] +[:mouse_move, 588, 580, 2, 257, 129] +[:mouse_move, 587, 580, 2, 258, 129] +[:mouse_move, 586, 579, 2, 259, 130] +[:mouse_move, 585, 579, 2, 260, 130] +[:mouse_move, 584, 578, 2, 261, 131] +[:mouse_move, 584, 577, 2, 262, 131] +[:mouse_move, 584, 576, 2, 263, 132] +[:mouse_move, 583, 576, 2, 264, 133] +[:mouse_move, 584, 576, 2, 265, 135] +[:mouse_button_up, 1, 0, 1, 266, 147] +[:mouse_move, 585, 575, 2, 267, 153] +[:mouse_move, 585, 571, 2, 268, 196] +[:mouse_move, 585, 568, 2, 269, 197] +[:mouse_move, 586, 563, 2, 270, 197] +[:mouse_move, 587, 558, 2, 271, 197] +[:mouse_move, 587, 557, 2, 272, 198] +[:mouse_move, 587, 555, 2, 273, 199] +[:mouse_move, 588, 555, 2, 274, 200] +[:mouse_move, 588, 554, 2, 275, 200] +[:mouse_move, 588, 550, 2, 276, 235] +[:mouse_move, 594, 541, 2, 277, 236] +[:mouse_move, 605, 525, 2, 278, 236] +[:mouse_move, 622, 502, 2, 279, 236] +[:mouse_move, 654, 458, 2, 280, 237] +[:mouse_move, 672, 425, 2, 281, 237] +[:mouse_move, 682, 391, 2, 282, 238] +[:mouse_move, 688, 358, 2, 283, 239] +[:mouse_move, 692, 333, 2, 284, 239] +[:mouse_move, 694, 319, 2, 285, 239] +[:mouse_move, 697, 308, 2, 286, 240] +[:mouse_move, 698, 303, 2, 287, 240] +[:mouse_move, 700, 299, 2, 288, 241] +[:mouse_move, 702, 295, 2, 289, 241] +[:mouse_move, 703, 291, 2, 290, 242] +[:mouse_move, 704, 289, 2, 291, 242] +[:mouse_move, 705, 288, 2, 292, 243] +[:mouse_move, 706, 288, 2, 293, 245] +[:mouse_move, 706, 291, 2, 294, 246] +[:mouse_move, 706, 294, 2, 295, 246] +[:mouse_move, 706, 298, 2, 296, 247] +[:mouse_move, 706, 303, 2, 297, 247] +[:mouse_move, 707, 308, 2, 298, 247] +[:mouse_move, 709, 315, 2, 299, 248] +[:mouse_move, 710, 321, 2, 300, 248] +[:mouse_move, 711, 324, 2, 301, 249] +[:mouse_move, 711, 325, 2, 302, 249] +[:mouse_move, 712, 325, 2, 303, 250] +[:mouse_move, 713, 325, 2, 304, 252] +[:mouse_move, 713, 324, 2, 305, 252] +[:mouse_move, 714, 324, 2, 306, 253] +[:mouse_button_pressed, 1, 0, 1, 307, 254] +[:mouse_button_up, 1, 0, 1, 308, 255] +[:mouse_move, 714, 325, 2, 309, 263] +[:mouse_move, 714, 331, 2, 310, 263] +[:mouse_move, 714, 344, 2, 311, 264] +[:mouse_move, 714, 365, 2, 312, 264] +[:mouse_move, 710, 394, 2, 313, 264] +[:mouse_move, 696, 432, 2, 314, 265] +[:mouse_move, 678, 472, 2, 315, 265] +[:mouse_move, 654, 506, 2, 316, 266] +[:mouse_move, 637, 532, 2, 317, 267] +[:mouse_move, 624, 549, 2, 318, 267] +[:mouse_move, 615, 559, 2, 319, 267] +[:mouse_move, 612, 562, 2, 320, 268] +[:mouse_move, 609, 563, 2, 321, 268] +[:mouse_move, 608, 564, 2, 322, 269] +[:mouse_move, 606, 566, 2, 323, 269] +[:mouse_move, 606, 568, 2, 324, 270] +[:mouse_move, 606, 572, 2, 325, 270] +[:mouse_move, 606, 573, 2, 326, 271] +[:mouse_move, 606, 574, 2, 327, 271] +[:mouse_move, 605, 573, 2, 328, 273] +[:mouse_move, 606, 571, 2, 329, 273] +[:mouse_move, 606, 566, 2, 330, 274] +[:mouse_move, 606, 565, 2, 331, 274] +[:mouse_move, 605, 565, 2, 332, 275] +[:mouse_move, 601, 565, 2, 333, 275] +[:mouse_move, 593, 565, 2, 334, 276] +[:mouse_move, 583, 565, 2, 335, 276] +[:mouse_move, 573, 567, 2, 336, 277] +[:mouse_move, 570, 567, 2, 337, 278] +[:mouse_move, 569, 567, 2, 338, 278] +[:mouse_move, 570, 568, 2, 339, 284] +[:mouse_move, 572, 568, 2, 340, 284] +[:mouse_move, 573, 568, 2, 341, 286] +[:mouse_button_pressed, 1, 0, 1, 342, 290] +[:mouse_move, 574, 568, 2, 343, 290] +[:mouse_move, 576, 568, 2, 344, 291] +[:mouse_move, 586, 564, 2, 345, 292] +[:mouse_move, 601, 560, 2, 346, 292] +[:mouse_move, 622, 552, 2, 347, 292] +[:mouse_move, 648, 544, 2, 348, 293] +[:mouse_move, 675, 537, 2, 349, 293] +[:mouse_move, 702, 533, 2, 350, 293] +[:mouse_move, 726, 530, 2, 351, 293] +[:mouse_move, 747, 526, 2, 352, 293] +[:mouse_move, 771, 518, 2, 353, 293] +[:mouse_move, 786, 514, 2, 354, 293] +[:mouse_move, 802, 511, 2, 355, 294] +[:mouse_move, 815, 508, 2, 356, 294] +[:mouse_move, 827, 505, 2, 357, 294] +[:mouse_move, 833, 504, 2, 358, 294] +[:mouse_move, 835, 503, 2, 359, 294] +[:mouse_move, 832, 503, 2, 360, 294] +[:mouse_move, 830, 504, 2, 361, 294] +[:mouse_move, 826, 506, 2, 362, 294] +[:mouse_move, 822, 508, 2, 363, 294] +[:mouse_move, 818, 511, 2, 364, 294] +[:mouse_move, 816, 511, 2, 365, 294] +[:mouse_move, 813, 513, 2, 366, 294] +[:mouse_move, 813, 514, 2, 367, 294] +[:mouse_move, 812, 515, 2, 368, 294] +[:mouse_move, 812, 516, 2, 369, 294] +[:mouse_move, 812, 517, 2, 370, 294] +[:mouse_move, 813, 518, 2, 371, 295] +[:mouse_move, 814, 518, 2, 372, 295] +[:mouse_move, 815, 518, 2, 373, 295] +[:mouse_move, 816, 518, 2, 374, 295] +[:mouse_move, 817, 518, 2, 375, 295] +[:mouse_button_up, 1, 0, 1, 376, 302] +[:mouse_move, 817, 517, 2, 377, 313] +[:key_down_raw, 96, 0, 2, 378, 320] +[:key_up_raw, 96, 0, 2, 379, 321] +[:mouse_move, 817, 518, 2, 380, 323] +[:mouse_move, 819, 515, 2, 381, 324] +[:mouse_move, 819, 510, 2, 382, 324] +[:mouse_move, 811, 498, 2, 383, 324] +[:mouse_move, 797, 486, 2, 384, 324] +[:mouse_move, 786, 482, 2, 385, 324] +[:mouse_move, 780, 479, 2, 386, 324] +[:mouse_move, 779, 478, 2, 387, 324] +[:mouse_move, 778, 479, 2, 388, 327] +[:mouse_move, 779, 484, 2, 389, 327] +[:mouse_move, 780, 487, 2, 390, 327] +[:mouse_move, 781, 488, 2, 391, 327] +[:mouse_move, 782, 488, 2, 392, 327] +[:mouse_move, 782, 487, 2, 393, 328] +[:mouse_move, 789, 485, 2, 394, 328] +[:mouse_move, 800, 481, 2, 395, 328] +[:mouse_move, 816, 472, 2, 396, 328] +[:mouse_move, 839, 456, 2, 397, 328] +[:mouse_move, 870, 434, 2, 398, 329] +[:mouse_move, 904, 409, 2, 399, 329] +[:mouse_move, 944, 380, 2, 400, 329] +[:mouse_move, 996, 331, 2, 401, 329] +[:mouse_move, 1011, 312, 2, 402, 329] +[:mouse_move, 1042, 278, 2, 403, 329] +[:mouse_move, 1081, 231, 2, 404, 329] +[:mouse_move, 1101, 213, 2, 405, 330] +[:mouse_move, 1114, 202, 2, 406, 330] +[:mouse_move, 1118, 196, 2, 407, 330] +[:mouse_move, 1118, 195, 2, 408, 330] +[:mouse_move, 1117, 194, 2, 409, 331] +[:mouse_move, 1115, 194, 2, 410, 331] +[:mouse_move, 1110, 193, 2, 411, 331] +[:mouse_move, 1102, 189, 2, 412, 331] +[:mouse_move, 1084, 184, 2, 413, 331] +[:mouse_move, 1052, 175, 2, 414, 332] +[:mouse_move, 1005, 162, 2, 415, 332] +[:mouse_move, 938, 144, 2, 416, 332] +[:mouse_move, 892, 138, 2, 417, 332] +[:mouse_move, 860, 134, 2, 418, 332] +[:mouse_move, 833, 128, 2, 419, 333] +[:mouse_move, 809, 120, 2, 420, 333] +[:mouse_move, 782, 108, 2, 421, 333] +[:mouse_move, 772, 104, 2, 422, 333] +[:mouse_move, 770, 103, 2, 423, 333] +[:mouse_move, 769, 103, 2, 424, 333] +[:mouse_move, 766, 101, 2, 425, 334] +[:mouse_move, 764, 100, 2, 426, 334] +[:mouse_move, 763, 100, 2, 427, 334] +[:mouse_move, 761, 99, 2, 428, 334] +[:mouse_move, 760, 98, 2, 429, 334] +[:key_down_raw, 13, 0, 2, 430, 341] |
