if statement - Rock paper scissors in Ruby -
i have implement small part of rock, paper, scissors game assignment. here code:
class rockpaperscissors # exceptions class can raise: class nosuchstrategyerror < standarderror ; end def self.winner(player1, player2) # code here puts "player1 = " + player1[1] if (player1[1] || player2[1] != 'r') || (player1[1] || player[2] != 'p') || (player1[1] || player2[1] != 's') raise nosuchstrategyerror.new("strategy must 1 of 'r','s','p'") else if player1[1] == player2[1] return player1 elsif (player1[1] == 'r' && player2[1] == 'p') || (player1[1] == 'p' && player2[1] == 's') || (player1[1] == 's' && player2[1] == 'r') return player2 else return player1 end end end def self.tournament_winner(tournament) # code here end end i using rspec test out code , breaks in both of below cases. assuming has check make sure input valid, , though input valid, whatever reason, way doing line if (player1[1] || player2[1] != 'r') || (player1[1] || player[2] != 'p') || (player1[1] || player2[1] != 's') making input fail on every case. how can fix line if input valid, doesn't raise error?
failures: 1) rockpaperscissors game rock breaks scissors [10 points] failure/error: raise nosuchstrategyerror.new("strategy must 1 of 'r','s','p'") rockpaperscissors::nosuchstrategyerror: strategy must 1 of 'r','s','p' # ./lib/rock_paper_scissors.rb:11:in `winner' # ./spec/rock_paper_scissors_spec.rb:10:in `block (3 levels) in <top (required)>' edit: player1 , player2 arrays format ["playername", "move"] move being either r,s or p rock, scissors or paper
Comments
Post a Comment