title: Building a game of dominoes - modelling and laying out
body: <p>I started to make a simple domino game. (the one where you place the tiles with same numbers next to each other). I started modelling it and i seem to have landed in a tough spot now. Im modelling the actual domino (called "bone"):</p>
  
  <pre><code>namespace DominoCore
  {
      public enum BoneOrientation { Horizontal, Vertical }
  
      public interface IBone
      {
          int FirstValue { get; }
          int SecondValue { get; }
          BoneOrientation Orientation { get; set; }
      }
  }
  </code></pre>
  
  <p>After this type I need to lay them out on the playing field. I made a playing field with square tiles in it:</p>
  
  <pre><code>namespace DominoCore
  {
      public interface IField
      {
          IPlayer FirstPlayer { get; }
          IPlayer SecondPlayer { get; }
          IBoneYard BoneYard { get; }
          List&lt;ITile&gt; Tiles { get; }
  
          void PlaceBone(IPlayer player, IBone bone, int startX);
      }
  }
  </code></pre>
  
  <p>The playing field has two players and a Boneyard (the dominoes not given to players) and then a list of tiles.</p>
  
  <pre><code>namespace DominoCore
  {
      public enum BoneExpandDirection { Up, Down, Right, Left }
  
      public interface ITile
      {
          int X { get; }
          int Y { get; }
          IBone Bone { get; set; }
          BoneExpandDirection ExpandDirection { get; set; }
      }
  }
  </code></pre>
  
  <p>Now comes my problems:, </p>
  
  <ol>
  <li>If I get a domino (Bone) with the value of (1,3) and want to place it on the field, how do I represent the location of where it has been placed (e.g. tile with coordinate 5,5) </li>
  <li>Does the domino tile then expand to the right from 5,5? </li>
  <li>What if I turn it 90 degrees, then the orientation is upward, turn it 180 degrees then its to the left - and the value is now (3,1). </li>
  <li>How do I make this distinction between layout, domino and tile? </li>
  </ol>
  
  <p>I guess at some point I need to figure out, when a player places a tile - to calculate if its legal (search the field for tiles/bones). The various placements of the same domino /bone is shown in image below.</p>
  
  <p>The next problem is laying out the dominos/bones, I am thinking about making a grid, but that doesnt fit with placing a tile "across" (perpendicular) other dominos/bones. When placing a tile I'm back at the first problem: how to validate it its legal? how to find the domino it borders with?</p>
  
  <p>Hope this is making sense - I find it hard to describe the layout and the validation problem im facing.</p>
  
  <p><img src="https://i.stack.imgur.com/gnWM5.jpg" alt="Various domino scenarios"></p>
  
  <p><strong>EDIT</strong>
  When starting the game the Bones in play are:</p>
  
  <pre><code>[6,6] [6,5] [6,4] [6,3] [6,2] [6,1] [6,0]
  [5,5] [5,4] [5,3] [5,2] [5,1] [5,0]
  [4,4] [4,3] [4,2] [4,1] [4,0] 
  [3,3] [3,2] [3,1] [3,0]
  [2,2] [2,1] [2,0]
  [1,1] [1,0]
  [0,0]
  </code></pre>
  
  <p>Each tile can be reversed this means that tile [6,3] can also be flipped 180 degrees and used as [3,6]</p>