コード例 #1
0
        //adds the dictionary to the binary search tree
        private void addDictionary()
        {
            TextReader      reader = new StreamReader(@"Files/Dictionary.txt");
            List <DSString> temp   = new ArrayList <DSString>(DICTIONARY_SIZE);

            //progressbar
            pbrProgress.Value   = 0;
            pbrProgress.Maximum = DICTIONARY_SIZE + DICTIONARY_SIZE;
            lblInfo.Text        = "Loading Dictionary...";

            string line;

            while ((line = reader.ReadLine()) != null)
            {
                DSString add = new DSString(line);
                temp.add(add);

                //show update
                updateProgress();
            }

            //get a split ordering
            List <DSString> split_ordering = Searching.binarySplit <DSString>(temp.toArray());

            //add the items to the tree so lookups remain logarithmic
            for (int i = 0; i < split_ordering.size(); i++)
            {
                my_bst.add(split_ordering.get(i));

                //show update
                updateProgress();
            }

            lblInfo.Text = "Loading Dictionary...";
        }
コード例 #2
0
            /// <summary>
            /// Initializes the class with both a sort type and finish time.
            /// </summary>
            /// <param name="the_sort"></param>
            /// <param name="the_finish_time"></param>
            public FinishTime(DSString the_sort, DSLong the_finish_time)
            {
                Preconditions.checkNull(the_sort);
                Preconditions.checkNull(the_finish_time);

                my_sort        = the_sort;
                my_finish_time = the_finish_time;
            }
コード例 #3
0
        //------------------- HELPER METHODS -------------------

        private bool checkEdgeForVertex(List <SimpleEdge <DSString> > the_edge, DSString the_check)
        {
            //loop through simple edges
            for (int i = 0; i < the_edge.size(); i++)
            {
                if (the_edge.get(i).second_label.Equals(the_check))
                {
                    return(true);
                }
            }

            //must find the element
            return(false);
        }
コード例 #4
0
ファイル: DSIfNode.cs プロジェクト: coppertung/UnityTools
        public void chooseTargetB(DSIfStatement statement)
        {
            GenericMenu dropDownMenu = new GenericMenu();

            for (int i = 0; i < ds.datas.Count; i++)
            {
                for (int j = 0; j < ds.datas [i].fields.Count; j++)
                {
                    if (ds.datas [i].fields [j].type == statement.targetType)
                    {
                        string itemName = ds.datas [i].name + "/" + ds.datas [i].fields [j].name;
                        switch (statement.targetType)
                        {
                        case DSDataType.Int:
                            DSInt intItem = (DSInt)ds.datas [i].fields [j];
                            dropDownMenu.AddItem(new GUIContent(itemName), false, () => {
                                statement.intTargetB    = intItem;
                                statement.targetBString = itemName;
                            });
                            break;

                        case DSDataType.Float:
                            DSFloat floatItem = (DSFloat)ds.datas [i].fields [j];
                            dropDownMenu.AddItem(new GUIContent(itemName), false, () => {
                                statement.floatTargetB  = floatItem;
                                statement.targetBString = itemName;
                            });
                            break;

                        case DSDataType.Bool:
                            DSBool boolItem = (DSBool)ds.datas [i].fields [j];
                            dropDownMenu.AddItem(new GUIContent(itemName), false, () => {
                                statement.boolTargetB   = boolItem;
                                statement.targetBString = itemName;
                            });
                            break;

                        case DSDataType.String:
                            DSString stringItem = (DSString)ds.datas [i].fields [j];
                            dropDownMenu.AddItem(new GUIContent(itemName), false, () => {
                                statement.stringTargetB = stringItem;
                                statement.targetBString = itemName;
                            });
                            break;
                        }
                    }
                }
            }
            dropDownMenu.ShowAsContext();
        }
コード例 #5
0
        //checks whether the list of completed elements contains a sort.
        private bool checkCompletedContains(DSString the_sort)
        {
            //loop through and compare sort names
            Iterator <FinishTime> it = my_completed.iterator();

            while (it.hasNext())
            {
                if (it.next().sort.Equals(the_sort))
                {
                    return(true);
                }
            }
            return(false);
        }
