Beispiel #1
0
        public static Move GetInstance(Component component, Combinable combinable)
        {
            Move bestMove = BestAppend(combinable);

            if (component.CoreLength >= combinable.CoreLength)
            {
                Move absorbsMoveOrNull = BestAbsorbs(component, combinable);
                bestMove = Move.MaxOrNull(absorbsMoveOrNull, bestMove);
            }
            else
            {
                Move absorbedByMoveOrNull = BestAbsorbedBy(component, combinable);
                bestMove = Move.MaxOrNull(absorbedByMoveOrNull, bestMove);
            }

            Move leftMoveOrNull = BestLeftOrNull(component, combinable);

            bestMove = Move.MaxOrNull(leftMoveOrNull, bestMove);

            Move rightMoveOrNull = BestRightOrNull(component, combinable);

            bestMove = Move.MaxOrNull(rightMoveOrNull, bestMove);

            return(bestMove);
        }
Beispiel #2
0
        static private Move BestAbsorbedBy(Component component, Combinable combinable)
        {
            PatchPattern unification = component.PatchPattern().UnifyOrNull(combinable.PatchPattern());

            if (unification != null)
            {
                Move bestMove = new MergeInPatch(component, combinable, unification);
                return(bestMove);
            }
            else
            {
                return(null);
            }
        }
Beispiel #3
0
        static private Move BestRightLeftOrNull(Component component, Combinable combinable, PatchPattern main, PatchPattern other)
        {
            int lengthOfShorter = Math.Min(main.CoreLength, other.CoreLength);


            for (int overlap = lengthOfShorter - 1; overlap > 0; --overlap)
            {
                PatchPattern unification = other.UnifyOnRightOrNull(overlap, main);
                if (unification != null)
                {
                    Move aMove = new MergeInPatch(component, combinable, unification);
                    return(aMove);
                }
            }

            return(null);
        }
Beispiel #4
0
        public MergeInPatch(Component component, Combinable combinable, PatchPattern unification)
        {
            string u = unification.ToString();

            Debug.Assert(u[0] != '.' && u[u.Length - 1] != '.');           // real assert should have AASet.OptionalAny at start or end

            Component   = component;
            Combinable  = combinable;
            Unification = unification;
            if (combinable is Patch)
            {
                _LengthIncrease = unification.FullLength - component.FullLength;
                Debug.Assert(_LengthIncrease >= 0);                 // real assert
                _ScoreImprovement = combinable.Weight;
            }
            else
            {
                //!!!we don't distinish between a merge that reduces the length more or less
                Debug.WriteLine("A merge of two components has been found");
                _LengthIncrease = Unification.FullLength - (Component.FullLength + Combinable.FullLength);
                Debug.Assert(_LengthIncrease < 0);
                _ScoreImprovement = 0;
            }
        }
Beispiel #5
0
 public void ReplaceWithUnification(Combinable combinable, PatchPattern unification)
 {
     _patchPattern = unification;
     Weight       += combinable.Weight;
 }
Beispiel #6
0
        static private Move BestRightOrNull(Component component, Combinable combinable)
        {
            Move aMove = BestRightLeftOrNull(component, combinable, combinable.PatchPattern(), component.PatchPattern());

            return(aMove);
        }
Beispiel #7
0
        static private Move BestAppend(Combinable combinable)
        {
            Move bestMove = combinable.GetAppend();

            return(bestMove);
        }