For a Valve networked-game mock, demonstrate how a client handles packets delivered late or twice. Drawing a timeline is worthwhile because the failure is visible frame by frame.
What to prepare for Valve
Valve advertises game development software engineering and Steamworks documents networking interfaces. Use the exercise as an original mock for networked systems. A separate team might prioritize tools or rendering, which is a reason to review the posting before choosing follow-ups. Valve game development SWE role, Steamworks networking overview
Apply the newest snapshot to a game client
Each item has an increasing integer server tick and complete state. Packets can arrive out of order, and duplicate packets at the same tick carry the same state. Apply only snapshots newer than the last accepted tick. Return the accepted ticks.
def applied(snapshots):
latest, out = (-1, [])
for tick, state in snapshots:
if tick > latest:
latest = tick
out.append(tick)
return out
assert applied([(9, 'a'), (11, 'b'), (10, 'late'), (11, 'b'), (13, 'd')]) == [9, 11, 13]
assert applied([(0, {})]) == [0]
assert applied([]) == []
Track the greatest applied tick. A single O(n) walk accepts a strictly increasing subsequence, costing O(1) additional state apart from output. The contract depends on complete snapshots. Deltas that reference an older state need ordered delivery or an explicit base and recovery snapshot.
Walk through a boundary case
Arrive at tick 9, then receive a full snapshot at 11 and a late packet at 10. The full snapshot at 11 wins and the late duplicate must have no effect. Change the packet at 11 to a delta requiring base 10. The client cannot reconstruct it from 9 and should resync. Put both scenarios in the same replay test to ensure the transport type controls the policy.
Reject deltas whose base was never applied
Model the delta header separately from the state value. A wrong base requests a fresh snapshot. An out-of-order delta whose target was already applied can be dropped. Test a target newer than the current state with a missing base before showing a valid update.
def delta(current, base, target):
if target <= current:
return ('drop', current)
if current != base:
return ('resync', current)
return ('apply', target)
assert delta(9, 10, 11) == ('resync', 9)
assert delta(11, 9, 10) == ('drop', 11)
assert delta(11, 11, 12) == ('apply', 12)
Design and debugging follow-up
Sequence 11 is received before 10, so a complete snapshot at 11 can replace displayed state. If 11 merely specifies a change relative to 10, applying it to 9 can corrupt state. Include a base revision on a delta and ask for a full snapshot on mismatch. Add a replay fixture with loss, duplication and reordering.
What to bring to a mock interview
Bring a debugging story with a simulation-to-render boundary. Show the server tick, local input tick and visible frame. Explain whether interpolation, pending local input or an old server snapshot produced the visual error.