コード例 #6
0
        /// <summary>
        /// Updates the progress bars on the window to display the finished percentage
        /// for each sort.
        /// </summary>
        public void updatePercentage()
        {
            //loop through all sorts
            for (int i = 0; i < my_sort_types.Length; i++)
            {
                //find the sort and update the sort's progress bar
                DSString    sort = new DSString(my_sort_types[i]);
                DrawnSort   ds   = my_sorts.get(sort);
                ProgressBar bar  = my_progress_bars.get(sort);
                bar.Value = (int)(100.0 * ds.percentage_complete);

                //if the sort is finished and has not been marked so
                if (ds.time_taken != 0 && !checkCompletedContains(sort))
                {
                    //record the finish time
                    my_completed.add(new FinishTime(sort, new DSLong(ds.time_taken)));
                }
            }

            //check for whether all labels are correct
            int  count = 0;
            long last  = 0;

            FinishTime[] times = my_completed.toArray();
            Sorting <FinishTime> .Sort(Sorts.InsertionSort, ref times); //sort the finish times

            for (int i = 0; i < times.Length; i++)
            {
                FinishTime sort_done = times[i];
                //this only advances count if a different finish time was found (it recognizes the ties)
                if (last != sort_done.finish_time.value)
                {
                    count++;
                }
                last = sort_done.finish_time.value;

                my_sort_labels.get(sort_done.sort).Text = sort_done.sort.value + " (" + count + ")";
            }

            //check for all sorts finished
            if (my_completed.size() == NUMBER_OF_SORTS)
            {
                Application.DoEvents();
                btnStartTheRace.Enabled = true;
                tmrUpdate.Enabled       = false;
                return;
            }
            Application.DoEvents();
        }
コード例 #7
0
        //clears old race state values.
        private void clearLastRaceValues()
        {
            //clear old place counts for which sort finishes first
            my_completed.clear();

            //clear old label places
            for (int i = 0; i < my_sort_types.Length; i++)
            {
                DSString sort = new DSString(my_sort_types[i]);
                my_sort_labels.get(sort).Text = sort.value;
            }

            //clear old progress bar values
            Iterator <ProgressBar> it = my_progress_bars.values().iterator();
            {
                while (it.hasNext())
                {
                    it.next().Value = 0;
                }
            }
        }
コード例 #8
0
ファイル: DSDataField.cs プロジェクト: coppertung/UnityTools
        public void updateFieldType(int dataIndex, DSDataType type)
        {
            if (_fields [dataIndex].type != type)
            {
                IDSData toReplace = _fields [dataIndex];
                _fields.RemoveAt(dataIndex);
                switch (type)
                {
                case DSDataType.Bool:
                    DSBool newBool = new DSBool();
                    newBool.name = toReplace.name;
                    newBool.type = DSDataType.Bool;
                    _fields.Insert(dataIndex, newBool);
                    break;

                case DSDataType.Float:
                    DSFloat newFloat = new DSFloat();
                    newFloat.name = toReplace.name;
                    newFloat.type = DSDataType.Float;
                    _fields.Insert(dataIndex, newFloat);
                    break;

                case DSDataType.Int:
                    DSInt newInt = new DSInt();
                    newInt.name = toReplace.name;
                    newInt.type = DSDataType.Int;
                    _fields.Insert(dataIndex, newInt);
                    break;

                case DSDataType.String:
                    DSString newString = new DSString();
                    newString.name = toReplace.name;
                    newString.type = DSDataType.String;
                    _fields.Insert(dataIndex, newString);
                    break;
                }
            }
        }
コード例 #9
0
        //cleans up old races and starts the sort threads for a new race.
        private void startRace()
        {
            //setup a new race
            clearLastRaceValues();
            clearOldSorts();

            //generate the drawing objects
            for (int i = 0; i < my_sort_types.Length; i++)
            {
                DSString cur_sort = new DSString(my_sort_types[i]);
                Sorts    type     = (Sorts)Enum.Parse(Sorts.BubbleSort.GetType(), cur_sort.value);
                my_sorts.put(cur_sort, new DrawnSort(type, getInput(), this));
            }

            tmrUpdate.Enabled = true;

            //start the sorts
            Iterator <DrawnSort> it = my_sorts.values().iterator();

            while (it.hasNext())
            {
                it.next().start();
            }
        }
