Exemplo n.º 1
0
        private bool IsMutant(List <string> dna)
        {
            bool     mutantFound       = false;
            short    sequenceCount     = 0;
            Sequence lastSequenceFound = null;
            Sequence sequence          = null;

            Entities.Index index = null;

            Matrix matrix = new Matrix(dna);

            if (matrix.RowsCount < 4 && matrix.ColumnsCount < 4)
            {
                return(false);
            }

            for (int x = 0; x < matrix.RowsCount; x++)
            {
                for (int y = 0; y < matrix.ColumnsCount; y++)
                {
                    index = new Entities.Index(x, y);

                    if (!this.IndexBelongToHorizontalSequence(lastSequenceFound, index))
                    {
                        sequence = matrix.FindHorizontalSequence(index);
                        this.AnalyzeResult(sequence, ref sequenceCount, ref lastSequenceFound, out mutantFound);
                        if (mutantFound)
                        {
                            return(true);
                        }
                    }

                    if (!this.IndexBelongToVerticalSequence(lastSequenceFound, index))
                    {
                        sequence = matrix.FindVerticalSequence(index);
                        this.AnalyzeResult(sequence, ref sequenceCount, ref lastSequenceFound, out mutantFound);
                        if (mutantFound)
                        {
                            return(true);
                        }
                    }

                    if (!this.IndexBelongToLeftObliqueSequence(lastSequenceFound, index))
                    {
                        sequence = matrix.FindLeftObliqueSequence(index);
                        this.AnalyzeResult(sequence, ref sequenceCount, ref lastSequenceFound, out mutantFound);
                        if (mutantFound)
                        {
                            return(true);
                        }
                    }

                    if (!this.IndexBelongToRightObliqueSequence(lastSequenceFound, index))
                    {
                        sequence = matrix.FindRightObliqueSequence(index);
                        this.AnalyzeResult(sequence, ref sequenceCount, ref lastSequenceFound, out mutantFound);
                        if (mutantFound)
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Exemplo n.º 2
0
 private bool IndexBelongToVerticalSequence(Sequence sequence, Entities.Index index)
 {
     return(sequence != null && sequence.SequenceType == SequenceType.VERTICAL && sequence.Contains(index));
 }
Exemplo n.º 3
0
 private bool IndexBelongToRightObliqueSequence(Sequence sequence, Entities.Index index)
 {
     return(sequence != null && sequence.SequenceType == SequenceType.OBLIQUE_RIGHT && sequence.Contains(index));
 }
Exemplo n.º 4
0
 private bool IndexBelongToHorizontalSequence(Sequence sequence, Entities.Index index)
 {
     return(sequence != null && sequence.SequenceType == SequenceType.HORIZONTAL && sequence.Contains(index));
 }