feat(*): Add self-play RL training pipeline with PPO trainer, in-game GDScript policy inference, and bot opponent support in Match mode

This commit is contained in:
Josh Creek
2026-07-18 19:32:51 +01:00
parent 328831df1f
commit 85f96eb15e
81 changed files with 3934 additions and 10 deletions
@@ -0,0 +1,30 @@
extends RewardFunction2D
class_name ApproachNodeReward2D
## Calculates the reward for approaching node
## a reward is only added when the agent reaches a new
## best distance to the target object.
## Best distance reward will be calculated for this object
@export var target_node: Node2D
## Scales the reward, 1.0 means the reward is equal to
## how much closer the agent is than the previous best.
@export_range(0.0, 1.0, 0.0001, "or_greater") var reward_scale: float = 1.0
var _best_distance
func get_reward() -> float:
var reward := 0.0
var current_distance := global_position.distance_to(target_node.global_position)
if not _best_distance:
_best_distance = current_distance
if current_distance < _best_distance:
reward = (_best_distance - current_distance) * reward_scale
_best_distance = current_distance
return reward
func reset():
_best_distance = null