Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

- DO IN RUBY. Project is a Rock, Paper, Scissors game. Using Cloud 9, and here is the skeleton outline we were given: class RockPaperScissors

- DO IN RUBY. Project is a Rock, Paper, Scissors game. Using Cloud 9, and here is the skeleton outline we were given:

class RockPaperScissors

# Exceptions this class can raise: class NoSuchStrategyError < StandardError ; end

def self.winner(player1, player2)

#enter code here

end

def self.tournament_winner(tournament)

#enter code here

end

end

Here is what we are supposed to do:

spec/rock_paper_scissors_spec.rb

In a game of rock-paper-scissors, each player chooses to play Rock (R), Paper (P), or Scissors (S). The rules are: Rock breaks Scissors, Scissors cuts Paper, but Paper covers Rock. (In other words, Rock wins over Scissors, Scissors wins over Paper, and Paper wins over Rock.)

In a round of rock-paper-scissors, each player's name and strategy is encoded as an array of two elements

[ ["Kristen", "P"], ["Jacob", "S"] ] # Jacob would win since S > P

A: Game Winner:

Create a RockPaperScissors class with a class method winner that takes two 2-element arrays like those above, and returns the one representing the winner:

RockPaperScissors.winner(['Kristen,'P'], ['Jacob','S']) # => ['Jacob','S']

If either player's strategy is something other than "R", "P" or "S" (case-insensitive), the method should raise a RockPaperScissors::NoSuchStrategyError exception.

If both players use the same strategy, the first player is the winner.

B: Tournament:

A rock-paper-scissors tournament is encoded as an array of games - that is, each element can be considered its own tournament.

[ [ [ ["Kristen", "P"], ["Ben", "S"] ], [ ["Justin", "R"], ["Walter", "S"] ], ], [ [ ["Allen", "S"], ["Omer", "P"] ], [ ["David", "R"], ["Richard", "P"] ] ] ]

In the tournament above Kristen will always play P and Ben will always play S. This tournament plays out as follows:

Under this scenario, Ben would beat Kristen (S>P) and Justin would beat Walter (R>S), so Ben and Justin would play (Justin wins since R>S); similarly, Allen would beat Omer, Richard would beat David, and Allen and Richard would play (Allen wins since S>P); and finally Justin would beat Allen since R>S. That is, pairwise play continues until there is only a single winner.

Write a method `RockPaperScissors.tournament_winner' that takes a tournament encoded as an array and returns the winner (for the above example, it should return ['Justin', 'R']). You can assume that the array is well formed (that is, there are 2n players, and each one participates in exactly one match per round).

HINT: Formulate the problem as a recursive one whose base case you solved in part A.

Select one of the rspec tests, copy it, and modify it so that it tests a feature of the rock-paper-scissors library you have implemented. Alternatively, you can write your own test.

Finally, go to your text file and summarize the purpose of each rspec test (including your added test).

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Secrets Of Analytical Leaders Insights From Information Insiders

Authors: Wayne Eckerson

1st Edition

1935504347, 9781935504344

More Books

Students also viewed these Databases questions

Question

What is intraperiod tax allocation?

Answered: 1 week ago

Question

(4) How much feedback am I giving them on their performance?

Answered: 1 week ago

Question

(2) How stretching are these goals?

Answered: 1 week ago