-
Notifications
You must be signed in to change notification settings - Fork 31
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
base: master
Are you sure you want to change the base?
Conversation
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.
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" |
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.
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 |
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.
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) || |
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.
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 |
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.
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 |
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.
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".
@jaybobo