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

Add initial stat support for action counts #11

Closed
wants to merge 22 commits into from

Conversation

NickCondron
Copy link
Contributor

@NickCondron NickCondron commented Jul 19, 2022

This is a draft because I'd like your input on how best to setup an interface for computing game stats like slippi-js does. Initial stats we will compute will be action counts because I implemented it in slippi-js, and I know how it works.

Currently my main issue is that the Frame<N> type is clumsy. Seems like we either bite the bullet and implement a conversion to some sort of Vec or we implement a macro that makes working with Frame<N> more reasonable. However, I've never used const generics before; maybe there's a better way. EDIT: I figured out this part

I want the interface to be idiomatic and not just copy what slippi-js does. I need help with the design. Implementing the calculations is more straightforward.

@NickCondron NickCondron marked this pull request as ready for review August 16, 2022 04:17
@NickCondron NickCondron changed the title Draft: Add initial stat support for action counts Add initial stat support for action counts Aug 16, 2022
@NickCondron
Copy link
Contributor Author

The action counts have reached or surpassed feature-parity with slippi-js action counts. Only exception is that slippi-js has logic to differentiate tech rolls based on player position. I skipped that part because it's only valid for 2-player games. 2-player specific stats can probably go somewhere else.

I enforce a v0.2.0 version medium because accurate action counts are impossible without state_age. Currently the code panics if an earlier replay is provided. I don't know the best way to handle that case given the version is not encoded in the type system. v2.0.0 adds l-cancel info, but that is left as optional.

Some tests were 'borrowed' from slippi-js, but I don't feel bad because I wrote a few of them. Could probably use more tests for wavedash/dashdance

Chose to make each action count u16 instead of u8. I think there might be some cases where an action could exceed 255 occurrences, especially in non-competitive formats.

@NickCondron NickCondron marked this pull request as draft August 21, 2022 11:38
peppi/tests/stats.rs Show resolved Hide resolved
peppi/src/stats/actions.rs Outdated Show resolved Hide resolved
peppi/src/stats/actions.rs Show resolved Hide resolved
}

fn is_ftilt(state: Common) -> bool {
state.0 >= Common::ATTACK_S_3_HI.0 && state.0 <= Common::ATTACK_S_3_LW.0
Copy link
Owner

Choose a reason for hiding this comment

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

I see why you wanted Ord on action states now. But I wonder what impact this has on the generated code for the surrounding match statement; it wouldn't suprise me if the compiler can't see through this to generate the same jump table it would if you wrote Common::ATTACK_S_3_HI | Common::ATTACK_S_3_HI_S | ... inline.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea maybe not. However, I'm not going to worry about efficiency right now. Based on my tests, parsing is much slower than any reasonable stat computation we would do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What's your outlook for backwards compatibility of this module? It would be unfortunate if we had to bump peppi's major version number frequently just for stats. If that's a concern, we could potentially put stats in a separate crate.

Not all changes are breaking. For example:

  • Adding new action type to ActionComputer (if ActionStat is non_exhaustive) -- non-breaking
  • Adding new StatComputer -- non-breaking
  • fix stat to be more accurate -- non_breaking

I see your concern though. Stats doesn't need any crate-internal access, so it could easily be it's own crate. I don't know how that fits with your goals for peppi to be shared among different languages.

peppi/src/stats/interface.rs Outdated Show resolved Hide resolved
Copy link
Owner

@hohav hohav left a comment

Choose a reason for hiding this comment

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

What's your outlook for backwards compatibility of this module? It would be unfortunate if we had to bump peppi's major version number frequently just for stats. If that's a concern, we could potentially put stats in a separate crate.

Comment on lines +20 to +27
const MIN_VERSION: Version = Version(0, 1, 0);
fn check_version(ver: Version) -> StatResult<()> {
if ver < Self::MIN_VERSION {
Err(StatError::OldVersion(ver, Self::MIN_VERSION))
} else {
Ok(())
}
}
Copy link
Owner

Choose a reason for hiding this comment

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

Are there any pre-0.1 replays out there? Even if there are, IMO it's not worth spending any code on them at all.

Copy link
Contributor Author

@NickCondron NickCondron Sep 6, 2022

Choose a reason for hiding this comment

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

0.1 is the first replay version. This line exists so that you don't have to define MIN_VERSION if you want your stats to be available for all replays.

@@ -52,6 +52,8 @@ pub mod model {
}
}

pub mod stats;
Copy link
Owner

Choose a reason for hiding this comment

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

Could you put examples of how to use this mod in the README? Both partial and one-shot methods, if I'm understanding the design correctly.

@hohav hohav mentioned this pull request Sep 6, 2022
@NickCondron
Copy link
Contributor Author

Closing because I plan on rewriting this once I figure out a better interface for it. I'm happy with the nuts and bolts of the implementation, but currently the types are clunky. I like your suggestion of making stats be its own crate.

@NickCondron NickCondron closed this Dec 4, 2022
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.

2 participants