private void VerticalCheck(IBoard board, HashSet <BoardChange> changes) { for (int x = 0; x < board.Width; x++) { var groups = SimpleGrouper.GroupVertical(board, x); var ruleLine = board.TopRules[x]; if (ruleLine.Count == 0) { continue; } var highestRuleNumber = ruleLine.Max(); if (!groups.ContainsNones || highestRuleNumber == 0) { continue; } foreach (var group in groups.Groups) { if (group.State == CellState.Filled && group.Count == highestRuleNumber) { // Block off before the start of the group. if (group.StartIndex > 0 && board[x, group.StartIndex - 1] == CellState.None) { changes.Add(BoardChange.Blocked(x, group.StartIndex - 1)); } var lastIndex = group.StartIndex + group.Count; if (lastIndex < board.Height && board[x, lastIndex] == CellState.None) { changes.Add(BoardChange.Blocked(x, lastIndex)); } } } } }
public void MixedAllVertical() { var board = BoardSamples.Board1 .ApplyChanges( new BoardChange(0, 0, CellState.Filled), new BoardChange(0, 1, CellState.Filled), new BoardChange(0, 3, CellState.Filled), new BoardChange(0, 4, CellState.Blocked) ); var verticalGroup = SimpleGrouper.GroupVertical(board, 0); var expected = new List <Group> { new Group(CellState.Filled, 0, 2), new Group(CellState.None, 2, 1), new Group(CellState.Filled, 3, 1), new Group(CellState.Blocked, 4, 1) }; Assert.Equal(expected, verticalGroup.Groups); var horizontalGroup = SimpleGrouper.GroupHorizontal(board, 4); var expectedHorizontal = new List <Group> { new Group(CellState.Blocked, 0, 1), new Group(CellState.None, 1, 4) }; Assert.Equal(expectedHorizontal, horizontalGroup.Groups); }
private void VerticalCheck(IBoard board, HashSet <BoardChange> changes) { bool lineIsCompleted; for (int x = 0; x < board.Width; x++) { lineIsCompleted = false; IRuleLine?ruleLine = board.TopRules[x]; int? firstRule = ruleLine?.FirstOrDefault(); if (firstRule == null) { continue; } GroupCollection?groups = SimpleGrouper.GroupVertical(board, x); if (groups == null) { continue; } Group?firstEmptyGroup = default; int totalSpace = 0; foreach (Group group in groups.Groups) { switch (group.State) { case CellState.None: if (firstEmptyGroup == null) { firstEmptyGroup = group; } totalSpace += group.Count; break; case CellState.Filled: totalSpace += group.Count; break; case CellState.Blocked: if (totalSpace < firstRule.Value && firstEmptyGroup != null) { for (int i = 0; i < firstEmptyGroup.Value.Count; i++) { changes.Add(BoardChange.Blocked(x, i + firstEmptyGroup.Value.StartIndex)); } lineIsCompleted = true; } break; default: break; } // Jump out of the group loop if (lineIsCompleted) { break; } } } }
public void EmptyBoardVertical() { var board = BoardSamples.Board1; var horizontalGroup = SimpleGrouper.GroupVertical(board, 0); var expected = new List <Group> { new Group(CellState.None, 0, 5) }; Assert.Equal(expected, horizontalGroup.Groups); }
public void MixedFilledAndEmptyVertical() { var board = BoardSamples.Board1 .ApplyChanges( new BoardChange(0, 0, CellState.Filled), new BoardChange(0, 1, CellState.Filled), new BoardChange(0, 3, CellState.Filled) ); var verticalGroup = SimpleGrouper.GroupVertical(board, 0); var expected = new List <Group> { new Group(CellState.Filled, 0, 2), new Group(CellState.None, 2, 1), new Group(CellState.Filled, 3, 1), new Group(CellState.None, 4, 1), }; Assert.Equal(expected, verticalGroup.Groups); }
private static void HorizontalRulesCheck(IBoard board, HashSet <BoardChange> changes) { for (int y = 0; y < board.Height; y++) { GroupCollection?groups = SimpleGrouper.GroupHorizontal(board, y); IRuleLine? ruleLine = board.LeftRules[y]; if (groups.ContainsNones && groups.SatisfiesRuleLine(ruleLine)) { for (int x = 0; x < board.Width; x++) { CellState state = board[x, y]; if (state == CellState.None) { changes.Add(BoardChange.Blocked(x, y)); } } } } }