TinkerStorm / shuffle-theory

Research into different shuffling theories and how they may effect a service as it scales across shards and clusters.
https://discord.gg/z5DPVHNBuw
GNU General Public License v3.0
0 stars 0 forks source link
mafia werewolf werewolf-game

shuffle-theory

Research into different shuffling theories and how they may effect a service as it scales across shards and clusters.

Method Comparison

The only comparison to make is how the roles are distributed, which have suttle differences in their state management.

Note: The following is a comparison between the calling of console.time and console.timeEnd and the time taken to execute the function.

The chance of a role being assigned to a player is determined by chance.shuffle. When a role's chance is calculated, it can be anywhere between 70% and 130% - for now they are scaled up as integers, but I am unsure on the effect it may have on the chance outcomes.

Run Instructions

Using yarn

gh clone TinkerStorm/shuffle-theory
yarn
yarn build

# these steps will not build the project
yarn mode:stock
yarn mode:auction

# or you can run all stages
yarn all

Development Notes

This sandbox assumes that all players with active scrolls are unique scrolls per role. Multiple scrolls per role can be supported, but it strays dangerously close to imbalance of chance ratios between players.

They are equally fast, but the reducing-stock is a bit more bias towards players at the top of the list, favoring their scrolls before other players have a chance.

This is not fair benchmarking... I know.

Method Iteratee Stock Time (5 runs)
reducing-stock Player Roles 8.474 ms
auction-bid Role Players 8.158 ms

chance.weighted(values, weights) returns a value, which may prove troublesome if multiple instances of the same reference exist... using first match as array.indexOf(value) is good enough to workaround this but not as a permenant solution to scale in production.

GitHub CoPilot

On reducing-stock copilot had provided me with a 'functional' approach to remove all matching references from the array... only problem with that is I can't stop it early without an external variable check (which may also be out-of-sync). Lodash's remove function does the exact same by asking for a predicate to remove elements if the predicate returns true (again requiring an external reference).

License

This project is licensed under GNU General Public License v3.0, see the LICENSE file for more information. The package.json has also been marked as private, meaning it should not be published on the registry at this time.

Credit

This takes inspiration from weighted-rng by Mackan using the weight mapping to determine what element should be returned - this may end up using it once names and scrolls aren't required to be completely randomized.

In a future iteration, this may end up using a name dictionary from jslife by ArchboxDev (@bubmet and @mount2010) to provide an alternative source of names during initial development stages. Eventually, this will have it's own names dictionary to select from (at least that's the idea).

Future Plans

There are a few things I would like to consider adding to this project: