示例#1
0
        public static void Sort(dynamic what, int begin, int end, Comp<dynamic> comp = null)
        {
            if (comp == null)
            {
                comp = (a, b) => { return a.CompareTo(b); };
            }
            int last = end - 1;
            int dist = end - begin + 1;
            if (dist == 0 || dist == 1)
            {
                return;
            }
            if (dist == 2)
            {
                if (comp(what[begin], what[last]) == -1)
                {
                    int tmp = what[begin];
                    what[begin] = what[end];
                    what[last] = tmp;
                }
                return;
            }

            dist /= 2;
            int mid = begin + dist;
            Sort(what, begin, mid, comp);
            Sort(what, mid, end, comp);
            Merge(what, begin, mid, mid, end, comp);
        }
示例#2
0
 static void Main(string[] args)
 {
     Comp d = new Comp(CompareElements);
     //Func<object, object, bool> f = new Func<object, object, bool>(CompareElements);
     object[] arr = { 5, 3, 4, 5, 3, 1, 9, 8 };
     object key = 6;
     SearchElement(arr, key, d);
 }
示例#3
0
 static void SearchElement(object[] obj, object key, Comp dlg)
 {
     foreach (object o in obj)
         if (dlg(o, key))
         {
             Console.WriteLine("Element is in the array!");
             return;
         }
     Console.WriteLine("No such element in the array!");
 }
示例#4
0
        private static void Merge(dynamic what, int b1, int e1, int b2, int e2, Comp<dynamic> comp = null)
        {
            if (comp==null)
            {
                comp = (a, b) => { return a.CompareTo(b); };
            }

            List<dynamic> __arr = new List<dynamic>();
            int it1 = b1, it2 = b2;
            while (it1 != e1 && it2 != e2)
            {
                if (comp(what[it1], what[it2]) == -1)
                {
                    __arr.Add(what[it1]);
                    it1++;
                }
                else
                {
                    __arr.Add(what[it2]);
                    it2++;
                }
            }

            if (it1 == e1)
            {
                while (it2 != e2)
                {
                    __arr.Add(what[it2]);
                    it2++;
                }
            }

            if (it2 == e2)
            {
                while (it1 != e1)
                {
                    __arr.Add(what[it1]);
                    it1++;
                }
            }

            it1 = b1;
            for (int i = 0; i < e1 - b1; i++)
            {
                what[it1] = __arr[i];
                it1++;
            }

            it2 = b2;
            for (int i = e1 - b1; i < __arr.Count; i++)
            {
                what[it2] = __arr[i];
                it2++;
            }
        }
示例#5
0
        /// <summary>
        /// Read information from file.
        /// </summary>
        /// <param name="fileName"> Name of file. </param>
        private void ReadFromFile(string fileName)
        {
            StreamReader reader = new StreamReader(fileName);
            if (reader == null)
            {
                throw new FileLoadException("Can't open", fileName);
            }

            // Number of comps and matrix.
            numberOfComps = Convert.ToInt32(reader.ReadLine());
            compsMatrix = new Matrix(reader, numberOfComps);

            // Chance of Infection with number os OS.
            int numberOfOS = Convert.ToInt32(reader.ReadLine());
            opSysts = new OperationSystem[numberOfOS];
            for (int i = 0; i < numberOfOS; i++)
            {
                string[] temp = reader.ReadLine().Split(' ');
                opSysts[i] = new OperationSystem(temp[0], 100 / Convert.ToInt32(temp[1]));
            }

            // Computer's OS.
            comps = new Comp[numberOfComps];
            for (int i = 0; i < numberOfComps; i++)
            {
                comps[i] = new Comp(false, OpSystWithName(reader.ReadLine().Split(' ')[1]));
            }

            // Infected.
            numberOfInfected = 0;
            string[] arrayInfected = reader.ReadLine().Split(' ');
            for (int i = 0; i < arrayInfected.Length; i++)
            {
                comps[Convert.ToInt32(arrayInfected[i]) - 1].IsInfected = true;
                numberOfInfected++;
            }

            reader.Close();
        }
