Skip to content

1122 test path smoothing with splines #1139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

mFragaBA
Copy link
Contributor

@mFragaBA mFragaBA commented Mar 28, 2025

Motivation

We want to make the bot movement a bit less robot-like. For now we won't mind it not being perfect. We compared against brawl stars and tried to use their bot movement as a baseline

Closes #1122

Summary of changes

Added 2 core functions for bots:

  • 1 that calls a rust nif that implements path simplification. This means that it removes points in the path that are not actually needed. In order to do that, we have to do "raycasts" by checking collisions between lines and the game obstacles. This is definitely not efficient enough (as we need to check collisions between each path's edge and all obstacles in the map) and can be improved but is good enough for a first iteration
    • based on ian millington's book on AI programming for games
  • another one that takes a path and returns a "smoothed" version using splines. This one was written using pure elixir, we might aim to implement this in the future using rust to improve it's runtime perf. This feature is gated under an env var flag TEST_PATHFINDING_SPLINES. Based on load tests there is a noticeable performance impact of doing this, so for now we'll keep it off by default. Once we retake bots research we can use it to compare against other techniques or try to improve it.

How to test it?

Play a game locally. Check that bots take more reasonable paths. You can test the splines by running export TEST_PATHFINDING_SPLINES=true and restarting the app. Bots will take more "rounded" paths, the movement is still not 100% smooth, but it is done so in small increments.

Checklist

  • Tested the changes locally.
  • Reviewed the changes on GitHub, line by line.
  • This change requires new documentation.
    • Documentation has been added/updated.

@mFragaBA mFragaBA temporarily deployed to testing-argentina March 28, 2025 18:26 — with GitHub Actions Inactive
@mFragaBA mFragaBA mentioned this pull request Apr 1, 2025
4 tasks
@mFragaBA mFragaBA changed the base branch from main to 1123-use-pathfinding-in-actual-bot-behavior April 1, 2025 13:26
@mFragaBA mFragaBA force-pushed the 1122-test-path-smoothing-with-splines branch from 7b100a1 to 77e36ba Compare April 1, 2025 13:27
@mFragaBA mFragaBA force-pushed the 1123-use-pathfinding-in-actual-bot-behavior branch from 412a89c to cd66994 Compare April 1, 2025 13:28
@mFragaBA mFragaBA force-pushed the 1122-test-path-smoothing-with-splines branch 4 times, most recently from bc5d13e to 871b2d3 Compare April 1, 2025 20:59
@mFragaBA mFragaBA force-pushed the 1123-use-pathfinding-in-actual-bot-behavior branch from ae46d35 to a7850ce Compare April 3, 2025 20:42
@mFragaBA mFragaBA force-pushed the 1122-test-path-smoothing-with-splines branch 3 times, most recently from 4e7b897 to d1fcc58 Compare April 7, 2025 19:38
Base automatically changed from 1123-use-pathfinding-in-actual-bot-behavior to main April 15, 2025 15:00
@mFragaBA mFragaBA force-pushed the 1122-test-path-smoothing-with-splines branch from d1fcc58 to e72177a Compare April 21, 2025 20:01
@mFragaBA mFragaBA temporarily deployed to testing-europe May 9, 2025 21:07 — with GitHub Actions Inactive
@mFragaBA
Copy link
Contributor Author

mFragaBA commented May 9, 2025

Ran loadtest without using splines. Here's the snapshot. While metrics didn't vary that much, the game felt a bit more stuttery compared with main with 400 games, but run smoothly with 300

@mFragaBA mFragaBA temporarily deployed to testing-europe May 12, 2025 15:41 — with GitHub Actions Inactive
@mFragaBA mFragaBA temporarily deployed to testing-europe May 12, 2025 17:41 — with GitHub Actions Inactive
@mFragaBA mFragaBA marked this pull request as ready for review May 12, 2025 18:19
@mFragaBA
Copy link
Contributor Author

Just ran another loadtest but with the splines feature on. The games felt more stuttery. We'll merge this PR but keeping the flag off by default with a note on splines. In the future if we double down on them we can look for improvements such as:

  • implementing the algorithm with rust
  • play around with spline parameters
  • try other path smoothing techniques

@mFragaBA mFragaBA marked this pull request as draft May 12, 2025 18:24
@mFragaBA mFragaBA force-pushed the 1122-test-path-smoothing-with-splines branch from 5368d95 to 3d8be76 Compare May 12, 2025 18:32
@mFragaBA mFragaBA temporarily deployed to testing-europe May 12, 2025 18:43 — with GitHub Actions Inactive
|> maybe_set_obstacles(game_state)
end

defp maybe_set_obstacles(%{bot_state_machine: %{obstacles: nil}} = state, %{obstacles: obstacles})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to store the obstacles in order to perform collision checks when simplifying the path

Comment on lines +9 to +11
@segment_point_amount 5
@tension 0.2
@alpha 0.5
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can also play with these values. I used the values suggested in the article, and played around with the segment_point_amount. After 5 I didn't see a difference

@mFragaBA mFragaBA marked this pull request as ready for review May 12, 2025 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BOTS] - Pathfinding: test path smoothing
1 participant