12. Debug the Logic Labyrinth

Used one-hot assignment:

LocationQ7Q6Q5Q4Q3Q2Q1Q0
A00000001
B00000010
C00000100
D00001000
E00010000
F00100000
G01000000
H10000000

Each supplied button conditioner uses two D flip-flops on the FSM clock.

The first stores the current sampled level and the second stores the preceding sample. The one-cycle rising-edge event is:

Lp = L_current·L_previous'
Rp = R_current·R_previous'

Therefore, holding a button HIGH does not repeatedly move the FSM. Define the move decodes from the conditioned pulses:

M0 = Lp'·Rp'     Hold
MR = Lp'·Rp      Right
ML = Lp·Rp'      Left
MS = Lp·Rp       Straight

The move names are useful input decodes because the equations would otherwise repeat the same two-input products.

The state terms, however, use the actual one-hot flip-flop outputs so that each equation maps directly to a circuit:

D0 = Q0·M0 + Q1·ML + Q2·MR
D1 = Q1·M0 + Q0·MR + Q4·ML
D2 = Q2·M0 + (Q0 + Q3 + Q5)·ML
D3 = Q3·M0 + Q0·MS
D4 = Q4·M0 + Q1·MR + Q2·MS + Q3·MR + Q6·ML
D5 = Q5·M0 + Q1·MS + Q2·ML + Q3·MS + Q6·MS
D6 = Q6·M0 + Q4·MS + Q5·MR
D7 = Q7 + Q4·MR + Q5·MS + Q6·MR

FINISH = Q7

The faulty template changes only the terminal-state terms.

Its behavior is equivalent to adding Q7·MS to D0 while qualifying the Q7 hold in D7 with MS'.

Thus H is retained for MS=0, but a straight event makes D7=0 and D0=1, producing the incorrect H → A transition.

The repair removes the Q7·MS entry term from D0 and restores the unconditional Q7 term in D7.

Because correct D7 contains Q7 without a move condition, every future button combination retains H until reset.

All other D-input equations and both supplied button conditioners remain unchanged.