Advance the rotors
This commit is contained in:
parent
b5cac3d137
commit
b6b96ed770
1 changed files with 12 additions and 1 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue