easy 10 pts Solved

Reaction Game Scorer

Score a simple reflex game: a light comes on, the player presses a button, and the circuit measures how many cycles it took — flagging jumping the gun or dozing off.

Verilog problems / Fun & Games

What you must build

Score a simple reflex game: a light comes on, the player presses a button, and the circuit measures how many cycles it took — flagging jumping the gun or dozing off.

Engineers use “Reaction Game Scorer” as a building block in fun & games. Interviewers ask for the same ports and the same corner cases this judge covers. Completing it in the browser is the same skill as writing synthesizable RTL at work, minus the EDA license.

Concept: A 3-state FSM (idle → armed → done) times the gap between stimulus and button: pressing before the stimulus is too_early, pressing within the window gives a valid reaction_time, and letting a counter hit a fixed threshold without a press sets too_slow. That timeout check is the easy piece to forget — an implementation that only reacts to button in the armed state and never checks whether the counter has run out will simply wait forever for a press that never comes, silently dropping the entire "too slow" case instead of ever flagging it.

Port contract

The judge instantiates exactly these ports. Extra ports or a different module name fail to elaborate.

NameDirWidthDescription
clkinput1Clock
rstinput1Sync active-high reset, returns to idle
stimulusinput1Pulses for 1 cycle: the light turns on
buttoninput11 while the player is pressing the button
reaction_timeoutput4Cycles between stimulus and a valid press
too_slowoutput11 if 5 cycles pass after stimulus with no press
too_earlyoutput11 if the button is pressed before any stimulus
validoutput11 once a valid in-window press has been scored

How to approach this kata

This is a hard kata. Sketch the state bits and the illegal overlaps (full/empty, wrap, simultaneous enable) on paper first. A design that “usually works” in your head will fail a directed corner in the hidden tests.

Hidden tests instantiate top_module, drive the ports, and compare every sample against a golden model. They do not grade coding style. They do grade X/Z, off-by-one counters, and ignoring enables. Sign in only when you want the run saved on the leaderboard — the specification below is public.

Starter shape

Copy this skeleton into the editor (or press Reset starter). Fill the body; do not rename the module.

module top_module(
  input  clk,
  input  rst,
  input  stimulus,
  input  button,
  output reg [3:0] reaction_time,
  output reg too_slow,
  output reg too_early,
  output reg valid
);

  // Your code here — idle: too_early if button pressed with no stimulus yet, else move to armed on stimulus.

Why this shows up in interviews

Reaction Game Scorer sits under Fun & Games (sequential, fsm, game-logic). Concept: A 3-state FSM (idle → armed → done) times the gap between stimulus and button : pressing before the stimulus is too_early , pressing within the window gives a valid reaction_time, and letting a counter hit a fixed threshold without a press sets too_slow . That timeout check is the easy piece to forget — an implementation that only reacts to button in the armed state and never checks whether the counter has run out will simply wait forever for a press that never comes, silently dropping the entire "too slow" case instead of ever flagging it.

A passing solution is synthesizable intent: no delays in the DUT, no initial blocks inside top_module, and no reference to testbench tasks. Use blocking assignments only in combinational always blocks; use non-blocking for registers clocked by clk.

Related problems

  • Rock Paper Scissors Lizard Spock — Judge a round of the 5-way expanded rock-paper-scissors from The Big Bang Theory — each move beats exactly two of the other four, so the usual 3-way rule table isn't enough.
  • Magic 8-Ball Fortune Teller — Give a "random-feeling" fortune-teller answer on every shake using a self-advancing 3-bit LFSR — a tiny, deterministic taste of pseudo-randomness in hardware.
  • Hot Potato Token Passer — Pass a token around a 4-player ring every cycle until a buzzer sounds — whoever's holding it when the music stops loses, and the game freezes there.
  • Space Invaders Collision Detector — Detect whether a bullet hits an alien: a classic range-overlap check dressed up as retro arcade collision logic.

FAQ

What does this problem require?

What does the Reaction Game Scorer problem ask for? Score a simple reflex game: a light comes on, the player presses a button, and the circuit measures how many cycles it took — flagging jumping the gun or dozing off. Implement it as Verilog module top_module with the listed ports.

Combinational or sequential?

Is Reaction Game Scorer combinational or sequential? Tags: sequential, fsm, game-logic. Follow the clock/reset ports if they appear in the table; if there is no clock, use continuous assignment or combinational always @(*).

How does the auto-grader work?

How is Reaction Game Scorer graded? A hidden SystemVerilog/Verilog testbench in the EcrioniX judge simulates your module in the browser. You pass when every directed vector matches, including the waveform contract shown on this page.

Write a module named top_module matching the ports below exactly.
Expected waveform
Your solution
Judge output
// Output appears after you run tests.