Skip to content

Commit 709420e

Browse files
committed
simplify frame by removing an Option
1 parent 9ec9ccd commit 709420e

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

rust/bowling/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ impl BowlingGame {
4343

4444
// Handle normal rolls
4545
if pins == 10 {
46-
let frame = Frame::new(pins, None);
46+
let frame = Frame::new(pins, 0);
4747
self.frames.push(frame);
4848
}
4949
if self.previous_roll.is_some() {
5050
let roll1 = self.previous_roll.unwrap();
51-
let frame = Frame::new(roll1, Some(pins));
51+
let frame = Frame::new(roll1, pins);
5252
self.frames.push(frame);
5353
self.previous_roll = None;
5454
} else {
@@ -68,7 +68,7 @@ impl BowlingGame {
6868
total += frame.score(self.fill_ball1.unwrap_or(0), self.fill_ball2.unwrap_or(0));
6969
} else {
7070
let next_roll1 = next_frame.unwrap().roll1;
71-
let next_roll2 = next_frame.unwrap().roll2.unwrap();
71+
let next_roll2 = next_frame.unwrap().roll2;
7272
total += frame.score(next_roll1, next_roll2);
7373
}
7474
}
@@ -91,11 +91,11 @@ impl BowlingGame {
9191

9292
pub struct Frame {
9393
pub roll1: u16,
94-
roll2: Option<u16>
94+
pub roll2: u16
9595
}
9696

9797
impl Frame {
98-
pub fn new(roll1:u16, roll2: Option<u16>) -> Self {
98+
pub fn new(roll1:u16, roll2: u16) -> Self {
9999
return Frame{
100100
roll1: roll1,
101101
roll2: roll2
@@ -119,6 +119,6 @@ impl Frame {
119119
return self.roll1 != 10 && self.open_frame_score() == 10
120120
}
121121
fn open_frame_score(&self) -> u16 {
122-
self.roll1 + self.roll2.unwrap_or(0)
122+
self.roll1 + self.roll2
123123
}
124124
}

0 commit comments

Comments
 (0)