<?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: Ayush Shah</title>
    <description>The latest articles on DEV Community by Ayush Shah (@ayush_shah_c70f4a911b1b1c).</description>
    <link>https://dev.to/ayush_shah_c70f4a911b1b1c</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%2F4105091%2F5cc23450-1e4e-4052-b052-e654ad1a2357.png</url>
      <title>DEV Community: Ayush Shah</title>
      <link>https://dev.to/ayush_shah_c70f4a911b1b1c</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ayush_shah_c70f4a911b1b1c"/>
    <language>en</language>
    <item>
      <title>I Built an Adaptive Hand Cricket Game Using React, MediaPipe, and TensorFlow.js</title>
      <dc:creator>Ayush Shah</dc:creator>
      <pubDate>Tue, 15 Sep 2026 04:54:14 +0000</pubDate>
      <link>https://dev.to/ayush_shah_c70f4a911b1b1c/i-built-an-adaptive-hand-cricket-game-using-react-mediapipe-and-tensorflowjs-495a</link>
      <guid>https://dev.to/ayush_shah_c70f4a911b1b1c/i-built-an-adaptive-hand-cricket-game-using-react-mediapipe-and-tensorflowjs-495a</guid>
      <description>&lt;p&gt;I wanted to build something fun, not another CRUD app or chatbot.&lt;/p&gt;

&lt;p&gt;So I built &lt;strong&gt;Adaptive Hand Cricket&lt;/strong&gt;: a browser-based game where you play hand cricket through your webcam, your hand gestures are recognized in real time, and the computer gradually becomes harder by combining randomness, live gesture reading, and machine learning.&lt;/p&gt;

&lt;h2&gt;
  
  
  How it works
&lt;/h2&gt;

&lt;p&gt;The game uses:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;React + Vite&lt;/strong&gt; for the frontend&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;MediaPipe&lt;/strong&gt; for real-time hand landmark detection&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;TensorFlow.js&lt;/strong&gt; for learning player patterns&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Webcam input&lt;/strong&gt; through &lt;code&gt;getUserMedia&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;localStorage&lt;/strong&gt; to remember previous batting behavior&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The supported gestures are:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1 -&amp;gt; index
2 -&amp;gt; index + middle
3 -&amp;gt; index + middle + ring
4 -&amp;gt; index + middle + ring + pinky
5 -&amp;gt; all fingers
6 -&amp;gt; thumb
7 -&amp;gt; thumb + index
8 -&amp;gt; thumb + index + middle
9 -&amp;gt; thumb + index + middle + ring

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead of simply counting fingers, I classify the exact finger pattern.&lt;/p&gt;

&lt;h2&gt;
  
  
  The game loop
&lt;/h2&gt;

&lt;p&gt;Every delivery follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Computer commits to a move
        ↓
        3
        2
        1
        ↓
      SHOW
        ↓
Human gesture is locked
        ↓
Both moves are revealed
        ↓
Score / wicket is calculated
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This keeps the reveal synchronized like actual hand cricket.&lt;/p&gt;

&lt;h2&gt;
  
  
  Making the opponent adaptive
&lt;/h2&gt;

&lt;p&gt;A completely random computer got boring quickly, so I added three decision strategies:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;RANDOM
ML
PEEK
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Difficulty automatically increases with the player's score:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0-39   -&amp;gt; EASY
40-99  -&amp;gt; MEDIUM
100+   -&amp;gt; HARD
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each level changes how often the opponent uses each strategy.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;EASY&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;peekChance&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;mlChance&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;randomChance&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.60&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Peek strategy
&lt;/h2&gt;

&lt;p&gt;Humans often form their gesture before the countdown reaches zero.&lt;/p&gt;

&lt;p&gt;On some deliveries, the computer is secretly allowed to inspect the gesture at a random point during:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;3... 2... 1...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If it gets a valid reading, it can use that number.&lt;/p&gt;

&lt;p&gt;Slightly evil. Very effective.&lt;/p&gt;

&lt;h2&gt;
  
  
  Learning player patterns
&lt;/h2&gt;

&lt;p&gt;The more interesting strategy uses TensorFlow.js.&lt;/p&gt;

&lt;p&gt;Every batting move is stored:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;7, 4, 2, 7, 8, 4, 7...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The model learns from:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the player's last 5 moves&lt;/li&gt;
&lt;li&gt;overall frequency of numbers 1-9&lt;/li&gt;
&lt;li&gt;recent frequency of numbers 1-9&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This produces &lt;strong&gt;63 input features&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The network is intentionally small:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;63 inputs
   ↓
Dense 64
   ↓
Dense 32
   ↓
9-way Softmax
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output might look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;4 -&amp;gt; 18%
7 -&amp;gt; 42%
8 -&amp;gt; 12%
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So the model predicts &lt;strong&gt;7&lt;/strong&gt; as the player's next move.&lt;/p&gt;

&lt;p&gt;Training starts after enough moves have been collected and retrains periodically rather than after every ball.&lt;/p&gt;

&lt;h2&gt;
  
  
  What surprised me
&lt;/h2&gt;

&lt;p&gt;The machine learning was not actually the hardest part.&lt;/p&gt;

&lt;p&gt;The trickier problems were:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;thumb detection across different hand orientations&lt;/li&gt;
&lt;li&gt;synchronizing countdown and capture timing&lt;/li&gt;
&lt;li&gt;preventing invalid camera frames from affecting gameplay&lt;/li&gt;
&lt;li&gt;managing game transitions cleanly&lt;/li&gt;
&lt;li&gt;keeping browser ML from interfering with real-time video processing&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A small game ended up touching &lt;strong&gt;computer vision, React state management, probability, feature engineering, browser ML, and real-time interaction design&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'd improve next
&lt;/h2&gt;

&lt;p&gt;I'd like to add:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a short multi-frame voting window instead of using one camera frame&lt;/li&gt;
&lt;li&gt;proper ML-vs-random prediction accuracy tracking&lt;/li&gt;
&lt;li&gt;player profiles&lt;/li&gt;
&lt;li&gt;a comparison between neural networks and simpler approaches like Markov chains&lt;/li&gt;
&lt;li&gt;better gesture classification for rotated hands&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Tech Stack
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;React
Vite
MediaPipe Tasks Vision
TensorFlow.js
WebRTC / getUserMedia
localStorage
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It started as a simple question:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Can I play hand cricket against my webcam?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;It turned into:&lt;/p&gt;

&lt;p&gt;Can the computer learn how predictable I am?&lt;/p&gt;

</description>
      <category>gamedev</category>
      <category>javascript</category>
      <category>machinelearning</category>
      <category>react</category>
    </item>
  </channel>
</rss>