コード例 #10
0
        public override void draw()
        {
            drawInOutPoint();
            titleRect           = rect;
            titleRect.height    = 20f;
            extendedRect        = rect;
            extendedRect.y      = rect.y + titleRect.height - 1f;
            extendedRect.height = rect.height - titleRect.height;
            GUILayout.BeginArea(titleRect, title, GUI.skin.box);
            GUILayout.EndArea();
            GUILayout.BeginArea(extendedRect, GUI.skin.box);
            GUILayout.BeginVertical();
            GUILayout.Space(5f);
            GUILayout.BeginHorizontal();
            GUILayout.Label("Type:", GUILayout.Width(50f));
            actionType = (DSDataType)EditorGUILayout.EnumPopup(actionType);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label(assignValue ? "Target:" : "Target A:", GUILayout.Width(60f));
            if (GUILayout.Button(targetAString))
            {
                chooseTargetAWithDropDown();
            }
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label("Assign Value:", GUILayout.Width(100f));
            assignValue = EditorGUILayout.Toggle(assignValue);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label(assignValue ? "Value:" : "Target B:", GUILayout.Width(60f));
            switch (actionType)
            {
            case DSDataType.Int:
                if (assignValue)
                {
                    intInput = EditorGUILayout.IntField(intInput);
                }
                else
                {
                    if (GUILayout.Button(targetBString))
                    {
                        GenericMenu dropDownMenu = new GenericMenu();
                        for (int i = 0; i < ds.datas.Count; i++)
                        {
                            for (int j = 0; j < ds.datas [i].fields.Count; j++)
                            {
                                if (ds.datas [i].fields [j].type == DSDataType.Int)
                                {
                                    string itemName = ds.datas [i].name + "/" + ds.datas [i].fields [j].name;
                                    DSInt  item     = (DSInt)ds.datas [i].fields [j];
                                    dropDownMenu.AddItem(new GUIContent(itemName), false, () => {
                                        intTargetB    = item;
                                        targetBString = itemName;
                                    });
                                }
                            }
                        }
                        dropDownMenu.ShowAsContext();
                    }
                }
                break;

            case DSDataType.Float:
                if (assignValue)
                {
                    floatInput = EditorGUILayout.FloatField(floatInput);
                }
                else
                {
                    if (GUILayout.Button(targetBString))
                    {
                        GenericMenu dropDownMenu = new GenericMenu();
                        for (int i = 0; i < ds.datas.Count; i++)
                        {
                            for (int j = 0; j < ds.datas [i].fields.Count; j++)
                            {
                                if (ds.datas [i].fields [j].type == DSDataType.Float)
                                {
                                    string  itemName = ds.datas [i].name + "/" + ds.datas [i].fields [j].name;
                                    DSFloat item     = (DSFloat)ds.datas [i].fields [j];
                                    dropDownMenu.AddItem(new GUIContent(itemName), false, () => {
                                        floatTargetB  = item;
                                        targetBString = itemName;
                                    });
                                }
                            }
                        }
                        dropDownMenu.ShowAsContext();
                    }
                }
                break;

            case DSDataType.Bool:
                if (assignValue)
                {
                    boolInput = EditorGUILayout.Toggle(boolInput);
                }
                else
                {
                    if (GUILayout.Button(targetBString))
                    {
                        GenericMenu dropDownMenu = new GenericMenu();
                        for (int i = 0; i < ds.datas.Count; i++)
                        {
                            for (int j = 0; j < ds.datas [i].fields.Count; j++)
                            {
                                if (ds.datas [i].fields [j].type == DSDataType.Bool)
                                {
                                    string itemName = ds.datas [i].name + "/" + ds.datas [i].fields [j].name;
                                    DSBool item     = (DSBool)ds.datas [i].fields [j];
                                    dropDownMenu.AddItem(new GUIContent(itemName), false, () => {
                                        boolTargetB   = item;
                                        targetBString = itemName;
                                    });
                                }
                            }
                        }
                        dropDownMenu.ShowAsContext();
                    }
                }
                break;

            case DSDataType.String:
                if (assignValue)
                {
                    stringInput = EditorGUILayout.TextField(stringInput);
                }
                else
                {
                    if (GUILayout.Button(targetBString))
                    {
                        GenericMenu dropDownMenu = new GenericMenu();
                        for (int i = 0; i < ds.datas.Count; i++)
                        {
                            for (int j = 0; j < ds.datas [i].fields.Count; j++)
                            {
                                if (ds.datas [i].fields [j].type == DSDataType.String)
                                {
                                    string   itemName = ds.datas [i].name + "/" + ds.datas [i].fields [j].name;
                                    DSString item     = (DSString)ds.datas [i].fields [j];
                                    dropDownMenu.AddItem(new GUIContent(itemName), false, () => {
                                        stringTargetB = item;
                                        targetBString = itemName;
                                    });
                                }
                            }
                        }
                        dropDownMenu.ShowAsContext();
                    }
                }
                break;
            }
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
            GUILayout.EndArea();
        }
