title: Puzzle matching game algorithm
body: <p>I want to make a puzzle matching game, but I have a problem with the algorithm.</p>
  
  <p>Here's my game - a board, e.g. 4x4 - 16 cells containing 8 pairs of letters. The letters are scrambled.</p>
  
  <p>The requirements are:</p>
  
  <ul>
  <li>Pairs of letters that aren't blocked by other letters should be joined together</li>
  <li>After a pair of letters join, it will disappear</li>
  <li>You should choose the nearest possible pair of letters to join first</li>
  </ul>
  
  <p>Example image:</p>
  
  <p><img src="https://i.stack.imgur.com/j849p.jpg" alt=""></p>
  
  <p>What is the most effective algorithm should I use <strong>to match a pair of alphabet</strong>?</p>