title: Algorithm C# unity chess game
body: <p>I'm making a 2D chess game using Unity. </p>
  
  <p>I'm writing the code that tells if the piece can move to this position or not.</p>
  
  <p>Here is the explanations about how I did it:</p>
  
  <ul>
  <li>There is a "wallpaper" representing the board.</li>
  <li>On each square of the "wallpaper", I put an other square with desactivated mesh renderer.</li>
  <li>When the player select a square, if there is a piece on this position, I activate the mesh renderers of all squares where the piece can go.</li>
  <li>All squares are stored in a simple array I use to determine possible positions.</li>
  </ul>
  
  <p>With pawns, no problem, it works perfectly, but with rooks or knights, the mouvement is more complicated and I have issues doing this.</p>
  
  <p>here I will work with knights.</p>
  
  <p>When it is in the center of the board, no problem: <a href="http://prntscr.com/crcogo" rel="nofollow">http://prntscr.com/crcogo</a></p>
  
  <p>But when I'm on a side of the board, well, check by yourself: <a href="http://prntscr.com/crcozu" rel="nofollow">http://prntscr.com/crcozu</a></p>
  
  <p>Here is the code:</p>
  
  <pre><code>case "White_Knight(Clone)_0":
                  int Index_Knight_1 = Array.IndexOf(Board, Square_Selected);
                  // Les cases en +
                  if (Index_Knight_1 + 6 &lt;= 64 )
                  {
                      Board[Index_Knight_1 + 6].GetComponent&lt;MeshRenderer&gt;().enabled = true;
                  }
                  if (Index_Knight_1 + 10 &lt;= 64)
                  {
                      Board[Index_Knight_1 + 10].GetComponent&lt;MeshRenderer&gt;().enabled = true;
                  }
                  if (Index_Knight_1 + 15 &lt;= 64)
                  {
                      Board[Index_Knight_1 + 15].GetComponent&lt;MeshRenderer&gt;().enabled = true;
                  }
                  if (Index_Knight_1 + 17 &lt;= 64)
                  {
                      Board[Index_Knight_1 + 17].GetComponent&lt;MeshRenderer&gt;().enabled = true;
                  }
                  // les cases en -
                  if (Index_Knight_1 - 6 &gt;= 0)
                  {
                      Board[Index_Knight_1 - 6].GetComponent&lt;MeshRenderer&gt;().enabled = true;
                  }
                  if (Index_Knight_1 - 10 &gt;= 0)
                  {
                      Board[Index_Knight_1 - 10].GetComponent&lt;MeshRenderer&gt;().enabled = true;
                  }
                  if (Index_Knight_1 - 15 &gt;= 0)
                  {
                      Board[Index_Knight_1 - 15].GetComponent&lt;MeshRenderer&gt;().enabled = true;
                  }
                  if (Index_Knight_1 - 17 &gt;= 0)
                  {
                      Board[Index_Knight_1 - 17].GetComponent&lt;MeshRenderer&gt;().enabled = true;
                  }
  </code></pre>
  
  <p>I thnik I don't use the correct way to do this, but I would like to script it myself without taking pieces of code there or there.</p>
  
  <p>In this case, I thought about using multiples of eight, but I'm stuck here :D</p>
  
  <p>Could someone give me a piece of an advice?</p>
  
  <p>Thanks!</p>
  
  <p>Ho, I know it should not be "64" in the conditions, but 63, just saw it.</p>