コード例 #11
0
        public override void load(string save)
        {
            string[] saveStrings = save.Split(DataSimulator.DS_SAVELOAD_SEPERATOR);
            actionType    = (DSDataType)int.Parse(saveStrings [4]);
            targetAString = saveStrings [5];
            assignValue   = bool.Parse(saveStrings [6]);
            if (!string.IsNullOrEmpty(targetAString))
            {
                string[] splitTargetAStrings = targetAString.Split('/');
                string[] splitTargetBStrings = null;
                switch (actionType)
                {
                case DSDataType.Int:
                    intTargetA = (DSInt)ds.datas.Find(x => x.name.Equals(splitTargetAStrings [0])).fields.Find(x => x.name.Equals(splitTargetAStrings [1]));
                    if (assignValue)
                    {
                        intInput = int.Parse(saveStrings [7]);
                    }
                    else
                    {
                        targetBString       = saveStrings [7];
                        splitTargetBStrings = targetBString.Split('/');
                        intTargetB          = (DSInt)ds.datas.Find(x => x.name.Equals(splitTargetBStrings [0])).fields.Find(x => x.name.Equals(splitTargetBStrings [1]));
                    }
                    break;

                case DSDataType.Float:
                    floatTargetA = (DSFloat)ds.datas.Find(x => x.name.Equals(splitTargetAStrings [0])).fields.Find(x => x.name.Equals(splitTargetAStrings [1]));
                    if (assignValue)
                    {
                        floatInput = float.Parse(saveStrings [7]);
                    }
                    else
                    {
                        targetBString       = saveStrings [7];
                        splitTargetBStrings = targetBString.Split('/');
                        floatTargetB        = (DSFloat)ds.datas.Find(x => x.name.Equals(splitTargetBStrings [0])).fields.Find(x => x.name.Equals(splitTargetBStrings [1]));
                    }                                       break;

                case DSDataType.Bool:
                    boolTargetA = (DSBool)ds.datas.Find(x => x.name.Equals(splitTargetAStrings [0])).fields.Find(x => x.name.Equals(splitTargetAStrings [1]));
                    if (assignValue)
                    {
                        boolInput = bool.Parse(saveStrings [7]);
                    }
                    else
                    {
                        targetBString       = saveStrings [7];
                        splitTargetBStrings = targetBString.Split('/');
                        boolTargetB         = (DSBool)ds.datas.Find(x => x.name.Equals(splitTargetBStrings [0])).fields.Find(x => x.name.Equals(splitTargetBStrings [1]));
                    }                                               break;

                case DSDataType.String:
                    stringTargetA = (DSString)ds.datas.Find(x => x.name.Equals(splitTargetAStrings [0])).fields.Find(x => x.name.Equals(splitTargetAStrings [1]));
                    if (assignValue)
                    {
                        stringInput = saveStrings [7];
                    }
                    else
                    {
                        targetBString       = saveStrings [7];
                        splitTargetBStrings = targetBString.Split('/');
                        stringTargetB       = (DSString)ds.datas.Find(x => x.name.Equals(splitTargetBStrings [0])).fields.Find(x => x.name.Equals(splitTargetBStrings [1]));
                    }
                    break;
                }
            }
        }
