Skip to content

homy-game-studio/hgs-unity-rl-agents

Repository files navigation

WIP - HGS Reinforced Learning Agents

Startup

  1. Create an class for your agent extending Agent, and implement the follow methods:
protected override void ExecuteAction(int action)
{
    switch (action)
    {
        case 0: _dir = Vector2.left; break;
        case 1: _dir = Vector2.up; break;
        case 2: _dir = Vector2.right; break;
        case 3: _dir = Vector2.down; break;
        case 4: _dir = Vector2.left + Vector2.up; break;
        case 5: _dir = Vector2.right + Vector2.up; break;
        case 6: _dir = Vector2.left + Vector2.down; break;
        case 7: _dir = Vector2.right + Vector2.down; break;
    }
}

protected override float GetReward()
{
    var reward = 1f - _endDistance / 3f;
    if (_endDistance <= 1.5f) return reward * 2f;
    if (_endDistance > _initialDistance) return -1f;
    return reward;
}

protected override float[] GetState()
{
    var direction = (transform.position - target.position).normalized;
    return new float[] { direction.x, direction.y };
}
  1. Create a Brain ScriptableObject and attach in you agent
image
  1. Ajdust params and train

Progress

  1. Traning - First epochs
2024-04-24.09-12-58.mp4
  1. Training - Last epochs
2024-04-24.09-06-57.mp4
  1. Final Result
2024-04-24.09-04-54.mp4

About

Deep Q Learning based agents abstraction for your game

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages