fix: suppress unused_signal warning on event_bus signals
This commit is contained in:
@@ -5,67 +5,67 @@ extends BaseAI
|
||||
const _C = preload("res://src/core/constants.gd")
|
||||
|
||||
func _init():
|
||||
ai_name = "Rule AI"
|
||||
ai_name = "Rule AI"
|
||||
|
||||
func decide(hand: Array, table: Array, current_rank: int, config: RuleConfig) -> HandEvaluator.EvaluatedPlay:
|
||||
var moves := MoveGenerator.generate(hand, current_rank, config)
|
||||
var last_play := _last_non_pass(table)
|
||||
var candidates: Array = []
|
||||
for m in moves:
|
||||
if m.type == -1:
|
||||
continue
|
||||
if last_play == null:
|
||||
candidates.append(m)
|
||||
elif _can_beat(m, last_play, config):
|
||||
candidates.append(m)
|
||||
if candidates.is_empty():
|
||||
return _pass_move()
|
||||
var scored := _score_all(candidates, hand.size(), current_rank)
|
||||
scored.sort_custom(func(a, b): return a["score"] > b["score"])
|
||||
return scored[0]["move"]
|
||||
var moves := MoveGenerator.generate(hand, current_rank, config)
|
||||
var last_play := _last_non_pass(table)
|
||||
var candidates: Array = []
|
||||
for m in moves:
|
||||
if m.type == -1:
|
||||
continue
|
||||
if last_play == null:
|
||||
candidates.append(m)
|
||||
elif _can_beat(m, last_play, config):
|
||||
candidates.append(m)
|
||||
if candidates.is_empty():
|
||||
return _pass_move()
|
||||
var scored := _score_all(candidates, hand.size(), current_rank)
|
||||
scored.sort_custom(func(a, b): return a["score"] > b["score"])
|
||||
return scored[0]["move"]
|
||||
|
||||
func _score_all(moves: Array, hand_size: int, current_rank: int) -> Array:
|
||||
var results := []
|
||||
for m in moves:
|
||||
var score := _score_move(m, hand_size, current_rank)
|
||||
results.append({"move": m, "score": score})
|
||||
return results
|
||||
var results := []
|
||||
for m in moves:
|
||||
var score := _score_move(m, hand_size, current_rank)
|
||||
results.append({"move": m, "score": score})
|
||||
return results
|
||||
|
||||
func _score_move(play: HandEvaluator.EvaluatedPlay, hand_size: int, current_rank: int) -> float:
|
||||
var score := 0.0
|
||||
var remaining := hand_size - play.cards.size()
|
||||
score += (27.0 - remaining) / 27.0 * 0.3
|
||||
if play.type == _C.TYPE_BOMB or play.type == _C.TYPE_ROCKET:
|
||||
score -= 0.2
|
||||
elif play.type == _C.TYPE_STRAIGHT_FLUSH:
|
||||
score -= 0.1
|
||||
score += play.cards.size() * 0.02
|
||||
if play.primary_rank >= 14 and remaining > 10:
|
||||
score -= 0.1
|
||||
if remaining <= 3:
|
||||
score += 0.5
|
||||
if play.is_pure_bomb:
|
||||
score += 0.05
|
||||
return score
|
||||
var score := 0.0
|
||||
var remaining := hand_size - play.cards.size()
|
||||
score += (27.0 - remaining) / 27.0 * 0.3
|
||||
if play.type == _C.TYPE_BOMB or play.type == _C.TYPE_ROCKET:
|
||||
score -= 0.2
|
||||
elif play.type == _C.TYPE_STRAIGHT_FLUSH:
|
||||
score -= 0.1
|
||||
score += play.cards.size() * 0.02
|
||||
if play.primary_rank >= 14 and remaining > 10:
|
||||
score -= 0.1
|
||||
if remaining <= 3:
|
||||
score += 0.5
|
||||
if play.is_pure_bomb:
|
||||
score += 0.05
|
||||
return score
|
||||
|
||||
func _can_beat(play: HandEvaluator.EvaluatedPlay, last: HandEvaluator.EvaluatedPlay, config: RuleConfig) -> bool:
|
||||
if play.type == _C.TYPE_ROCKET:
|
||||
return true
|
||||
if play.type == _C.TYPE_BOMB and last.type != _C.TYPE_ROCKET:
|
||||
return RuleEngine.compare_bombs(play, last, config) > 0
|
||||
if play.type == last.type:
|
||||
return play.primary_rank > last.primary_rank
|
||||
return false
|
||||
if play.type == _C.TYPE_ROCKET:
|
||||
return true
|
||||
if play.type == _C.TYPE_BOMB and last.type != _C.TYPE_ROCKET:
|
||||
return RuleEngine.compare_bombs(play, last, config) > 0
|
||||
if play.type == last.type:
|
||||
return play.primary_rank > last.primary_rank
|
||||
return false
|
||||
|
||||
func _last_non_pass(table: Array) -> HandEvaluator.EvaluatedPlay:
|
||||
for i in range(table.size() - 1, -1, -1):
|
||||
var play: HandEvaluator.EvaluatedPlay = table[i]
|
||||
if play.type != -1:
|
||||
return play
|
||||
return null
|
||||
for i in range(table.size() - 1, -1, -1):
|
||||
var play: HandEvaluator.EvaluatedPlay = table[i]
|
||||
if play.type != -1:
|
||||
return play
|
||||
return null
|
||||
|
||||
func _pass_move() -> HandEvaluator.EvaluatedPlay:
|
||||
var p := HandEvaluator.EvaluatedPlay.new()
|
||||
p.type = -1
|
||||
p.primary_rank = 0
|
||||
return p
|
||||
var p := HandEvaluator.EvaluatedPlay.new()
|
||||
p.type = -1
|
||||
p.primary_rank = 0
|
||||
return p
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# src/autoload/event_bus.gd
|
||||
@warning_ignore("unused_signal")
|
||||
extends Node
|
||||
|
||||
signal player_played_cards(player_idx: int, play_type: int, cards: Array)
|
||||
|
||||
@@ -9,10 +9,10 @@ var controller: TrainingController
|
||||
@onready var status_label: Label = $StatusLabel
|
||||
|
||||
func _ready() -> void:
|
||||
play_button.pressed.connect(_on_play_pressed)
|
||||
pass_button.pressed.connect(_on_pass_pressed)
|
||||
hint_button.pressed.connect(_on_hint_pressed)
|
||||
start_training()
|
||||
play_button.pressed.connect(_on_play_pressed)
|
||||
pass_button.pressed.connect(_on_pass_pressed)
|
||||
hint_button.pressed.connect(_on_hint_pressed)
|
||||
start_training()
|
||||
|
||||
func start_training() -> void:
|
||||
controller = TrainingController.new()
|
||||
@@ -70,5 +70,5 @@ func _on_game_ended(winner_team: int, reason: String) -> void:
|
||||
if hand_area: hand_area.disable_input()
|
||||
|
||||
func _refresh_ui() -> void:
|
||||
if controller and controller.game_state and hand_area:
|
||||
hand_area.update_hand(controller.game_state.get_hand(0))
|
||||
if controller and controller.game_state and hand_area:
|
||||
hand_area.update_hand(controller.game_state.get_hand(0))
|
||||
|
||||
Reference in New Issue
Block a user