From 872d98d636a9b75d2ec73febce9eccb72fa35b3f Mon Sep 17 00:00:00 2001 From: alex Date: Sun, 10 May 2026 14:16:56 +0500 Subject: [PATCH 1/5] test: get score second roll in first frame --- tests/test_game.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/test_game.cpp b/tests/test_game.cpp index b98c25c..ca098be 100644 --- a/tests/test_game.cpp +++ b/tests/test_game.cpp @@ -185,4 +185,12 @@ TEST(GameTest, FrameScoreTenthFrameIncomplete) { game.roll(0); game.roll(10); EXPECT_EQ(game.frameScore(10), 0); +} + +TEST(GameTest, SecondRollInFirstFrame) { + Game game; + game.roll(0); + game.roll(5); + for (int i = 0; i < 18; ++i) + EXPECT_EQ(game.rollScore(1, 2), 5); } \ No newline at end of file From 642dc40387f879a28973b0e0fcffea0f28bf2021 Mon Sep 17 00:00:00 2001 From: alex Date: Sun, 10 May 2026 14:21:37 +0500 Subject: [PATCH 2/5] feat: add get roll score stub --- includes/game.h | 1 + sources/game.cpp | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/includes/game.h b/includes/game.h index 6a25937..d0b1992 100644 --- a/includes/game.h +++ b/includes/game.h @@ -10,6 +10,7 @@ class Game { void roll(int pins); int score() const; int frameScore(int frame) const; + int rollScore(int frame, int roll) const; }; #endif \ No newline at end of file diff --git a/sources/game.cpp b/sources/game.cpp index 33f9327..0dc88fb 100644 --- a/sources/game.cpp +++ b/sources/game.cpp @@ -80,4 +80,6 @@ int Game::frameScore(int frame) const { } return rolls[rollIndex] + rolls[rollIndex + 1]; -} \ No newline at end of file +} + +int Game::rollScore(int frame, int roll) const { return 5; } \ No newline at end of file From e95fe2fb686d77709d899bb694fc452c2b7a20b3 Mon Sep 17 00:00:00 2001 From: alex Date: Sun, 10 May 2026 14:29:49 +0500 Subject: [PATCH 3/5] feat: get roll score of default frames --- sources/game.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/sources/game.cpp b/sources/game.cpp index 0dc88fb..ce8378e 100644 --- a/sources/game.cpp +++ b/sources/game.cpp @@ -82,4 +82,12 @@ int Game::frameScore(int frame) const { return rolls[rollIndex] + rolls[rollIndex + 1]; } -int Game::rollScore(int frame, int roll) const { return 5; } \ No newline at end of file +int Game::rollScore(int frame, int roll) const { + int rollIndex = 0; + + for (int f = 1; f < frame; ++f) { + rollIndex += 2; + } + + return rolls[rollIndex + roll - 1]; +} \ No newline at end of file From 76585e30ff09f88becd3e13f3a3e8f113f936f32 Mon Sep 17 00:00:00 2001 From: alex Date: Sun, 10 May 2026 14:54:37 +0500 Subject: [PATCH 4/5] test: rolls scores with strike --- tests/test_game.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tests/test_game.cpp b/tests/test_game.cpp index ca098be..aaef7df 100644 --- a/tests/test_game.cpp +++ b/tests/test_game.cpp @@ -192,5 +192,21 @@ TEST(GameTest, SecondRollInFirstFrame) { game.roll(0); game.roll(5); for (int i = 0; i < 18; ++i) - EXPECT_EQ(game.rollScore(1, 2), 5); + game.roll(0); + EXPECT_EQ(game.rollScore(1, 2), 5); +} + +TEST(GameTest, RollScoreWithStrike) { + Game game; + game.roll(0); + game.roll(5); + game.roll(10); + game.roll(5); + game.roll(4); + EXPECT_EQ(game.rollScore(1, 1), 0); + EXPECT_EQ(game.rollScore(1, 2), 5); + EXPECT_EQ(game.rollScore(2, 1), 10); + EXPECT_EQ(game.rollScore(2, 2), 0); + EXPECT_EQ(game.rollScore(3, 1), 5); + EXPECT_EQ(game.rollScore(3, 2), 4); } \ No newline at end of file From db29c6c133252fb1c8ac4d7b967784719f4ad24f Mon Sep 17 00:00:00 2001 From: alex Date: Sun, 10 May 2026 14:58:40 +0500 Subject: [PATCH 5/5] feat: get roll score include strikes --- sources/game.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/sources/game.cpp b/sources/game.cpp index ce8378e..f124cf8 100644 --- a/sources/game.cpp +++ b/sources/game.cpp @@ -86,8 +86,22 @@ int Game::rollScore(int frame, int roll) const { int rollIndex = 0; for (int f = 1; f < frame; ++f) { - rollIndex += 2; + if (rollIndex >= rolls.size()) + return 0; + if (rolls[rollIndex] == 10) + rollIndex += 1; + else + rollIndex += 2; } - return rolls[rollIndex + roll - 1]; + if (rollIndex >= rolls.size()) + return 0; + + if (roll == 2 && rolls[rollIndex] == 10) + return 0; + + if (rollIndex + (roll - 1) >= rolls.size()) + return 0; + + return rolls[rollIndex + (roll - 1)]; } \ No newline at end of file