コード例 #12
0
        public void chooseTargetAWithDropDown()
        {
            GenericMenu dropDownMenu = new GenericMenu();

            switch (actionType)
            {
            case DSDataType.Int:
                for (int i = 0; i < ds.datas.Count; i++)
                {
                    for (int j = 0; j < ds.datas [i].fields.Count; j++)
                    {
                        if (ds.datas [i].fields [j].type == DSDataType.Int)
                        {
                            string itemName = ds.datas [i].name + "/" + ds.datas [i].fields [j].name;
                            DSInt  item     = (DSInt)ds.datas [i].fields [j];
                            dropDownMenu.AddItem(new GUIContent(itemName), false, () => {
                                intTargetA    = item;
                                targetAString = itemName;
                            });
                        }
                    }
                }
                break;

            case DSDataType.Float:
                for (int i = 0; i < ds.datas.Count; i++)
                {
                    for (int j = 0; j < ds.datas [i].fields.Count; j++)
                    {
                        if (ds.datas [i].fields [j].type == DSDataType.Float)
                        {
                            string  itemName = ds.datas [i].name + "/" + ds.datas [i].fields [j].name;
                            DSFloat item     = (DSFloat)ds.datas [i].fields [j];
                            dropDownMenu.AddItem(new GUIContent(itemName), false, () => {
                                floatTargetA  = item;
                                targetAString = itemName;
                            });
                        }
                    }
                }
                break;

            case DSDataType.Bool:
                for (int i = 0; i < ds.datas.Count; i++)
                {
                    for (int j = 0; j < ds.datas [i].fields.Count; j++)
                    {
                        if (ds.datas [i].fields [j].type == DSDataType.Bool)
                        {
                            string itemName = ds.datas [i].name + "/" + ds.datas [i].fields [j].name;
                            DSBool item     = (DSBool)ds.datas [i].fields [j];
                            dropDownMenu.AddItem(new GUIContent(itemName), false, () => {
                                boolTargetA   = item;
                                targetAString = itemName;
                            });
                        }
                    }
                }
                break;

            case DSDataType.String:
                for (int i = 0; i < ds.datas.Count; i++)
                {
                    for (int j = 0; j < ds.datas [i].fields.Count; j++)
                    {
                        if (ds.datas [i].fields [j].type == DSDataType.String)
                        {
                            string   itemName = ds.datas [i].name + "/" + ds.datas [i].fields [j].name;
                            DSString item     = (DSString)ds.datas [i].fields [j];
                            dropDownMenu.AddItem(new GUIContent(itemName), false, () => {
                                stringTargetA = item;
                                targetAString = itemName;
                            });
                        }
                    }
                }
                break;
            }
            dropDownMenu.ShowAsContext();
        }
コード例 #13
0
        //searches for words in the dictionary that match unique permutations of all subsets
        //of the user input.
        private void searchForWords()
        {
            string input = txtLetters.Text;

            //check for bad input
            if (input.Length == 0)
            {
                MessageBox.Show("You must enter letters in the textbox to get results.");
                return;
            }
            else if (input.Length > 8)
            {
                MessageBox.Show("A maximum of eight characters is allowed due to the time-complexity of this algorithm.");
                return;
            }

            //tree to hold words
            if (!my_dictionary_loaded)
            {
                my_dictionary_loaded = true;
                addDictionary();
            }

            //get characters
            char[] letters = input.ToLower().ToCharArray();

            //get unique permutations
            Subsets s = new Subsets();

            s.addObserver(this);

            lblInfo.Text = "Getting letter permutations...";
            List <List <DSInteger> > permutation_indices = s.getUniquePermutationIndices <DSInteger>(letters.Length);

            lblInfo.Text        = "Building possible words...";
            pbrProgress.Value   = 0;
            pbrProgress.Maximum = permutation_indices.size();

            //get word candidates from the permutation indices
            Set <DSString> word_candidates = new HashSet <DSString>();

            for (int i = 0; i < permutation_indices.size(); i++)
            {
                StringBuilder    builder     = new StringBuilder();
                List <DSInteger> permutation = permutation_indices.get(i);
                for (int j = 0; j < permutation.size(); j++)
                {
                    builder.Append(letters[permutation.get(j).value]);
                }

                DSString possible = new DSString(builder.ToString());
                if (!word_candidates.contains(possible))
                {
                    word_candidates.add(possible);
                }

                //show progress
                updateProgress();
            }

            pbrProgress.Value   = 0;
            pbrProgress.Maximum = word_candidates.size();
            lblInfo.Text        = "Check Search Tree for words...";

            //sort candidates according to length and then alphabetically
            DSString[] sorted = word_candidates.toArray();
            Sorting <DSString> .Sort(Sorts.QuickSort, ref sorted, new StringLengthComparator());

            //clear old lookups
            lstWords.Items.Clear();

            //lookup each word in the bst
            for (int i = sorted.Length - 1; i >= 0; i--)
            {
                DSString current = sorted[i];
                if (my_bst.contains(current))
                {
                    lstWords.Items.Add(current.value);
                }

                //show progress
                updateProgress();
            }

            //show words found
            lblInfo.Text = "Words found: " + lstWords.Items.Count;
        }
