breadth-first traversal of grid is working!

an array of token groups is calculated successfully
and it's probably fast enough.
This commit is contained in:
Jack Case
2025-08-21 18:35:10 -04:00
parent 94c9632afd
commit ee0507c805
3 changed files with 33 additions and 8 deletions

22
grid.gd
View File

@@ -21,10 +21,14 @@ func _ready():
var token_node = token.instantiate()
add_child(token_node)
token_node.position = Vector2(offset*column, offset*row)
token_node.set_type(randi_range(0,3 ))
token_node.set_debug_label(str(row) + "," + str(column))
grid[row].append(token_node)
calculate_token_groups()
func _process(_delta: float) -> void:
if Input.is_action_just_pressed("activate"):
calculate_token_groups()
func populate_grid():
pass
@@ -54,14 +58,20 @@ func calculate_token_groups():
visited_nodes.append(current_coord)
var adjacent_token_coords = [
[row - 1, col],
[row, col + 1],
[row + 1, col],
[row, col - 1]
[current_coord[0] - 1, current_coord[1]],
[current_coord[0], current_coord[1] + 1],
[current_coord[0] + 1, current_coord[1]],
[current_coord[0], current_coord[1] - 1]
]
var valid_coords = adjacent_token_coords.filter(
func(coord_pair): return coord_pair[0] >= 0 and coord_pair[0] < rows and coord_pair[1] >= 0 and coord_pair[1] < cols
func(coord_pair):
return (
coord_pair[0] >= 0 and
coord_pair[0] < rows and
coord_pair[1] >= 0 and
coord_pair[1] < cols
)
)
for coord in valid_coords: