mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-11 08:23:45 +00:00
feat(training): add opt-in teamplay evaluation
This commit is contained in:
@@ -38,6 +38,10 @@ extends AIController3D
|
||||
# stone, matching ball_touch_cooldown_ticks's existing "stepping-stone, not
|
||||
# the objective" framing.
|
||||
@export_range(0.0, 1.0) var ball_touch_direction_floor := 0.3
|
||||
# Fraction of a touch payout shared with teammates. Zero preserves all
|
||||
# existing 1v1/curriculum reward functions; in teamplay the shared amount is
|
||||
# divided across teammates and never exceeds the touching ship's payout.
|
||||
@export_range(0.0, 1.0) var team_touch_credit_weight := 0.0
|
||||
@export var velocity_to_ball_weight := 0.02
|
||||
# Dense reward for approaching the ball *nose first* near the floor. Unlike
|
||||
# velocity_to_ball_weight, sideways/reverse closing velocity earns nothing:
|
||||
@@ -606,6 +610,12 @@ func _on_ship_body_entered(body: Node) -> void:
|
||||
if air_touch_bonus_weight > 0.0 and ball.global_position.y > AIR_TOUCH_HEIGHT:
|
||||
touch_payout += air_touch_bonus_weight * alignment
|
||||
reward += touch_payout
|
||||
if team_touch_credit_weight > 0.0 and not teammates.is_empty():
|
||||
var teammate_credit := team_touch_credit(touch_payout, team_touch_credit_weight, teammates.size())
|
||||
for teammate in teammates:
|
||||
var teammate_agent := teammate.get_node_or_null("ShipAIController") as ShipAIController
|
||||
if is_instance_valid(teammate_agent):
|
||||
teammate_agent.reward += teammate_credit
|
||||
_ticks_since_ball_touch = 0
|
||||
|
||||
# air_touch_fraction/productive_air_touch_fraction (see get_info) share
|
||||
@@ -616,4 +626,10 @@ func _on_ship_body_entered(body: Node) -> void:
|
||||
if ball.global_position.y > AIR_TOUCH_HEIGHT:
|
||||
_air_touches += 1
|
||||
if alignment >= PRODUCTIVE_AIR_TOUCH_ALIGNMENT:
|
||||
_productive_air_touches += 1
|
||||
_productive_air_touches += 1
|
||||
|
||||
|
||||
static func team_touch_credit(touch_payout: float, weight: float, teammate_count: int) -> float:
|
||||
if touch_payout <= 0.0 or weight <= 0.0 or teammate_count <= 0:
|
||||
return 0.0
|
||||
return touch_payout * clampf(weight, 0.0, 1.0) / teammate_count
|
||||
|
||||
Reference in New Issue
Block a user