예제 #1
0
 public void Remove(Polyominoe poly)
 {
     foreach (Squarie square in poly.Squaries)
     {
         Occupied[square.Row, square.Col] = poly.Color;
     }
 }
예제 #2
0
        public bool IsValid(Polyominoe poly)
        {
            bool isValid = true;

            foreach (Squarie square in poly.Squaries)
            {
                if (Occupied[square.Row, square.Col] != Colors.NONE)
                {
                    isValid = false;
                    break;
                }
            }
            return(isValid);
        }
예제 #3
0
        private bool Solve(int colorIx)
        {
            if (colorIx == allPermutations.Count)
            {
                return(true);
            }

            foreach (Polyominoe permutation in allPermutations[colorIx])
            {
                optionStack.Push(permutation);
            }

            Polyominoe current       = optionStack.Pop();
            Colors     currentColor  = current.Color;
            int        layersChanged = 0;

            while (!board.IsValid(current))
            {
                if (optionStack.Count == 0)
                {
                    return(false);
                }
                current = optionStack.Pop();
                if (current.Color != currentColor)
                {
                    layersChanged++;
                    currentColor = current.Color;
                    board.Remove(lastAdded);
                }
            }

            board.Add(current);
            lastAdded = current;

            return(Solve(colorIx - layersChanged + 1));
        }