Exemple #1
0
        public (List <int> codes, int score) Solve(TileGrid grid)
        {
            int gridCode = 0;

            for (int i = 0; i < Size * Size; i++)
            {
                if (grid.State[i % Size, i / Size])
                {
                    gridCode ^= 1 << i;
                }
            }

            var solution = Solve(gridCode);

            for (int i = 0; i < Size * Size; i++)
            {
                if ((solution.codes[0] & 1 << i) != 0)
                {
                    grid.Imbue(i % Size, i / Size);
                }
            }
            return(solution);
        }
        private void InitializeTileGrid()
        {
            grid = new TileGrid(GridSize);
            uniformGrid.Children.Clear();
            buttons = new ContentControl[GridSize, GridSize];
            for (int y = GridSize - 1; y >= 0; y--)
            {
                for (int x = 0; x < GridSize; x++)
                {
                    var button = new ContentControl
                    {
                        Template = (ControlTemplate)System.Windows.Application.Current.FindResource("WhiteTile")
                    };
                    int xTemp = x, yTemp = y;
                    button.MouseDown += (object sender, MouseButtonEventArgs e) =>
                    {
                        switch (e.ChangedButton)
                        {
                        case MouseButton.Left:
                            Flip(xTemp, yTemp);
                            break;

                        case MouseButton.Right:
                            FlipSingle(xTemp, yTemp);
                            break;

                        default:
                            break;
                        }
                    };
                    buttons[x, y] = button;
                    uniformGrid.Children.Add(button);
                }
            }
            solveButton.IsEnabled = GridSize <= 5;
        }