Advance the rotors

This commit is contained in:
Eryn Wells 2015-07-19 08:45:18 -07:00
parent b5cac3d137
commit b6b96ed770

View file

@ -44,6 +44,17 @@ class Machine {
}
private func advanceRotors() {
var shouldAdvance = true // Always advance the first rotor
for rotor in rotors.reverse() {
if shouldAdvance {
rotor.advance()
}
// Advance the next rotor if this rotor is in the notch position.
if let notch = rotor.notch {
shouldAdvance = rotor.position == notch
} else {
shouldAdvance = false
}
}
}
}