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() var token_node = token.instantiate()
add_child(token_node) add_child(token_node)
token_node.position = Vector2(offset*column, offset*row) 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)) token_node.set_debug_label(str(row) + "," + str(column))
grid[row].append(token_node) 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(): func populate_grid():
pass pass
@@ -54,14 +58,20 @@ func calculate_token_groups():
visited_nodes.append(current_coord) visited_nodes.append(current_coord)
var adjacent_token_coords = [ var adjacent_token_coords = [
[row - 1, col], [current_coord[0] - 1, current_coord[1]],
[row, col + 1], [current_coord[0], current_coord[1] + 1],
[row + 1, col], [current_coord[0] + 1, current_coord[1]],
[row, col - 1] [current_coord[0], current_coord[1] - 1]
] ]
var valid_coords = adjacent_token_coords.filter( 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: for coord in valid_coords:

View File

@@ -14,3 +14,16 @@ config/name="combo-car"
run/main_scene="uid://bai2mcthexgm5" run/main_scene="uid://bai2mcthexgm5"
config/features=PackedStringArray("4.4", "GL Compatibility") config/features=PackedStringArray("4.4", "GL Compatibility")
config/icon="res://icon.svg" config/icon="res://icon.svg"
[input]
activate={
"deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":32,"location":0,"echo":false,"script":null)
]
}
[rendering]
renderer/rendering_method="gl_compatibility"
renderer/rendering_method.mobile="gl_compatibility"

View File

@@ -10,8 +10,10 @@ var debug_label: Label
func _ready(): func _ready():
color_polygon = $Color color_polygon = $Color
debug_label = $"Debug Label" debug_label = $"Debug Label"
type = randi_range(0, 3) as token_type
match type: func set_type(type: token_type):
self.type = type
match self.type:
token_type.TYPE_1: token_type.TYPE_1:
color_polygon.color = Color.RED color_polygon.color = Color.RED
token_type.TYPE_2: token_type.TYPE_2: