This file contains hidden or 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
| require 'rspec' | |
| #Need something like spots/adjacency | |
| class Board | |
| attr_reader :cell_count | |
| def initialize | |
| @cells = [] | |
| end |
This file contains hidden or 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
| require 'rspec' | |
| class Board | |
| LIVE = "X" | |
| DEAD = "O" | |
| attr_reader :board | |
| def initialize(board_array) | |
| @board = parse_in(board_array) |
This file contains hidden or 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
| require 'rspec' | |
| def get_score(game) | |
| bonus_tally = [] | |
| counter = 0 | |
| while counter < game.length | |
| if game[counter] == 10 | |
| scores_to_add = [game[counter + 1], game[counter + 2]] | |
| bonus_tally += scores_to_add unless scores_to_add.any?(&:nil?) |
This file contains hidden or 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
| require 'rspec' | |
| class Game | |
| attr_reader :player1, :player2 | |
| POINTS = [0, 15, 30, 40] | |
| def initialize | |
| @player1 = Player.new('player1') | |
| @player2 = Player.new('player2') | |
| @point = Point.new(@player1, @player2) | |
| @score_view = ScoreView.new(@player1, @player2) |
This file contains hidden or 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
| require 'rspec' | |
| class Game | |
| attr_reader :player1, :player2 | |
| def initialize | |
| @player1 = Player.new('player 1') | |
| @player2 = Player.new('player 2') | |
| @score_view = ScoreView.new(self) | |
| end |
This file contains hidden or 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
| require 'rspec' | |
| def from_roman(roman) | |
| if roman.include? "X" | |
| roman[0] == "X" ? 10 * roman.count("X") + ones(roman) : 9 | |
| else | |
| ones(roman) | |
| end | |
| end |
This file contains hidden or 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
| require 'rspec' | |
| # input: integer (0-100) | |
| # output: hash, e.g. | |
| # 5 -> {quarters: 0, dimes: 0, nickels: 1, pennies: 0} | |
| # 12 -> {quarters: 0, dimes: 1, nickels: 0, pennies: 2} | |
| describe "#make_change" do | |
| it "1 should return 1 penny" do | |
| expect(make_change(1)).to eq(quarters: 0, dimes: 0, nickels: 0, pennies: 1) |
This file contains hidden or 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
| require 'rspec' | |
| # input: integer (0-100) | |
| # output: hash, e.g. | |
| # 5 -> {quarters: 0, dimes: 0, nickels: 1, pennies: 0} | |
| # 12 -> {quarters: 0, dimes: 1, nickels: 0, pennies: 2} | |
| # describe "#make_change" do | |
| # before { | |
| # @change_maker = AmericanChangeMaker.new(ChangeMaker) |
This file contains hidden or 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
| require 'rspec' | |
| #all gutters -> 0 | |
| #scores twenty with one pin knocked down every roll | |
| #spare in frame 1 followed by 3 pins = 16 | |
| #strike -> 3-> 4 = 24 | |
| #perfect game -> 300 | |
| class BowlingGame | |
| attr_reader :scorecard | |
| def initialize |
This file contains hidden or 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
| class BowlingGame | |
| attr_accessor :scorecard | |
| def score | |
| @scorecard.size.times.map { |i| frame_score(@scorecard[i, 3]) }.reduce(:+) | |
| end | |
| def frame_score(frames) | |
| if strike_or_spare?(frames.first) | |
| frames.flatten.first(3).reduce(:+) | |
| else |