Esempio n. 1
0
 private List <MatrixRow> BuildMatrixRowsForColourPairPaths(
     ColourPair colourPair,
     int colourPairIndex,
     IEnumerable <Path> paths)
 {
     return(paths
            .Select(path => BuildMatrixRowForColourPairPath(colourPair, colourPairIndex, path))
            .ToList());
 }
Esempio n. 2
0
        public static IEnumerable <Path> InitialPaths(ColourPair colourPair)
        {
            yield return(Path.PathWithStartCoordsAndDirection(colourPair.StartCoords, Direction.Up));

            yield return(Path.PathWithStartCoordsAndDirection(colourPair.StartCoords, Direction.Down));

            yield return(Path.PathWithStartCoordsAndDirection(colourPair.StartCoords, Direction.Left));

            yield return(Path.PathWithStartCoordsAndDirection(colourPair.StartCoords, Direction.Right));
        }
Esempio n. 3
0
        private Tuple <List <MatrixRow>, List <Path> > FindAllPathsForColourPair(
            ColourPair colourPair,
            int colourPairIndex,
            IEnumerable <Path> activePaths,
            int maxDirectionChanges)
        {
            var pathFinder       = new PathFinder(_cancellationToken);
            var paths            = pathFinder.FindAllPaths(_grid, colourPair.EndCoords, activePaths, maxDirectionChanges);
            var partitionedPaths = paths.ToLookup(p => p.IsActive);
            var completedPaths   = partitionedPaths[true].ToList();
            var stalledPaths     = partitionedPaths[false].ToList();
            var matrixRows       = BuildMatrixRowsForColourPairPaths(colourPair, colourPairIndex, completedPaths);

            return(Tuple.Create(matrixRows, stalledPaths));
        }
Esempio n. 4
0
        private MatrixRow BuildMatrixRowForColourPairPath(ColourPair colourPair, int colourPairIndex, Path path)
        {
            var dlxRow = new BitArray(_numColumns);

            dlxRow[colourPairIndex] = true;

            // ReSharper disable once LoopCanBePartlyConvertedToQuery
            foreach (var coords in path.CoordsList)
            {
                var gridLocationIndex = _numColourPairs + (_grid.GridSize * coords.X) + coords.Y;
                dlxRow[gridLocationIndex] = true;
            }

            return(new MatrixRow(colourPair, path, dlxRow));
        }
Esempio n. 5
0
 private List <Path> GetStalledPathsForColourPair(ColourPair colourPair)
 {
     return(_stalledPaths.Where(path => path.CoordsList.First().Equals(colourPair.StartCoords)).ToList());
 }
Esempio n. 6
0
 public MatrixRow(ColourPair colourPair, Path path, BitArray dlxRow)
 {
     _colourPair = colourPair;
     _path       = path;
     _dlxRow     = dlxRow;
 }