Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class SlotMachine
- # 0 1 2 3 4
- OPTIONS = ["cherry", "seven", "bell", "star", "joker"]
- def score(reels)
- if 3 == reels.uniq.size
- return 0
- elsif 2 == reels.uniq.size && reels.include?("joker")
- # we sort then take the middle one to find out which
- # one was the duplicate (see bottom of file)
- reel = reels.sort[1]
- # use the Array#index method to find out the index
- # of our reels
- return (OPTIONS.index(reel) + 1) * 5
- # eg: seven is index 1,
- # 1 + 1 is 2,
- # 2 * 5 is 10
- elsif reels.uniq.size == 1
- # we grab one from reels, doesn't matter which one
- # because they are all the same in this case
- reel = reels.sample
- # use the Array#index method to find out the index
- # of our reels
- return (OPTIONS.index(reel) + 1) * 10
- # eg: joker is index 4,
- # 4 + 1 is 5,
- # 5 * 10 is 50
- end
- end
- end
- # indexes 0 1 2
- # [b, a, b].sort => [a, b, b]
- # [b, b, a].sort => [a, b, b]
- # [a, b, b].sort => [a, b, b]
- # [b, a, a].sort => [a, a, b]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement