feat: fix some bug

This commit is contained in:
2026-04-24 22:56:11 +08:00
parent 8c5004d535
commit b76dd2e737
9 changed files with 105 additions and 156 deletions
+2 -30
View File
@@ -247,21 +247,12 @@ func _run_ai_tick():
var goals_achv = _is_goals_achieved()
if actor.action_points > 1: # Only print if they have multi-AP
print("[BotController] %s AI Tick. AP: %d, GoalsAchieved: %s, Board: %s" % [actor.name, actor.action_points, str(goals_achv), str(board_fullness)])
# Only stop completely if objectives are met AND we are at the finish line (if applicable)
# Only stop completely if objectives are met and at finish (or standard mode)
if goals_achv:
if is_sng and actor.current_position.x >= 21:
return
elif not is_sng:
return # In standard mode, goal achievement = game over usually
# STALL PREVENTION: If we have AP but couldn't do anything, we are stuck.
# Skip turn to prevent game freeze in turn-based mode.
if TurnManager.turn_based_mode and actor.action_points > 0:
print("[BotController] %s is STUCK with AP %d! Skipping turn to proceed flow." % [actor.name, actor.action_points])
actor.consume_action_points(actor.action_points)
return
# =============================================================================
# Power-Up / Sabotage
@@ -501,9 +492,6 @@ func _find_nearest_victim() -> Node3D:
func _try_grab() -> bool:
"""Try to grab a tile from the grid using direct player control."""
# Check AP only if turn-based
if TurnManager.turn_based_mode and actor.action_points <= 0:
return false
if _is_playerboard_full():
return false
@@ -572,8 +560,6 @@ func _find_tile_to_grab(tiles_needed: Array) -> Dictionary:
func _try_move() -> bool:
"""Try to move toward needed tiles taking single steps like a player."""
if TurnManager.turn_based_mode and actor.action_points <= 0:
return false
if _is_goals_achieved() and LobbyManager.game_mode != "Stop n Go":
return false
@@ -700,9 +686,6 @@ func _try_unstuck_move() -> bool:
func _try_put(high_priority: bool = false) -> bool:
"""Try to put a tile from playerboard onto grid."""
if actor.action_points <= 0:
return false
var put_slot = -1
# Check for Panic Mode
@@ -718,21 +701,17 @@ func _try_put(high_priority: bool = false) -> bool:
is_panic = true
if is_panic:
# Aggressive dumping
put_slot = strategic_planner.get_unneeded_tile_slot_panic()
else:
# Normal smart dumping
put_slot = strategic_planner.get_unneeded_tile_slot()
if put_slot == -1:
return false
# Find empty adjacent cell
var put_position = _find_empty_adjacent_cell()
if not put_position:
return false
# Execute put
_is_processing_action = true
_current_action = "putting"
@@ -742,7 +721,6 @@ func _try_put(high_priority: bool = false) -> bool:
actor.playerboard[put_slot] = -1
actor.rpc("sync_grid_item", cell.x, cell.y, cell.z, item)
actor.rpc("sync_playerboard", actor.playerboard)
actor.action_points -= 1
print("[BotController] %s put unneeded tile %d at %s (Panic: %s)" % [actor.name, item, put_position, is_panic])
await _wait_with_variance(action_delay)
@@ -773,18 +751,13 @@ func _find_empty_adjacent_cell() -> Vector2i:
func _try_arrange() -> bool:
"""Try to rearrange tiles in playerboard."""
if actor.action_points < 2:
return false
if _is_goals_achieved():
return false
# Find misplaced item and better position
var arrangement = _find_best_arrangement()
if arrangement.is_empty():
return false
# Execute arrangement
_is_processing_action = true
_current_action = "arranging"
@@ -793,7 +766,6 @@ func _try_arrange() -> bool:
actor.playerboard[arrangement.target_slot] = item
actor.playerboard[arrangement.source_slot] = -1
actor.rpc("sync_playerboard", actor.playerboard)
actor.action_points -= 2
print("[BotController] %s arranged slot %d -> %d" % [actor.name, arrangement.source_slot, arrangement.target_slot])
await _wait_with_variance(action_delay)