Sha256: d79728d683639c4e7f650fe99f84d3699bc4779692adc7002f9d880fa4c21711

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 KB

Contents

# create module that holds all contents for this script
module Constants 
  
  # create 2d list of choices
  protected
  CHOICES = [['r', 'rock'], ['p', 'paper'], ['s', 'scissors']] 

  # define entry to symbol (key to value)
  protected
  NTRY_TO_SYM = { 
    CHOICES[0][0] => :ROCK    , CHOICES[0][1] => :ROCK    ,
    CHOICES[1][0] => :PAPER   , CHOICES[1][1] => :PAPER   ,
    CHOICES[2][0] => :SCISSORS, CHOICES[2][1] => :SCISSORS
  } 

  # define valid entries
  protected
  VALID_ENTRIES = NTRY_TO_SYM.keys 

  # define computer choices
  protected
  COMPUTER_CHOICES = NTRY_TO_SYM.values 

  # create winners 2d list array with format: winning choice, losing choice
  protected
  WINNERS = [
    [:SCISSORS, :PAPER   ], 
    [:PAPER   , :ROCK    ], 
    [:ROCK    , :SCISSORS]
  ] 

  # this will take the original WINNERS array and flip the symbols, thus returning a loss for the user/player
  protected
  LOSERS = WINNERS.map { |winning_choice,losing_choice| [losing_choice,winning_choice] } 

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rpsg-0.3.5 lib/Constants.rb
rpsg-0.3.4 lib/Constants.rb
rpsg-0.3.3 lib/Constants.rb