示例#6
0
文件: test.cs 项目: mutast/study2
	void Start () {
		int x = 20;
		//Debug.Log(x);

		int a=10,b=14,c=100,d=1,e=5;
		int max = MAX(a,b,c,d,e);
		//Debug.Log("max= " + max.ToString());

		Comp co = new Comp();
		co.Num1 = 10;
		//Debug.Log(co.Num1);
		Person ps = new Person("namae",18);
		Person.Chek();
		//Debug.Log(Person.id);
		//Debug.Log(ps.Name);
		//Debug.Log(ps.Age);
		//str1 = "ttttttttt";
		//Debug.Log(str1);
		Debug.Log("ctest" + Ctest1.Test1(10));
		Ctest1.Num1 = 1000;
		Debug.Log("ctest2" + Ctest1.Num1);
		Debug.Log("gittest確認しましたー");
	}
示例#7
0
        private void Worlds_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.Comps.Enabled = false;
            this.Comps.DataSource = null;
            if (Worlds.SelectedItem.ToString() != "")
            {
                var compsDir = Path.Combine(Destination.Text, "saves", Worlds.SelectedItem.ToString(), "computer");
                if (Directory.Exists(compsDir))
                {
                    var info = new DirectoryInfo(compsDir);
                    this.Comps.DataSource = null;
                    this.Comps.Items.Clear();
                    var namedComps = new Dictionary<int, string>();
                    var lines = System.IO.File.ReadAllLines(Path.Combine(compsDir, "labels.txt"));
                    foreach (var line in lines)
                    {
                        var m = System.Text.RegularExpressions.Regex.Match(line, @"^(?<id>[0-9]+) (?<name>[^\n]+)");
                        while (m.Success)
                        {
                            Console.WriteLine(string.Format("{0} - {1}", m.Groups["id"].Value, m.Groups["name"].Value));
                            namedComps.Add(Convert.ToInt32(m.Groups["id"].Value), m.Groups["name"].Value);
                            m = m.NextMatch();
                        }
                    }
                    var comps = new List<Comp>();
                    foreach (var directory in info.GetDirectories().Select(x => x.Name))
                    {
                        int id = 0;
                        if (int.TryParse(directory, out id))
                        {
                            var comp = new Comp();
                            comp.id = id;
                            if (namedComps.ContainsKey(id)) comp.name = namedComps[id];
                            comps.Add(comp);
                        }
                    }

                    this.Comps.DataSource = comps.OrderBy(x => x.id).ToList(); ;
                    this.Comps.DisplayMember = "value";
                    this.Comps.ValueMember = "id";
                    this.Comps.Enabled = true;
                }
                else
                {
                    this.Comps.Items.Add("<None found>");
                }
            }
            this.Comps.SelectedIndex = 0;
            if (!this.isLoading)
            {
                Properties.Settings.Default.World = this.Worlds.SelectedItem.ToString();
                Properties.Settings.Default.Save();
            }
            this.UpdateCopy();
        }
 public ContentTypeInfo(ContentType type, Comp comp, string ext, string mime)
 {
     m_type = type;
     m_comp = comp;
     m_ext = ext;
     m_mime = mime;
 }
示例#9
0
 /// <summary>
 /// One step to infect some comps.
 /// </summary>
 private void StepInfection()
 {
     Comp[] newInfectedComps = new Comp[numberOfComps];
     comps.CopyTo(newInfectedComps, 0);
     for (int i = 0; i < numberOfComps; i++)
     {
         if (comps[i].IsInfected)
             for (int j = 0; j < numberOfComps; j++)
                 if (compsMatrix.IsConnect(i, j))
                     if (!comps[j].IsInfected && comps[j].Infect(random.Next(100)))
                         numberOfInfected++;
     }   
     comps = newInfectedComps;
 }