// FSM for a Red Light, Green Light game with two spaces. // Moving during a red light puts the player back at the start. // Inputs: // - M: player tries to move forward or not // - L: state of the light (1 = green, 0 = red) // Outputs: // - W: player win (if successfully reached second space) module light_game (input logic clk, reset, M, L, output logic W); // State Encodings and Variables enum logic [1:0] {Start, Mid, Win} ps, ns; // Next State Logic (ns) always_comb case (ps) Start: ns = (L & M) ? Mid : Start; Mid: ns = (L & M) ? Win : (M ? Start : Mid); Win: ns = M ? Start : Win; endcase // Output Logic assign W = (ns == Win); // alt: ((ps == Mid) & L & M) | // ((ps == Win) & ~M) // State Update Logic (ps) always_ff @(posedge clk) if (reset) ps <= Start; else ps <= ns; endmodule // light_game