コード例 #1
0
        // TODO: Implement FlippedBoard or make it work from the other end as well
        public IEnumerable <BoardChange> Solve(IBoard board)
        {
            HashSet <BoardChange>?changes = new HashSet <BoardChange>();

            this.VerticalCheck(board, changes);
            HashSet <BoardChange>?transposedChanges = new HashSet <BoardChange>();
            TransposedBoard?      transposedBoard   = new TransposedBoard(board);

            this.VerticalCheck(transposedBoard, transposedChanges);
            if (transposedChanges.Count > 0)
            {
                changes.Add(transposedChanges.Transpose());
            }

            HashSet <BoardChange>?flippedChanges = new HashSet <BoardChange>();
            FlippedBoard?         flippedBoard   = new FlippedBoard(board);

            this.VerticalCheck(flippedBoard, flippedChanges);
            if (flippedChanges.Count > 0)
            {
                changes.Add(flippedChanges.Flip(board.Width, board.Height));
            }

            HashSet <BoardChange>?flippedTransposedChanges = new HashSet <BoardChange>();
            FlippedBoard?         flippedTransposedBoard   = new FlippedBoard(transposedBoard);

            this.VerticalCheck(flippedTransposedBoard, flippedTransposedChanges);
            if (flippedTransposedChanges.Count > 0)
            {
                changes.Add(flippedTransposedChanges.Flip(board.Width, board.Height).Transpose());
            }

            return(changes);
        }
コード例 #2
0
        public void VerticalChanges()
        {
            var board  = new TransposedBoard(BoardSamples.Board1);
            var solver = new OnlyOneWayToFill();

            var actualChanges = solver.Solve(board);

            var expected = new HashSet <BoardChange>
            {
                new BoardChange(0, 0, CellState.Filled),
                new BoardChange(1, 0, CellState.Filled),
                new BoardChange(2, 0, CellState.Filled),
                new BoardChange(3, 0, CellState.Blocked),
                new BoardChange(4, 0, CellState.Filled),
                new BoardChange(0, 1, CellState.Filled),
                new BoardChange(1, 1, CellState.Filled),
                new BoardChange(2, 1, CellState.Blocked),
                new BoardChange(3, 1, CellState.Filled),
                new BoardChange(4, 1, CellState.Filled),
                new BoardChange(0, 2, CellState.Filled),
                new BoardChange(1, 2, CellState.Blocked),
                new BoardChange(2, 2, CellState.Filled),
                new BoardChange(3, 2, CellState.Blocked),
                new BoardChange(4, 2, CellState.Filled),
            };

            TestUtilities.VerifyChanges(expected.Transpose(), actualChanges);
        }