Skip to content
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

Bowling challenge #1606

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
env: {
browser: true,
commonjs: true,
es2021: true,
},
extends: 'airbnb-base',
overrides: [
],
parserOptions: {
ecmaVersion: 'latest',
},
rules: {
},
};
91 changes: 29 additions & 62 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,91 +1,58 @@
# Makers Academy Bowling Challenge (Javascript)

Bowling Challenge
=================

* 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
A weekend challenge as part of the Makers Academy bootcamp, undertaken in Javascript after [attempting the same problem in Ruby](https://github.com/tomcarmichael/bowling-challenge-ruby.git) first.

## The Task

**THIS IS NOT A BOWLING GAME, IT IS A BOWLING SCORECARD. DO NOT GENERATE RANDOM ROLLS. AN ACTUAL USER INTERFACE IS OPTIONAL**

Count and sum the scores of a bowling game for one player (in JavaScript).

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.

Start by looking in detail at the rules and the example of scoring for a complete game given below.

An example of how your code might be used could be:

```javaScript
let scorecard = new Scorecard()
scorecard.calculateScore() // returns 0
scorecard.addFrame(2, 5)
scorecard.addFrame(3, 5)
scorecard.calculateScore() // returns 15
```

But feel free to add other methods if you think they are useful.

As usual please start by

* Forking this repo

* Using test-driven development (if you decide to write a user interface, then make sure you have looked at the chapters on mocking).
The brief was defined in the README of the [Makers Academy repo](https://github.com/makersacademy/bowling-challenge) that I forked to begin this challenge.

* 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.
Key points:

___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.
>**THIS IS NOT A BOWLING GAME, IT IS A BOWLING SCORECARD. DO NOT GENERATE RANDOM ROLLS. AN ACTUAL USER INTERFACE IS OPTIONAL**

### Optional Extras
>Count and sum the scores of a bowling game for one player (in JavaScript).

In any order you like:
>More about ten pin bowling here: http://en.wikipedia.org/wiki/Ten-pin_bowling

* Set up [Travis CI](https://travis-ci.org) to run your tests.
* Add [ESLint](http://eslint.org/) to your codebase and make your code conform.
* Create a UserInterface class, allowing you to run a game from the command line.
## Getting started

You might even want to start with ESLint early on in your work — to help you
learn Javascript conventions as you go along.
`git clone https://github.com/tomcarmichael/bowling-challenge.git`

## Bowling — how does it work?
Install dependencies: `npm install`

### Strikes
## Usage

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.
The program is designed to be used in the context of the Node REPL, having been created solely as a learning exercise.

### Spares
In the terminal, run:

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).
`node`

### 10th frame
`const Game = require('./game')`

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.
`const game = new Game()`

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).
Define a 2D array of valid scores for a bowling game (each frame is an array) e.g.

### Gutter Game
`const scores = [[1, 4], [4, 5], [6, 4], [5, 5], [10], [0, 1], [7, 3], [6, 4], [10], [2, 7]]`

A Gutter Game is when the player never hits a pin (20 zero scores).
`game.play(scores)`

### Perfect Game
See the total score for the 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.
`game.grandTotal`

In the image below you can find some score examples.
Check if the game is a perfect game or gutter game:

More about ten pin bowling here: http://en.wikipedia.org/wiki/Ten-pin_bowling
`game.isGutterGame()` , `game.isPerfectGame()`

![Ten Pin Score Example](images/example_ten_pin_scoring.png)
## Running Tests

## Code Review
`jest`

In code review we'll be hoping to see:
![bowling-challenge-jest](./screenshots/bowling-challenge-jest.png)
![bowling-challenge-node](./screenshots/bowling-challenge-node.png)

* All tests passing
* The code is elegant: every class has a clear responsibility, methods are short etc.
## Reflections

Reviewers will potentially be using this [code review rubric](docs/review.md). Note that referring to this rubric in advance may make the challenge somewhat easier. You should be the judge of how much challenge you want.
This challenge was completed after one week of learning Javascript, following on from completing [the same challenge in Ruby](https://github.com/tomcarmichael/bowling-challenge-ruby). Although I did not implement a UI via the command line in this Javascript version, I tried to design and write the program in a way that would make it easily extendable for such a feature. A key goal for me was to write the program in such a way that scores were updated as soon as possible, during the game (as they would be in a bowling alley) something made more complex by the rules around bonus points for strikes and spares which are based on the scores in the subsequent frames. In the Ruby version of the challenge, scores were calculated at the end of the game only, and the user interface code was not sufficiently separated from the rest of the game logic. In this version of the program, I feel I was able to improve on both of those problems.
61 changes: 61 additions & 0 deletions coverage/clover.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<coverage generated="1684933289319" clover="3.2.0">
<project timestamp="1684933289319" name="All files">
<metrics statements="49" coveredstatements="49" conditionals="27" coveredconditionals="26" methods="17" coveredmethods="17" elements="93" coveredelements="92" complexity="0" loc="49" ncloc="49" packages="1" files="2" classes="2"/>
<file name="frame.js" path="/Users/tomcarmichael/Documents/code/js/bowling-challenge/frame.js">
<metrics statements="14" coveredstatements="14" conditionals="8" coveredconditionals="8" methods="6" coveredmethods="6"/>
<line num="3" count="122" type="stmt"/>
<line num="4" count="122" type="stmt"/>
<line num="5" count="122" type="stmt"/>
<line num="9" count="195" type="cond" truecount="4" falsecount="0"/>
<line num="10" count="2" type="stmt"/>
<line num="11" count="193" type="cond" truecount="2" falsecount="0"/>
<line num="12" count="1" type="stmt"/>
<line num="14" count="192" type="stmt"/>
<line num="15" count="192" type="stmt"/>
<line num="20" count="116" type="stmt"/>
<line num="21" count="186" type="stmt"/>
<line num="26" count="148" type="stmt"/>
<line num="30" count="110" type="cond" truecount="2" falsecount="0"/>
<line num="33" count="3" type="stmt"/>
</file>
<file name="game.js" path="/Users/tomcarmichael/Documents/code/js/bowling-challenge/game.js">
<metrics statements="35" coveredstatements="35" conditionals="19" coveredconditionals="18" methods="11" coveredmethods="11"/>
<line num="1" count="2" type="stmt"/>
<line num="5" count="15" type="stmt"/>
<line num="6" count="15" type="stmt"/>
<line num="7" count="15" type="stmt"/>
<line num="8" count="15" type="stmt"/>
<line num="12" count="15" type="stmt"/>
<line num="13" count="150" type="stmt"/>
<line num="14" count="150" type="stmt"/>
<line num="19" count="13" type="stmt"/>
<line num="21" count="130" type="stmt"/>
<line num="22" count="130" type="cond" truecount="2" falsecount="0"/>
<line num="24" count="13" type="stmt"/>
<line num="25" count="13" type="cond" truecount="4" falsecount="0"/>
<line num="27" count="7" type="stmt"/>
<line num="29" count="13" type="stmt"/>
<line num="33" count="117" type="stmt"/>
<line num="34" count="117" type="stmt"/>
<line num="35" count="117" type="stmt"/>
<line num="37" count="117" type="cond" truecount="2" falsecount="0"/>
<line num="38" count="13" type="stmt"/>
<line num="39" count="104" type="cond" truecount="2" falsecount="0"/>
<line num="40" count="43" type="stmt"/>
<line num="42" count="43" type="cond" truecount="4" falsecount="0"/>
<line num="43" count="32" type="stmt"/>
<line num="49" count="7" type="stmt"/>
<line num="50" count="7" type="stmt"/>
<line num="52" count="7" type="stmt"/>
<line num="53" count="10" type="stmt"/>
<line num="56" count="7" type="cond" truecount="4" falsecount="0"/>
<line num="57" count="2" type="stmt"/>
<line num="62" count="13" type="stmt"/>
<line num="63" count="130" type="stmt"/>
<line num="68" count="1" type="stmt"/>
<line num="72" count="1" type="stmt"/>
<line num="76" count="2" type="stmt"/>
</file>
</project>
</coverage>
Loading