Exemple #1
0
 public static IList <CrackboxGridItem> CreateGrid()
 {
     return(new List <CrackboxGridItem>
     {
         CrackboxGridItem.Create(0, 4, 12, 3, 1, new List <int> {
             1, 4, 5
         }),
         CrackboxGridItem.Create(1, 5, 13, 0, 2, new List <int> {
             0, 2, 4, 5, 6
         }),
         CrackboxGridItem.Create(2, 6, 14, 1, 3, new List <int> {
             1, 3, 5, 6, 7
         }),
         CrackboxGridItem.Create(3, 7, 15, 2, 0, new List <int> {
             2, 6, 7
         }),
         CrackboxGridItem.Create(4, 8, 0, 7, 5, new List <int> {
             0, 1, 5, 8, 9
         }),
         CrackboxGridItem.Create(5, 9, 1, 4, 6, new List <int> {
             0, 1, 2, 4, 6, 8, 9, 10
         }),
         CrackboxGridItem.Create(6, 10, 2, 5, 7, new List <int> {
             1, 2, 3, 5, 7, 9, 10, 11
         }),
         CrackboxGridItem.Create(7, 11, 3, 6, 4, new List <int> {
             2, 3, 6, 10, 11
         }),
         CrackboxGridItem.Create(8, 12, 4, 11, 9, new List <int> {
             4, 5, 9, 12, 13
         }),
         CrackboxGridItem.Create(9, 13, 5, 8, 10, new List <int> {
             4, 5, 6, 8, 10, 12, 13, 14
         }),
         CrackboxGridItem.Create(10, 14, 6, 9, 11, new List <int> {
             5, 6, 7, 9, 11, 13, 14, 15
         }),
         CrackboxGridItem.Create(11, 15, 7, 10, 8, new List <int> {
             6, 7, 10, 14, 15
         }),
         CrackboxGridItem.Create(12, 0, 8, 15, 13, new List <int> {
             8, 9, 13
         }),
         CrackboxGridItem.Create(13, 1, 9, 12, 14, new List <int> {
             8, 9, 10, 12, 14
         }),
         CrackboxGridItem.Create(14, 2, 10, 13, 15, new List <int> {
             9, 10, 11, 13, 15
         }),
         CrackboxGridItem.Create(15, 3, 11, 14, 12, new List <int> {
             10, 11, 14
         })
     });
 }
Exemple #2
0
 public CrackboxGridItem(CrackboxGridItem item)
 {
     Index          = item.Index;
     UpNeighbour    = item.UpNeighbour;
     DownNeighbour  = item.DownNeighbour;
     LeftNeighbour  = item.LeftNeighbour;
     RightNeighbour = item.RightNeighbour;
     IsBlack        = item.IsBlack;
     Value          = item.Value;
     IsLocked       = item.IsLocked;
     Neighbours     = item.Neighbours;
 }
        private int PlaceItem(CrackboxGridItem[] items, int index)
        {
            CrackboxGridItem next = null;
            var neighbours        = Shuffle(items[index].Neighbours).ToArray();

            foreach (var neighbour in neighbours)
            {
                if (items[neighbour].Value == 0)
                {
                    next = items[neighbour];
                }
                else
                {
                    // That place was already taken.
                    continue;
                }

                var candidates = Shuffle(UtilityMethods.FindCandidates(items[index].Value, this.remaining.ToArray())).ToArray();

                foreach (var candidate in candidates)
                {
                    if (next.Value != 0)
                    {
                        throw new InvalidOperationException(string.Format("Trying to place value in index {0} that already has value.", next.Index));
                    }

                    var nextNeighbours = Shuffle(next.Neighbours);
                    if (CanPlace(candidate, nextNeighbours, items))
                    {
                        this.remaining.Remove(candidate);
                        next.Value = candidate;
                        index      = next.Index;

                        return(index);
                    }
                }
            }

            return(-1);
        }