Exemple #1
0
        private void SetLineSolution(LineType lineType, int lineIndex, PicrossLine candidateToSet)
        {
            var targetSet            = lineType == LineType.Column ? Columns : Rows;
            PicrossActiveLine target = targetSet.First(line => line.Index == lineIndex);

            target.ApplyLine(candidateToSet);
        }
Exemple #2
0
 public PicrossLine(PicrossLine copySource)
 {
     Cells = new PicrossCell[copySource.Length];
     for (int i = 0; i < Length; i++)
     {
         Cells[i] = new PicrossCell()
         {
             State = copySource.Cells[i].State
         };
     }
 }
Exemple #3
0
        //This function should check if this line is a valid speculative candidate for the line we pass as a parameter
        //This does not count validity - we suppose that the speculative line was generated from the rule
        public bool IsCandidateSolutionFor(PicrossLine activeLine)
        {
            if (activeLine.Length != Cells.Count())
            {
                throw new ArgumentException();
            }

            return
                (Enumerable.Range(0, activeLine.Length - 1)
                 .Where(lineIndex => activeLine.Cells[lineIndex] != PicrossCellState.Undetermined)
                 .All(lineIndex => Cells[lineIndex].State == activeLine.Cells[lineIndex].State));
        }
Exemple #4
0
        public bool Validate(PicrossLine line)
        {
            var lineBlocks = line.ComputeBlocks();

            if (BlockCount <= lineBlocks.Count())
            {
                return(false);
            }
            else
            {
                return(Enumerable.Range(0, lineBlocks.Count() - 1).All(blockIndex =>
                                                                       lineBlocks.ElementAt(blockIndex) <= BlocksRule.ElementAt(blockIndex)));
            }
        }
Exemple #5
0
        public void And(PicrossLine otherLine)
        {
            if (Length != otherLine.Length)
            {
                throw new ArgumentException();
            }

            for (int i = 0; i < Length; i++)
            {
                var localState = Cells[i].State;
                var otherState = otherLine.Cells[i].State;
                Cells[i].State = localState.And(otherState);
            }
        }
Exemple #6
0
        public PicrossLine GetDeterminableCells()
        {
            if (!IsValid)
            {
                return(new PicrossLine(Length, PicrossCellState.Undetermined));
            }

            PicrossLine determinableCells = new PicrossLine(CandidateSolutions.First());

            foreach (var candidateSolution in CandidateSolutions.Skip(1))
            {
                determinableCells.And(candidateSolution);
            }
            return(determinableCells);
        }
Exemple #7
0
        public bool CheckSolution(PicrossLine line)
        {
            if (IsEmpty)
            {
                return(line.Cells.All(cell => cell.State == PicrossCellState.Void));
            }

            var lineBlocks = line.ComputeBlocks();

            if (BlockCount != lineBlocks.Count())
            {
                return(false);
            }
            else
            {
                return(Enumerable.Range(0, lineBlocks.Count() - 1).All(blockIndex =>
                                                                       lineBlocks.ElementAt(blockIndex) == BlocksRule.ElementAt(blockIndex)));
            }
        }
Exemple #8
0
        public void ApplyLine(PicrossLine line)
        {
            if (line.Length != Length)
            {
                throw new ArgumentException();
            }

            skipReview = true;
            Parallel.ForEach(
                Enumerable.Range(0, Length),
                cellIndex =>
            {
                var newState = line.Cells[cellIndex].State;
                if (newState != PicrossCellState.Undetermined)
                {
                    Cells[cellIndex].State = newState;
                }
            });
            skipReview = false;
            ReviewCandidates();
        }