| | | 1 | | using System; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | using System.Linq; |
| | | 4 | | using System.Security.Cryptography; |
| | | 5 | | |
| | | 6 | | namespace MineSweeper |
| | | 7 | | { |
| | | 8 | | public static class MineFieldHelper |
| | | 9 | | { |
| | | 10 | | public static IEnumerable<(int X, int Y)> RandomIndexGenerator(int width, int height) |
| | 1 | 11 | | { |
| | 3 | 12 | | while (true) |
| | 3 | 13 | | { |
| | 3 | 14 | | yield return (RandomNumberGenerator.GetInt32(width), |
| | 3 | 15 | | RandomNumberGenerator.GetInt32(height)); |
| | 2 | 16 | | } |
| | | 17 | | } |
| | | 18 | | |
| | | 19 | | public static IEnumerable<(int X, int Y)> NearPosGenerator(int x, int y) |
| | 11 | 20 | | { |
| | 11 | 21 | | yield return (x - 1, y - 1); |
| | 11 | 22 | | yield return (x, y - 1); |
| | 11 | 23 | | yield return (x + 1, y - 1); |
| | 11 | 24 | | yield return (x - 1, y); |
| | 11 | 25 | | yield return (x + 1, y); |
| | 11 | 26 | | yield return (x - 1, y + 1); |
| | 11 | 27 | | yield return (x, y + 1); |
| | 11 | 28 | | yield return (x + 1, y + 1); |
| | 11 | 29 | | } |
| | | 30 | | |
| | | 31 | | public static IEnumerable<Cell> NearCellGenerator(int x, int y, Func<(int, int), Cell> getCellFunc) => |
| | 36 | 32 | | from nearPos in NearPosGenerator(x, y) |
| | 116 | 33 | | let cell = getCellFunc(nearPos) |
| | 116 | 34 | | where cell is not null |
| | 72 | 35 | | select cell; |
| | | 36 | | |
| | | 37 | | } |
| | | 38 | | } |