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

completed challenge #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

completed challenge #25

wants to merge 1 commit into from

Conversation

ewarman
Copy link

@ewarman ewarman commented Jan 18, 2017

Copy link
Member

@qubbit qubbit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent use of spaces and tabs between files. I recommend using a linter like rubocop.

Also, to maintain consistent indentation in your code you can use http://editorconfig.org/

loop do
Print::score(scorekeeper.player_score, scorekeeper.computer_score)
case Print::new_match
when "r", "R"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could simplify by this by doing something like this:

foo = Print::new_match.downcase

case foo
when 'r'
when 'p'

etc

end

def evaluate(player_move)
@computer_move = generate_computer_move

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you've defined an attr_acessor for this variable, the @ in unnecessary.

Here's a pretty thorough explanation on stack overflow: http://stackoverflow.com/questions/5046831/why-use-rubys-attr-accessor-attr-reader-and-attr-writer

It's a pretty simple concept once you get the hang of it!

@player_move = player_move
@win = nil
if @player_move!=@computer_move
if (@player_move == :rock && @computer_move == :scissors) ||

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a pretty heavy if statement. You could extract this away into a method call, something like did_player_win? or winning_move?. Abstracting obtuse logic into nicely named method is a great way to help the next person to work on your code understand your intent!

end

def generate_computer_move
prng = Random.new

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is pretty short you could combine this line and the on below it since the instance is only used 1 time.

res = Random.new.rand(3)

def generate_computer_move
prng = Random.new
res = prng.rand(3)
if res == 0
Copy link

@austenmadden austenmadden Jan 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another way this could be handled is initializing a collection

moves = [:rock, :paper, :scissors].freeze
moves[res]

This is cool since you can also make this a class constant, and reuse it/establish an interface for dealing with the "moves".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants