Example #1
0
        private ICollection <MinedZone> GetMinedZones(MineCell[] uncoveredCells)
        {
            var minedZonesById = new Dictionary <string, MinedZone>();

            foreach (var cell in uncoveredCells)
            {
                var neighbours        = _mineField.GetNeighbours(cell).ToArray();
                var flaggedNeighbours = neighbours.FilterByVisibleState(MineState.Flagged).ToArray();
                var coveredNeighbours = neighbours.FilterByVisibleState(MineState.Covered).ToArray();
                var remainingCount    = cell.NeighbourhoodMineCount - flaggedNeighbours.Length;
                if (remainingCount > 0 && remainingCount < coveredNeighbours.Length)
                {
                    var zone = new MinedZone(remainingCount, coveredNeighbours);
                    minedZonesById[zone.Id] = zone;
                }
            }

            return(minedZonesById.Values);
        }
Example #2
0
        private bool PlayHardMoves(MinedZone zone, MinedZone other, bool returnOnFirstAction)
        {
            var cellsNotInOtherZone  = zone.Difference(other).ToArray();
            var mineCountInOtherZone = zone.MineCount - cellsNotInOtherZone.Length;

            if (mineCountInOtherZone == other.MineCount && cellsNotInOtherZone.Length > 0)
            {
                foreach (var cell in cellsNotInOtherZone)
                {
                    cell.HasFlag = true;
                    if (returnOnFirstAction)
                    {
                        break;
                    }
                }

                return(true);
            }

            var otherCellsNotInZone  = other.Difference(zone).ToArray();
            var otherMineCountInZone = other.MineCount - otherCellsNotInZone.Length;

            if (otherMineCountInZone == zone.MineCount && cellsNotInOtherZone.Length > 0)
            {
                foreach (var cell in cellsNotInOtherZone)
                {
                    _mineField.UncoverCell(cell);
                    if (returnOnFirstAction)
                    {
                        break;
                    }
                }

                return(true);
            }

            return(false);
        }
Example #3
0
        private bool PlayHardMoves(MinedZone zone, MinedZone other, bool returnOnFirstAction)
        {
            var cellsNotInOtherZone = zone.Difference(other).ToArray();
            var mineCountInOtherZone = zone.MineCount - cellsNotInOtherZone.Length;
            if (mineCountInOtherZone == other.MineCount && cellsNotInOtherZone.Length > 0)
            {
                foreach (var cell in cellsNotInOtherZone)
                {
                    cell.HasFlag = true;
                    if (returnOnFirstAction)
                    {
                        break;
                    }
                }

                return true;
            }

            var otherCellsNotInZone = other.Difference(zone).ToArray();
            var otherMineCountInZone = other.MineCount - otherCellsNotInZone.Length;
            if (otherMineCountInZone == zone.MineCount && cellsNotInOtherZone.Length > 0)
            {
                foreach (var cell in cellsNotInOtherZone)
                {
                    _mineField.UncoverCell(cell);
                    if (returnOnFirstAction)
                    {
                        break;
                    }
                }

                return true;
            }

            return false;
        }
Example #4
0
        private ICollection<MinedZone> GetMinedZones(MineCell[] uncoveredCells)
        {
            var minedZonesById = new Dictionary<string, MinedZone>();
            foreach (var cell in uncoveredCells)
            {
                var neighbours = _mineField.GetNeighbours(cell).ToArray();
                var flaggedNeighbours = neighbours.FilterByVisibleState(MineState.Flagged).ToArray();
                var coveredNeighbours = neighbours.FilterByVisibleState(MineState.Covered).ToArray();
                var remainingCount = cell.NeighbourhoodMineCount - flaggedNeighbours.Length;
                if (remainingCount > 0 && remainingCount < coveredNeighbours.Length)
                {
                    var zone = new MinedZone(remainingCount, coveredNeighbours);
                    minedZonesById[zone.Id] = zone;
                }
            }

            return minedZonesById.Values;
        }
Example #5
0
 public IEnumerable<MineCell> Difference(MinedZone other) => _cells.Except(other._cells);
Example #6
0
 public bool Intersect(MinedZone other) => other.Id != Id && _cells.Intersect(other._cells).Any();
Example #7
0
 public IEnumerable <MineCell> Difference(MinedZone other) => _cells.Except(other._cells);
Example #8
0
 public bool Intersect(MinedZone other) => other.Id != Id && _cells.Intersect(other._cells).Any();