<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: yulingg zhang</title>
    <description>The latest articles on DEV Community by yulingg zhang (@yulingg_zhang_dfbce7a345a).</description>
    <link>https://dev.to/yulingg_zhang_dfbce7a345a</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4112509%2Ff1b8ba84-b1bf-428a-8f3d-fe385fd89606.png</url>
      <title>DEV Community: yulingg zhang</title>
      <link>https://dev.to/yulingg_zhang_dfbce7a345a</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/yulingg_zhang_dfbce7a345a"/>
    <language>en</language>
    <item>
      <title>Testing a deterministic browser game: seeds, replay and invalid state</title>
      <dc:creator>yulingg zhang</dc:creator>
      <pubDate>Sun, 06 Sep 2026 15:38:25 +0000</pubDate>
      <link>https://dev.to/yulingg_zhang_dfbce7a345a/testing-a-deterministic-browser-game-seeds-replay-and-invalid-state-12ob</link>
      <guid>https://dev.to/yulingg_zhang_dfbce7a345a/testing-a-deterministic-browser-game-seeds-replay-and-invalid-state-12ob</guid>
      <description>&lt;p&gt;A random game is easier to debug when the same inputs produce the same result. In HoopTrait, a browser basketball project, the Lab mode combines eight selected traits and generates a fictional career. The interesting engineering problem is keeping replay, sharing and validation consistent.&lt;/p&gt;

&lt;p&gt;This is a technical development note, not a claim that a game score predicts an athlete's real performance.&lt;/p&gt;

&lt;h2&gt;
  
  
  Store the decisions, not just the result
&lt;/h2&gt;

&lt;p&gt;The Lab state records a seed, a dataset version and an ordered list of actions. An action is a pick or a reroll. Replaying those actions reconstructs the build.&lt;/p&gt;

&lt;p&gt;A seed alone is not a complete replay contract: changing the player pool or its order can change a seeded draw. A dataset version therefore matters alongside the random seed. For a future release, the same principle should apply to changes in the rules themselves.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test invariants across many runs
&lt;/h2&gt;

&lt;p&gt;The Lab test suite iterates through 1,000 seeds. For each seed it shuffles the order of the eight skills, uses the two allowed rerolls, and completes a build. It checks that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Eight distinct players were selected.&lt;/li&gt;
&lt;li&gt;All eight traits are present, and no player remains to be drawn after completion.&lt;/li&gt;
&lt;li&gt;The overall game score stays between 0 and 99 and matches the shared rating function.&lt;/li&gt;
&lt;li&gt;Packing and unpacking the share state returns the original state.&lt;/li&gt;
&lt;li&gt;Recomputing the fictional career returns the same output.&lt;/li&gt;
&lt;li&gt;The ten simulated seasons sum to the displayed career earnings.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Those assertions catch different problems. A stable score does not prove that a shared link reproduces the same selections. A complete build does not prove that its season totals add up.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reject impossible histories
&lt;/h2&gt;

&lt;p&gt;A share payload is untrusted input, even in a client-side game. Negative or fractional seeds, duplicate skill picks, a third reroll, unknown action types, a mismatched dataset version and actions after completion are rejected.&lt;/p&gt;

&lt;p&gt;The tests also cover malformed encoded payloads and unexpected fields. Local state is useful for a casual game, but it is not an anti-cheat system. A competitive leaderboard would need a separate trust model.&lt;/p&gt;

&lt;h2&gt;
  
  
  Make daily challenges explicit
&lt;/h2&gt;

&lt;p&gt;Daily challenges use a validated UTC date to derive the seed. The tests reject impossible dates and check that changing the date without the matching seed invalidates the state. This avoids treating a player's local midnight as a universal boundary.&lt;/p&gt;

&lt;h2&gt;
  
  
  What these tests do not establish
&lt;/h2&gt;

&lt;p&gt;Determinism proves repeatability, not realism. The career is an entertainment simulation, not a forecast. Unit tests also do not replace mobile interaction testing, data-quality review or permission checks for third-party assets.&lt;/p&gt;

&lt;p&gt;Project reference: &lt;a href="https://hooptrait.app/?utm_source=devto&amp;amp;utm_medium=community&amp;amp;utm_campaign=lab_testing_note" rel="noopener noreferrer"&gt;HoopTrait&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;For developers working on small games: what would you version first when introducing a new scoring model—the replay format, the dataset, or both?&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Drafted with AI assistance and checked against the project's Lab test source.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>debugging</category>
      <category>gamedev</category>
      <category>softwareengineering</category>
      <category>testing</category>
    </item>
  </channel>
</rss>
