Bowling.rs
A basic bowling score calculator written in Rust.
Installation
cargo add bowling-rs
Usage
You can create games manually with frames.
use ;
// Create a game with 12 strikes
let mut game = new;
// A perfect game has three strikes in the 10th frame, so we add that here
game.add_frame;
assert_eq!;
use ;
// A more realistic game
let game = new;
assert_eq!;
Parsing
You can also create games with a Vec<Vec<usize>> or Vec<usize> using [parse_score] or [parse_raw_score], respectively.
use ;
// Each frame is a `Vec<usize>`
let game = parse_score;
assert_eq!;
[parse_raw_score] takes in shots, rather than frames.
use ;
// Each shot is a `usize`
let game = parse_raw_score; // You must specify whether there was a bonus shot or not
assert_eq!;
Custom Bowling Scoring
You can create custom scoring for games using a [ScoreProvider].
use ;
;
// Implement `ScoreProvider`
// Create a basic game with 10 strikes
let game = new;
// Calculate the game's score with our `CustomScoreProvider`
let score = game.score_with_provider;
// The score should be 100, since there are 10 pins per strike
assert_eq!;
Contributing
Please create an issue at this time.