This commit is contained in:
2025-01-31 17:45:35 +08:00
parent cf389135c0
commit ef8d06b6cc
7 changed files with 253 additions and 26 deletions
+43
View File
@@ -1,6 +1,49 @@
extends ConditionLeaf
func is_goals_achieved(actor) -> bool:
# Convert goals to 2D for easier pattern matching
var goals_2d = []
for i in range(3):
var row = []
for j in range(3):
row.append(actor.goals[i * 3 + j])
goals_2d.append(row)
# Convert playerboard to 2D
var board_2d = []
for i in range(5):
var row = []
for j in range(5):
row.append(actor.playerboard[i * 5 + j])
board_2d.append(row)
# Check every possible 3x3 region in the 5x5 board
for start_row in range(3):
for start_col in range(3):
var matches = true
for i in range(3):
for j in range(3):
var board_item = board_2d[start_row + i][start_col + j]
var goal_item = goals_2d[i][j]
if goal_item != -1 and goal_item != board_item:
matches = false
break
elif goal_item == -1 and board_item != -1:
matches = false
break
if not matches:
break
if matches:
return true
return false
func tick(actor: Node, blackboard: Blackboard) -> int:
# First check if goals are achieved
if is_goals_achieved(actor):
blackboard.set_value("current_action", "idle")
return FAILURE
if actor.playerboard_is_full():
return FAILURE
+9
View File
@@ -1,6 +1,15 @@
extends ConditionLeaf
func is_goals_achieved(actor) -> bool:
# ... same is_goals_achieved function as in can_grab.gd ...
return false
func tick(actor: Node, blackboard: Blackboard) -> int:
# First check if goals are achieved
if is_goals_achieved(actor):
blackboard.set_value("current_action", "idle")
return FAILURE
# Find an item in playerboard that matches goals
var put_slot = -1
for i in range(actor.playerboard.size()):