コード例 #14
0
        private void drawDataField(DSDataField data)
        {
            for (int i = 0; i < data.fields.Count; i++)
            {
                try {
                    GUILayout.BeginHorizontal();
                    data.fields [i].name = GUILayout.TextField(data.fields [i].name, GUILayout.Width(80f));
                    DSDataType dataType = data.fields [i].type;
                    dataType = (DSDataType)EditorGUILayout.EnumPopup(dataType, GUILayout.Width(50f));
                    data.updateFieldType(i, dataType);
                    switch (data.fields [i].type)
                    {
                    case DSDataType.Bool:
                        GUILayout.Space(70f);
                        DSBool boolField = (DSBool)data.fields[i];
                        boolField.value = EditorGUILayout.Toggle(boolField.value);
                        break;

                    case DSDataType.Float:
                        DSFloat floatField = (DSFloat)data.fields[i];
                        GUILayout.Label("Random", GUILayout.Width(50f));
                        floatField.isRandom = EditorGUILayout.Toggle(floatField.isRandom, GUILayout.Width(20f));
                        if (floatField.isRandom)
                        {
                            floatField.minValue = EditorGUILayout.FloatField(floatField.minValue, GUILayout.Width(50f));
                            GUILayout.Label(" -", GUILayout.Width(20f));
                            floatField.maxValue = EditorGUILayout.FloatField(floatField.maxValue, GUILayout.Width(50f));
                        }
                        else
                        {
                            floatField.value = EditorGUILayout.FloatField(floatField.value, GUILayout.Width(50f));
                        }
                        break;

                    case DSDataType.Int:
                        DSInt intField = (DSInt)data.fields[i];
                        GUILayout.Label("Random", GUILayout.Width(50f));
                        intField.isRandom = EditorGUILayout.Toggle(intField.isRandom, GUILayout.Width(20f));
                        if (intField.isRandom)
                        {
                            intField.minValue = EditorGUILayout.IntField(intField.minValue, GUILayout.Width(50f));
                            GUILayout.Label(" -", GUILayout.Width(20f));
                            intField.maxValue = EditorGUILayout.IntField(intField.maxValue, GUILayout.Width(50f));
                        }
                        else
                        {
                            intField.value = EditorGUILayout.IntField(intField.value, GUILayout.Width(50f));
                        }
                        break;

                    case DSDataType.String:
                        DSString stringField = (DSString)data.fields[i];
                        if (string.IsNullOrEmpty(stringField.value))
                        {
                            stringField.value = "";
                        }
                        stringField.value = GUILayout.TextField(stringField.value);
                        break;
                    }
                    if (GUILayout.Button("-", GUILayout.Width(20)))
                    {
                        data.removeField(i);
                    }
                    GUILayout.EndHorizontal();
                }
                catch (ArgumentOutOfRangeException ex) {
                    // do nothing
                }
                catch (Exception ex) {
                    Debug.Log(ex.Message);
                }
            }
        }
コード例 #15
0
 //links a sort to a progressbar and a label.
 private void addSingleLink(DSString the_sort, ProgressBar the_pbar, Label the_label)
 {
     my_progress_bars.put(the_sort, the_pbar);
     my_sort_labels.put(the_sort, the_label);
 }