Skip to content
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

Try to summon imp types that are lacking #338

Merged
merged 1 commit into from Sep 13, 2018

Conversation

Projects
None yet
1 participant
@ozkriff
Copy link
Owner

ozkriff commented Sep 8, 2018

Before this PR the code for choosing who to summon looked like this:

let prototypes = ["imp", "imp_toxic", "imp_bomber"];
let prototype = thread_rng().choose(&prototypes).unwrap();

Since it was completely random and because bombers lived much longer then melee imps, it lead to a situations when there're like 12 or even 15 bombers on the map.


This PR chanes the summoning algorithm to prefer types that are under-presented on the map.

First, we use

fn count_agents_by_typename(state: &State, player_id: PlayerId) -> HashMap<String, u32>

to count player's agents on the map:

{"imp_toxic": 3, "imp_summoner": 2, "imp": 1}

Then we filter-out un-summonable typenames:

{"imp_toxic": 3, "imp": 1}

Add unrepresented summonable agent types with 0 count:

{"imp_toxic": 3, "imp": 1, "imp_bomber": 0}

Find the agent type with max count (3 in the example) and reverse the map to:

{"imp_toxic": 0, "imp": 2, "imp_bomber": 3}

Flatten it to a Vec<String>:

["imp", "imp", "imp_bomber", "imp_bomber", "imp_bomber"]

And finally we call choose() on this vector (prototypes_pool):

thread_rng()
    .choose(&prototypes_pool)
    .expect("Can't choose a prototype")

Ta-daa, we have out weighed typename to summon. :)
(Most likely it'll be "imp_bomber" in the example)


Seems to work fine now: even with increased summon rate imp types are balanced in count

Closes #301

@ozkriff ozkriff force-pushed the i301_max_bombers_count branch from 939979e to 9fc774b Sep 13, 2018

@ozkriff ozkriff merged commit 6e18d9c into master Sep 13, 2018

4 checks passed

continuous-integration/appveyor/branch AppVeyor build succeeded
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@ozkriff ozkriff deleted the i301_max_bombers_count branch Sep 13, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.