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); }
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); }
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; }
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; }
public IEnumerable<MineCell> Difference(MinedZone other) => _cells.Except(other._cells);
public bool Intersect(MinedZone other) => other.Id != Id && _cells.Intersect(other._cells).Any();
public IEnumerable <MineCell> Difference(MinedZone other) => _cells.Except(other._cells);