Esempio n. 1
0
        public void FirstMove(int x, int y)
        {
            Random rand = new Random();

            //For any board, take the user's first revealed panel + any neighbors of that panel, and mark them as unavailable for mine placement.
            var neighbors = GetNeighbors(x, y); //Get all neighbors

            neighbors.Add(Panels.First(z => z.X == x && z.Y == y));

            //Select random panels from set which are not excluded
            var mineList  = Panels.Except(neighbors).OrderBy(user => rand.Next());
            var mineSlots = mineList.Take(MineCount).ToList().Select(z => new { z.X, z.Y });

            //Place the mines
            foreach (var mineCoord in mineSlots)
            {
                Panels.Single(panel => panel.X == mineCoord.X && panel.Y == mineCoord.Y).IsMine = true;
            }

            //For every panel which is not a mine, determine and save the adjacent mines.
            foreach (var openPanel in Panels.Where(panel => !panel.IsMine))
            {
                var nearbyPanels = GetNeighbors(openPanel.X, openPanel.Y);
                openPanel.AdjacentMines = nearbyPanels.Count(z => z.IsMine);
            }

            Status = GameStatus.InProgress;
            Stopwatch.Start();
        }
Esempio n. 2
0
        public void FirstMove(int x, int y, Random rand)
        {
            //For any board, take the user's first revealed panel + any neighbors of that panel to X depth, and mark them as unavailable for mine placement.
            var depth     = 0.125 * Width;
            var neighbors = GetNeighbors(x, y, (int)depth); //Get all neighbors to specified depth

            neighbors.Add(GetPanel(x, y));

            //Select random panels from set which are not excluded
            var mineList  = Panels.Except(neighbors).OrderBy(user => rand.Next());
            var mineSlots = mineList.Take(MineCount).ToList().Select(z => new { z.X, z.Y });

            //Place the mines
            foreach (var mineCoord in mineSlots)
            {
                Panels.Single(panel => panel.X == mineCoord.X && panel.Y == mineCoord.Y).IsMine = true;
            }

            //For every panel which is not a mine, determine and save the adjacent mines.
            foreach (var openPanel in Panels.Where(panel => !panel.IsMine))
            {
                var nearbyPanels = GetNeighbors(openPanel.X, openPanel.Y);
                openPanel.AdjacentMines = nearbyPanels.Count(z => z.IsMine);
            }
        }
Esempio n. 3
0
        public void FirstMove(int x, int y, Random rand)
        {
            //Para qualquer painel, pegar o primeiro painél clicado e os vizinhos numa profundidade X
            //E marca-los como indisponíveis para colocar mina
            var depth     = 0.105 * Columns;
            var neighbors = Neighbors(x, y, (int)depth); //Pegar os vizinhos numa certa profundidade

            neighbors.Add(GetPanel(x, y));

            //Selecionar aleatóriamente painéis que não foram revelados
            var emptyList = Panels.Except(neighbors).OrderBy(p => rand.Next());
            //Montar lista com os paineis para colocar minas
            var mineSlots = emptyList.Take(MineCount).ToList().Select(z => new { z.X, z.Y });

            //Colocar as minas
            foreach (var mineCoord in mineSlots)
            {
                Panels.Single(panel => panel.X == mineCoord.X && panel.Y == mineCoord.Y).IsMine = true;
            }

            //Para cada painel que não é mina, determinar e salvar minas adjacentes
            foreach (var openPanel in Panels.Where(panel => !panel.IsMine))
            {
                var nearbyPanels = Neighbors(openPanel.X, openPanel.Y);
                openPanel.AdjacentMines = nearbyPanels.Count(z => z.IsMine);
            }
        }
Esempio n. 4
0
        public void FirstMove(int x, int y)
        {
            Random rand = new Random();

            //For any board, take the user's first revealed panel
            // and any neighbors of that panel, and mark them
            // as unavailable for mine placement.
            var neighbors = GetNeighbors(x, y); //Get all neighbors

            //Add the clicked panel to the "unavailable for mines" group.
            neighbors.Add(Panels.First(z => z.X == x && z.Y == y));

            //Select all panels from set which are available for mine placement.
            //Order them randomly.
            var mineList = Panels.Except(neighbors)
                           .OrderBy(user => rand.Next());

            //Select the first Z random panels.
            var mineSlots = mineList.Take(MineCount)
                            .ToList()
                            .Select(z => new { z.X, z.Y });

            //Place the mines in the randomly selected panels.
            foreach (var mineCoord in mineSlots)
            {
                Panels.Single(panel => panel.X == mineCoord.X &&
                              panel.Y == mineCoord.Y)
                .IsMine = true;
            }

            //For every panel which is not a mine,
            // including the unavailable ones from earlier,
            // determine and save the adjacent mines.
            foreach (var openPanel in Panels.Where(panel => !panel.IsMine))
            {
                var nearbyPanels = GetNeighbors(openPanel.X, openPanel.Y);
                openPanel.AdjacentMines = nearbyPanels.Count(z => z.IsMine);
            }

            //Mark the game as started.
            Status = GameStatus.InProgress;
            Stopwatch.Start();
        }