public static bool LegalPath(this Cell[,] board, int x, int y) { if (!board.Contains(x, y) || board[x, y] != Cell.Full) { return(true); } var copy = board.Copy(); FloodFill(copy, x, y, Cell.Full + 1); return(!copy.Points().Any(s => copy[s.x, s.y] == Cell.Full)); }
public static bool LegalNumbers(this Cell[,] board, int x, int y) { if (!board.Contains(x, y)) { return(true); } if (board[x, y] >= 0) { var cellNumber = (int)board[x, y]; var countUnknown = 0; var countFull = 0; foreach (var(dx, dy) in Cardinals) { var scale = 1; var foundUnknown = false; while (true) { var newX = x + dx * scale; var newY = y + dy * scale; if (!board.Contains(newX, newY) || board[newX, newY] == Cell.Empty || board[newX, newY] >= 0) { break; } if (foundUnknown || board[newX, newY] == Cell.Unknown) { foundUnknown = true; countUnknown++; } else if (board[newX, newY] == Cell.Full && ++countFull > cellNumber) { return(false); } scale++; } } return(countUnknown + countFull >= cellNumber && (cellNumber != 0 || countFull <= 0)); } foreach (var(dx, dy) in Cardinals) { var scale = 1; while (true) { var newX = x + dx * scale; var newY = y + dy * scale; if (!board.Contains(newX, newY)) { break; } if (board[newX, newY] >= 0) { if (!board.LegalNumbers(newX, newY)) { return(false); } break; } scale++; } } return(true); }
public static bool LegalSquare(this Cell[,] board, int x, int y) => !board.Contains(x, y) || board[x, y] != Cell.Full || !Diagonals.Select(d => (x: x + d.x, y: y + d.y)).Any(s =>