b-inary / postflop-solver

[Development suspended] An efficient open-source postflop solver library written in Rust
GNU Affero General Public License v3.0
246 stars 97 forks source link

Refactors for `bet_size.rs` #51

Closed bkushigian closed 1 month ago

bkushigian commented 1 month ago

Refactors for bet_size.rs

I'm in the midst of writing up some refactors. To make it easier to understand why I'm doing this (especially since there will be some breaking changes introduced), I'm documenting both what I'm changing and why I'm changing it.

Move is_raise related checks from BetSize creation to BetSizeOptions creation

bet_size_from_str(&str, boolean) depends on an is_raise: boolean predicate to return an Error under two conditions:

However, creating the bet size shouldn't be where this triggers an Err. For instance, BetSize::PrevBetRelative is a valid bet size but doesn't belong in BetSizeOptions::bet. This is causing some issues. For instance, during deserialization, I don't want to have to encode into the deserialization routine whether we are parsing a bet size or a raise size. Additionally, this is just suboptimal design, and should be refactored in its own right.

Instead, I'm refactoring so that BetSizeOptions is created from BetSizeOptions::try_from_sizes(bets: Vec<BetSize>, raises: Vec<BetSize>). This checks if there are invalid sizes in bets and, if so, returns an Err. Thus, BetSizeOptions should be created through officially supported construction functions such as try_from_sizes, and these should always check for invalid BetSizes in the bet field.

Make BetSizeOptions fields non-public

Next, bet_size::BetSizeOptions has public fields, meaning that it can be constructed:

BetSizeOptions { bet: SOME_VEC, raise: SOME_VEC }

Since there are invalid bet vectors, this means a user can bypass the 'official' constructors for BetSizeOptions (namely, BetSizeOptions::try_from_sizes(...)) which will silently create invalid instances.

Rename BetSizeOptions fields bet and raise to bets and raises

These are plural, so these should be pluralized.

bkushigian commented 1 month ago

ugh i keep opening issues in upstream lol