-
Notifications
You must be signed in to change notification settings - Fork 499
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
Partially completed bowling challenge #394
Open
SomthingInteresting
wants to merge
9
commits into
makersacademy:main
Choose a base branch
from
SomthingInteresting:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
235a794
initial commit with rspec setup and game and game spec file created
SomthingInteresting 67db208
initialise method working for game.rb, roll, frame and scoreboard cla…
SomthingInteresting d8649fb
initialise method working for game.rb, roll, frame and scoreboard cla…
SomthingInteresting ec36dd9
roll methods working with tests added, created game_test.app to see r…
SomthingInteresting ff180da
fixed current frame being added everytime to total frames
SomthingInteresting f69c181
simplified scoreboard to be in line with project focus of having read…
SomthingInteresting eec9084
refactored scoreboard so format is seperate
SomthingInteresting 5f8c296
added to README file and uploaded updated diagram
SomthingInteresting d4325d9
created strike test for scorecard but haven't updated method
SomthingInteresting File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--require spec_helper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
source "https://rubygems.org" | ||
|
||
# gem "rails" | ||
|
||
gem "rspec", "~> 3.12" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
diff-lcs (1.5.0) | ||
rspec (3.12.0) | ||
rspec-core (~> 3.12.0) | ||
rspec-expectations (~> 3.12.0) | ||
rspec-mocks (~> 3.12.0) | ||
rspec-core (3.12.2) | ||
rspec-support (~> 3.12.0) | ||
rspec-expectations (3.12.3) | ||
diff-lcs (>= 1.2.0, < 2.0) | ||
rspec-support (~> 3.12.0) | ||
rspec-mocks (3.12.5) | ||
diff-lcs (>= 1.2.0, < 2.0) | ||
rspec-support (~> 3.12.0) | ||
rspec-support (3.12.0) | ||
|
||
PLATFORMS | ||
arm64-darwin-21 | ||
|
||
DEPENDENCIES | ||
rspec (~> 3.12) | ||
|
||
BUNDLED WITH | ||
2.4.12 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
Bowling Challenge in Ruby | ||
================= | ||
|
||
* Feel free to use google, your notes, books, etc. but work on your own | ||
* If you refer to the solution of another coach or student, please put a link to that in your README | ||
* If you have a partial solution, **still check in a partial solution** | ||
* You must submit a pull request to this repo with your code by 9am Monday week | ||
|
||
## The Task | ||
|
||
**THIS IS NOT A BOWLING GAME, IT IS A BOWLING SCORECARD PROGRAM. DO NOT GENERATE RANDOM ROLLS. THE USER INPUTS THE ROLLS.** | ||
|
||
Count and sum the scores of a bowling game for one player. For this challenge, you do _not_ need to build a web app with a UI, instead, just focus on the logic for bowling (you also don't need a database). Next end-of-unit challenge, you will have the chance to translate the logic to Javascript and build a user interface. | ||
|
||
A bowling game consists of 10 frames in which the player tries to knock down the 10 pins. In every frame the player can roll one or two times. The actual number depends on strikes and spares. The score of a frame is the number of knocked down pins plus bonuses for strikes and spares. After every frame the 10 pins are reset. | ||
|
||
As usual please start by | ||
|
||
* Forking this repo | ||
|
||
* Finally submit a pull request before Monday week at 9am with your solution or partial solution. However much or little amount of code you wrote please please please submit a pull request before Monday week at 9am. | ||
|
||
___STRONG HINT, IGNORE AT YOUR PERIL:___ Bowling is a deceptively complex game. Careful thought and thorough diagramming — both before and throughout — will save you literal hours of your life. | ||
|
||
## Focus for this challenge | ||
The focus for this challenge is to write high-quality code. | ||
|
||
In order to do this, you may pay particular attention to the following: | ||
* Using diagramming to plan your approach to the challenge | ||
* TDD your code | ||
* Focus on testing behaviour rather than state | ||
* Commit often, with good commit messages | ||
* Single Responsibility Principle and encapsulation | ||
* Clear and readable code | ||
|
||
## Bowling — how does it work? | ||
|
||
### Strikes | ||
|
||
The player has a strike if he knocks down all 10 pins with the first roll in a frame. The frame ends immediately (since there are no pins left for a second roll). The bonus for that frame is the number of pins knocked down by the next two rolls. That would be the next frame, unless the player rolls another strike. | ||
|
||
### Spares | ||
|
||
The player has a spare if the knocks down all 10 pins with the two rolls of a frame. The bonus for that frame is the number of pins knocked down by the next roll (first roll of next frame). | ||
|
||
### 10th frame | ||
|
||
If the player rolls a strike or spare in the 10th frame they can roll the additional balls for the bonus. But they can never roll more than 3 balls in the 10th frame. The additional rolls only count for the bonus not for the regular frame count. | ||
|
||
10, 10, 10 in the 10th frame gives 30 points (10 points for the regular first strike and 20 points for the bonus). | ||
1, 9, 10 in the 10th frame gives 20 points (10 points for the regular spare and 10 points for the bonus). | ||
|
||
### Gutter Game | ||
|
||
A Gutter Game is when the player never hits a pin (20 zero scores). | ||
|
||
### Perfect Game | ||
|
||
A Perfect Game is when the player rolls 12 strikes (10 regular strikes and 2 strikes for the bonus in the 10th frame). The Perfect Game scores 300 points. | ||
|
||
In the image below you can find some score examples. | ||
|
||
More about ten pin bowling here: http://en.wikipedia.org/wiki/Ten-pin_bowling | ||
|
||
![Ten Pin Score Example](images/example_ten_pin_scoring.png) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,39 @@ | ||
Bowling Challenge in Ruby | ||
================= | ||
# Bowling Challenge in Ruby | ||
|
||
* Feel free to use google, your notes, books, etc. but work on your own | ||
* If you refer to the solution of another coach or student, please put a link to that in your README | ||
* If you have a partial solution, **still check in a partial solution** | ||
* You must submit a pull request to this repo with your code by 9am Monday week | ||
This is a solution to the bowling challenge in Ruby. The challenge is to write a program that calculates the score of a bowling game. | ||
|
||
## The Task | ||
## How to use | ||
|
||
**THIS IS NOT A BOWLING GAME, IT IS A BOWLING SCORECARD PROGRAM. DO NOT GENERATE RANDOM ROLLS. THE USER INPUTS THE ROLLS.** | ||
Clone this repo and run bundle install to install the dependencies. | ||
|
||
Count and sum the scores of a bowling game for one player. For this challenge, you do _not_ need to build a web app with a UI, instead, just focus on the logic for bowling (you also don't need a database). Next end-of-unit challenge, you will have the chance to translate the logic to Javascript and build a user interface. | ||
To run the tests, run rspec from the command line. | ||
|
||
A bowling game consists of 10 frames in which the player tries to knock down the 10 pins. In every frame the player can roll one or two times. The actual number depends on strikes and spares. The score of a frame is the number of knocked down pins plus bonuses for strikes and spares. After every frame the 10 pins are reset. | ||
To run the program: | ||
|
||
As usual please start by | ||
run irb from the command line and require the game file. | ||
|
||
* Forking this repo | ||
OR | ||
|
||
* Finally submit a pull request before Monday week at 9am with your solution or partial solution. However much or little amount of code you wrote please please please submit a pull request before Monday week at 9am. | ||
run ruby game.rb from the command line. | ||
|
||
___STRONG HINT, IGNORE AT YOUR PERIL:___ Bowling is a deceptively complex game. Careful thought and thorough diagramming — both before and throughout — will save you literal hours of your life. | ||
## Diagram | ||
|
||
## Focus for this challenge | ||
The focus for this challenge is to write high-quality code. | ||
INSERT DIAGRAM | ||
|
||
In order to do this, you may pay particular attention to the following: | ||
* Using diagramming to plan your approach to the challenge | ||
* TDD your code | ||
* Focus on testing behaviour rather than state | ||
* Commit often, with good commit messages | ||
* Single Responsibility Principle and encapsulation | ||
* Clear and readable code | ||
## Classes | ||
|
||
## Bowling — how does it work? | ||
### Game | ||
|
||
### Strikes | ||
The main class that controls the flow of the game. It has an `initialize` method that sets up the game with a new Frame and a new Scorecard. It also has a `roll` method which calls the roll method on the current frame and updates the Scorecard. The game continues until all frames are played. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I get the logic, but do we really need a Roll class? It seems like all it is doing right now is keeping an integer for a score, could we have not done that by just using actual integers in an array? |
||
|
||
The player has a strike if he knocks down all 10 pins with the first roll in a frame. The frame ends immediately (since there are no pins left for a second roll). The bonus for that frame is the number of pins knocked down by the next two rolls. That would be the next frame, unless the player rolls another strike. | ||
### Frame | ||
|
||
### Spares | ||
Controls the rolls in a frame. It has a `roll` method that adds the score to the frame and checks if the frame is over. It also has methods to check if the frame is a strike or a spare. A frame is considered over if it's a strike or has two rolls. | ||
|
||
The player has a spare if the knocks down all 10 pins with the two rolls of a frame. The bonus for that frame is the number of pins knocked down by the next roll (first roll of next frame). | ||
### Scorecard | ||
|
||
### 10th frame | ||
Controls the score. It has an `update` method that adds the score to the total score and calculates the bonus scores for strikes and spares, updating the frame scores accordingly. It also has a method to show the scorecard, which prints the score in a readable format. | ||
|
||
If the player rolls a strike or spare in the 10th frame they can roll the additional balls for the bonus. But they can never roll more than 3 balls in the 10th frame. The additional rolls only count for the bonus not for the regular frame count. | ||
### Roll | ||
|
||
10, 10, 10 in the 10th frame gives 30 points (10 points for the regular first strike and 20 points for the bonus). | ||
1, 9, 10 in the 10th frame gives 20 points (10 points for the regular spare and 10 points for the bonus). | ||
|
||
### Gutter Game | ||
|
||
A Gutter Game is when the player never hits a pin (20 zero scores). | ||
|
||
### Perfect Game | ||
|
||
A Perfect Game is when the player rolls 12 strikes (10 regular strikes and 2 strikes for the bonus in the 10th frame). The Perfect Game scores 300 points. | ||
|
||
In the image below you can find some score examples. | ||
|
||
More about ten pin bowling here: http://en.wikipedia.org/wiki/Ten-pin_bowling | ||
|
||
![Ten Pin Score Example](images/example_ten_pin_scoring.png) | ||
Records the score of the roll and feeds it to the Frame and Scorecard classes. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently the test on scorecard_spec.rb line 38 fails on rspec, but I am assuming that is because it is still in WIP
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct WIP