rps-project's People
rps-project's Issues
Implicit vs Explicit return values
(https://github.com/hilarysk/rps-project/blob/master/2015-01-29-rps-player-class.rb#L89)
I noticed you have a lot of explicit returns. That may not be a problem but I know a lot of ruby style guides states that the "Ruby Way" is to return values implicitly (no return statement). Figured I would throw that out there.
Ex:
Avoid return where not required for flow of control.
# bad
def some_method(some_arr)
return some_arr.size
end
# good
def some_method(some_arr)
some_arr.size
end
(Linked from: https://github.com/bbatsov/ruby-style-guide#no-explicit-return)
Keep in mind SRP.
(https://github.com/hilarysk/rps-project/blob/master/2015-01-29-rules-class.rb#L92-L101)
I would suggest thinking about single responsibility rule in some areas. Take the link above as an example.
This method both decides if moves are valid and if they aren't it also judges those moves and increments wins for the players who followed the rules. Seems like it is doing some pretty hefty hauling.
Game inherits from Player?
https://github.com/hilarysk/rps-project/blob/master/2015-01-29-game-class.rb#L25-Lundefined
Did you mean for Game to inherit from Player? I can't find where you use that later, and it seems both unnecessary and the sort of thing that could accidentally cause problems that might be hard to diagnose later if you didn't realize you did this.
If you never call Player methods on a game class, I don't think you want this.
Unless I missed where you did?
@app_name1 == player1.name
https://github.com/hilarysk/rps-project/blob/master/2015-01-29-game-class.rb#L44-L49
You don't need either app_name1 or app_name2 as a parameter for this method. You are already passing that info along inside the player objects, it can be accessed by the #name method you defined with attr_accessor in the Player class.
1. attributes versus local variables 2. lose if typo?
https://github.com/hilarysk/rps-project/blob/master/2015-02-01-psrls-class.rb#L88-L101
In general, you seem to assign @attributes much more frequently than you need to.
If you do not need to recall the information outside of this method, you should not need to save them as attributes.
if you remove
@move1 = move1
@move2 = move
I believe this method will work fine.
Secondly, am I reading this correctly that if I enter "rockl" as my move, or even maybe "Rock" I just LOSE A POINT? That's... harsh. I'm confused, you had a loop that check for valid input earlier when you asked for what kind of game the user wanted to play. Why not use a similar loop when players input their moves? Right now, you're simply penalizing user error. It feels like you're pointing at your user and laughing.
Suggest using modules in rules-class and psrls-class for shared methods
I hesitate to list this one as it comes with knocking out a lot of the character of the returns of these rules but I highly suggest finding the common methods and breaking them out to their own calls. currently psrls has basically the same rules as psr but more.
It would probably take some big reworks but I think it should be doable and cut down a lot of your code as you are repeating yourself quite a bit between the two classes.
For instance: both classes have a method for check_if_moves_are_valid which calls upon their individual @possible_moves array. Aside from the difference that @possible_moves array the methods boil down to the exact same. You should be able to create a module out of these. (Note that currently you are puts different text between the classes but it can be summed up to being the same)
Unnecessarily calling and storing .self
https://github.com/hilarysk/rps-project/blob/master/2015-01-29-game-class.rb#L108-Lundefined
def play_game(game_instance)
@game_instance = game_instance
@game_instance.get_game_choice
@game_instance.instantiate_rules
@rules_instance.print_rules
@game_instance.get_match_num
@game_instance.best_of_loop
@game_instance.deliver_results
@game_instance.print_move_array
end
You are passing a Game object itself as a parameter and setting it as an attribute. I don't think you need @game_instance at all. I believe this can be re-written like this and run exactly the same, and this will also eliminate recursively storing the game class in itself.
def play_game
get_game_choice
instantiate_rules
print_rules
get_match_num
best_of_loop
deliver_results
print_move_array
end
Best of N Issue
(https://github.com/hilarysk/rps-project/blob/master/2015-01-29-game-class.rb#L131-L139)
Can I ask exactly what a Best of 6 would look like? If you play 6 games and go 50/50 then you end up with a score of 3 to 3. There would need to be a tie breaker in there in this case (making it a best of 7). Should there be another check in there to make sure the number is odd? Roll it around and see if you agree.
Monster if / elsif
https://github.com/hilarysk/rps-project/blob/master/2015-02-01-psrls-class.rb#L116-L195
That is just a BEAST of an if statement.
While I am confident it gets the job done, it causes a few issues:
- It's hard to read
- It requires a lot of duplicate code between RPS and RPSLS
- It can't be fun to debug either.
I used a nested hash to help solve this problem, but I don't think that's the only method (and I stole that idea from Andrew Strovers.)
https://github.com/Ayolland/2015-01-29-rockpaperscissor/blob/master/rules.rb#L57-L80
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.