Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. class SlotMachine
  2. # 0 1 2 3 4
  3. OPTIONS = ["cherry", "seven", "bell", "star", "joker"]
  4.  
  5. def score(reels)
  6. if 3 == reels.uniq.size
  7. return 0
  8. elsif 2 == reels.uniq.size && reels.include?("joker")
  9. # we sort then take the middle one to find out which
  10. # one was the duplicate (see bottom of file)
  11. reel = reels.sort[1]
  12.  
  13. # use the Array#index method to find out the index
  14. # of our reels
  15. return (OPTIONS.index(reel) + 1) * 5
  16. # eg: seven is index 1,
  17. # 1 + 1 is 2,
  18. # 2 * 5 is 10
  19.  
  20. elsif reels.uniq.size == 1
  21. # we grab one from reels, doesn't matter which one
  22. # because they are all the same in this case
  23. reel = reels.sample
  24.  
  25. # use the Array#index method to find out the index
  26. # of our reels
  27. return (OPTIONS.index(reel) + 1) * 10
  28. # eg: joker is index 4,
  29. # 4 + 1 is 5,
  30. # 5 * 10 is 50
  31. end
  32. end
  33. end
  34.  
  35. # indexes 0 1 2
  36. # [b, a, b].sort => [a, b, b]
  37. # [b, b, a].sort => [a, b, b]
  38. # [a, b, b].sort => [a, b, b]
  39. # [b, a, a].sort => [a, a, b]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement