public IEnumerable <Choice> GetChoices(IMineGame mineGame, MineDetector mineDetector) { var result = new MineArray <double>(mineGame.LineCount, mineGame.ColumnCount); foreach (var coordinate in mineGame.AllCells()) { var contant = mineGame.NeighboursMineCountAt(coordinate); if (contant == null) { continue; } result[coordinate] = double.PositiveInfinity; var neighbours = mineGame.GetNeighbours(coordinate).ToList(); var unclickedNeighbours = neighbours.Where(coords => mineGame.NeighboursMineCountAt(coords) == null).ToList(); if (unclickedNeighbours.Count == 0) { continue; } var score = contant.Value / unclickedNeighbours.Count; foreach (var c in unclickedNeighbours) { result[c] += score; } } var bestScore = result.Min(); var candidates = mineGame.AllCells().Where(coords => Equals(result[coords], bestScore)); return(candidates.Select(c => new Choice(c, 0.2)).ToList()); }
public MineDetector(IMineGame mineGame) { _mines = new MineArray <bool>(mineGame.LineCount, mineGame.ColumnCount); foreach (var point in mineGame.AllCells()) { var undigedNeighbours = mineGame.GetNeighbours(point) .Where(p => mineGame.NeighboursMineCountAt(p) == null).ToList(); if (undigedNeighbours.Count == mineGame.NeighboursMineCountAt(point)) { foreach (var undigedNeighbour in undigedNeighbours) { _mines[undigedNeighbour] = true; } } } }
private static IEnumerable <Choice> FindSafePlace(IMineGame mineGame, MineDetector mineDetector) { foreach (var point in mineGame.AllCells()) { var neighbours = mineGame.GetNeighbours(point).ToList(); var minesCount1 = neighbours.Count(mineDetector.IsSureAMine); var minesCount2 = mineGame.NeighboursMineCountAt(point); if (minesCount1 == minesCount2) { foreach (var coordinate in neighbours.Where( p => mineGame.NeighboursMineCountAt(p) == null && !mineDetector.IsSureAMine(p))) { yield return(new Choice(coordinate, 0)); } } } }