update bot

This commit is contained in:
2026-01-06 08:55:14 +08:00
parent cbbe95e108
commit 059f152374
12 changed files with 353 additions and 148 deletions
+92
View File
@@ -86,6 +86,98 @@ func find_best_slot_for_tile(tile_type: int) -> int:
# Fallback: any empty slot
return actor.playerboard.find(-1)
func get_unneeded_tile_slot() -> int:
"""Find a slot containing a tile that is not needed for the goal."""
if not actor or actor.playerboard.size() == 0:
return -1
var needed_tiles = get_tiles_needed()
# Check center 3x3 for misplaced tiles
for i in range(3):
for j in range(3):
var goal_idx = i * 3 + j
var board_idx = (i + 1) * 5 + (j + 1)
if board_idx >= actor.playerboard.size():
continue
var current_item = actor.playerboard[board_idx]
if current_item == -1:
continue
# If this position has a specific goal
if goal_idx < actor.goals.size() and actor.goals[goal_idx] != -1:
# If current item doesn't match the goal for this position
if current_item != actor.goals[goal_idx]:
# AND we don't need this tile type elsewhere (or we have enough)
# Simplified: if it's not in needed_tiles, dump it.
# Note: needed_tiles calculation includes checking if we already have it in correct spot.
# But if we have it in WRONG spot, it might still remain in needed list?
# current get_tiles_needed logic: if board_idx != goal_value, add to needed.
# So if we have it here (wrong spot), it is still "needed" for the right spot.
# So we should only dump it if we have duplicates or if we truly don't need it.
# For now, simplistic approach: If it's not in the goal set AT ALL, dump it.
if not current_item in actor.goals:
return board_idx
# If it IS in goals but wrong spot, only dump if we can't arrange it?
# Or if we have too many of them?
# Let's count how many we have vs how many we need
var count_have = actor.playerboard.count(current_item)
var count_need = actor.goals.count(current_item)
if count_have > count_need:
return board_idx
# If this position is supposed to be empty (-1) but has item
elif goal_idx < actor.goals.size() and actor.goals[goal_idx] == -1:
return board_idx
# Check outer ring (non-goal area) - always dump unless saving for arrangement
# 5x5 board. Center 3x3 is indices: 6,7,8, 11,12,13, 16,17,18
var center_indices = [6, 7, 8, 11, 12, 13, 16, 17, 18]
for i in range(actor.playerboard.size()):
if not i in center_indices and actor.playerboard[i] != -1:
var item = actor.playerboard[i]
# Only keep if we strictly need it and can't find it easily?
# Actually, generally dump outer ring tiles to keep board clean
# unless we are about to move it to a valid spot.
# But BotController tries to arrange.
# If we have an outer tile that is needed, Arrange should handle it.
# If Arrange failed (lower priority checks), then Put should dump it.
return i
return -1
return -1
func get_unneeded_tile_slot_panic() -> int:
"""Aggressively find ANY tile that doesn't match a goal perfectly."""
if not actor or actor.playerboard.size() == 0:
return -1
# In panic mode, dump anything not matching goals
for i in range(3):
for j in range(3):
var goal_idx = i * 3 + j
var board_idx = (i + 1) * 5 + (j + 1)
if board_idx >= actor.playerboard.size(): continue
var item = actor.playerboard[board_idx]
if item == -1: continue
if goal_idx < actor.goals.size():
if actor.goals[goal_idx] != -1:
if item != actor.goals[goal_idx]: return board_idx
else:
return board_idx
# Dump outer ring
var center = [6, 7, 8, 11, 12, 13, 16, 17, 18]
for i in range(actor.playerboard.size()):
if not i in center and actor.playerboard[i] != -1: return i
return -1
# =============================================================================
# Tile Finding
# =============================================================================