Exemplo n.º 1
0
 private void CopyShowOrder(ShowOrder src, ShowOrder dest)
 {
     if (dest.Count > 0) dest.Clear();
     foreach (int item in src)
     {
         dest.Add(item);
     }
 }
Exemplo n.º 2
0
        //main backtrack function
        private bool BacktrackSearch()
        {
            if (solutionList.Count >= listThreshold) return true;

            if (solutionFull())
            {
                if (solutionAlreadyFound())
                    return true;

                ShowOrder temp = new ShowOrder(this);
                foreach (int item in showOrder)
                    temp.Add(item);
                addToSolutionList(temp);

                return true;
            }

            //insert the cast list that has the least amount of piece-possiblities but also
            int nextPossible = 0;
            int insertedValue  = insertNextPossible(showOrder.Count, nextPossible);

            while (insertedValue != -1)
            {

                //save the showOrderPosition into temp
                //save the showOrder into temp
                ShowOrderPosition tempShowOrderPosition = new ShowOrderPosition(this);
                ShowOrder tempShowOrder = new ShowOrder(this);
                CopyShowOrderPosition(showOrderPosition, tempShowOrderPosition);
                CopyShowOrder(showOrder, tempShowOrder);

                bool works = insertIntoShowOrder(insertedValue);

                if (works)
                    BacktrackSearch();

                //else return back to previous state
                CopyShowOrderPosition(tempShowOrderPosition, showOrderPosition);
                CopyShowOrder(tempShowOrder, showOrder);

                nextPossible++;
                insertedValue = insertNextPossible(showOrder.Count, nextPossible);

            }

            return false;
        }