class MasterMind::Tobi::GameLogic
Constants
- ADVANCED
- COLORS
- SEQUENCE_TYPES
Attributes
color_array[R]
length[R]
level[R]
sequence_type[R]
Public Class Methods
check_input(sequence, input)
click to toggle source
# File lib/mastermind/tobi/logic.rb, line 21 def self.check_input(sequence, input) verify_values(input.split(''), sequence, sequence[0..-1]) end
new(level)
click to toggle source
# File lib/mastermind/tobi/logic.rb, line 10 def initialize(level) @level = level @color_array = COLORS[level] @length = color_array.length @sequence_type = SEQUENCE_TYPES[level] end
verify_values(split_input, sequence, sequence_copy)
click to toggle source
# File lib/mastermind/tobi/logic.rb, line 25 def self.verify_values(split_input, sequence, sequence_copy) result_values = {correct_elements: 0, correct_position: 0} split_input.each_with_index{ |element, index| result_values[:correct_position] += 1 if split_input[index] == sequence[index] # if element in correct position if sequence_copy.include?(element) result_values[:correct_elements] += 1 sequence_copy.delete_at(sequence_copy.index(element)) # if in sequence, delete first occurrence so as to counter duplicates end } result_values end
Public Instance Methods
generate_sequence()
click to toggle source
# File lib/mastermind/tobi/logic.rb, line 17 def generate_sequence (color_array * (rand() * 1000).to_i).shuffle[0...color_array.length] # generate random combination of r/g/b/y end