mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-11 16:33:43 +00:00
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:
@@ -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
|
||||
Reference in New Issue
Block a user