Ukendio / Game

Mozilla Public License 2.0
18 stars 2 forks source link

Smart spawns #12

Closed Ukendio closed 3 years ago

Ukendio commented 3 years ago

In this FFA game, we want players that die to respawn at a location with the least enemy players around.

We have a set of spawn locations which are essentially just positions stored in an intrinsic set. A naive O(mn) approach would be iterate through the set and add all players distance relative to the position and compare with last spawn in the set. Another solution could be using Region3 which is relatively expensive, only check players within a certain radius of the spawn and add amount of players to that value in the set.

Ukendio commented 3 years ago

We have gotten a lot of traction on this problem 😅.

A few comments to take into account from developers:

Boswwalurus:

  1. spawning is rare and max player count tends to be small so nothing wrong with an O(n) solution, and you can do that solution in a local script too
  2. unless you're gonna have thousands of spawn locations and whatnot you're not gonna run into any issues

Evaera:

  1. I would probably do something dumb like for each spawn point pick the one that has the furthest average distance from all enemy players
  2. Implement neural net, after each spawn ask the player if it was a good spawn, train the model and soon you'll have the solution to the perfect spawn
    • 🤔

Osyris: I'd loop through each player, loop through each spawn, find spawn farthest from any enemy. O(n*m) is perfectly fine here, you won't have more than 100 players and you won't have more than 100 spawns.

sircfenner: I don't think "naive" is the right adjective; it's just a simple solution, and probably the best one

Ukendio commented 3 years ago

Decided to go with the general consensus. We will take the O(m*n) approach because the size of neither m or n will never grow to a size that warrants further optimisation.

Note: A divide-and-conquer algorithm could potentially make it into a O(nlogn).