public int detect_opponent(Book current) { for (int i = 0; i < used_books.Count; i++ ) { if ((Equals(used_books[i].signs, current.signs)) && (used_books[i].type != current.type)) return i; } return -1; }
public int detect_sign(Book b, Plane p) { int sum = 0; for (int i = 0; i < N; i++ ) { sum += b.mas[i] * p.lambdas[i]; } if (sum - p.lambdas[N] > 0) return 1; else return 0; }
public void recognize() { Book testbook = new Book(ClassType.Unknown, new int[] { Convert.ToInt32(dataGridView1.Rows[0].Cells[1].Value), Convert.ToInt32(dataGridView1.Rows[0].Cells[2].Value), Convert.ToInt32(dataGridView1.Rows[0].Cells[3].Value), Convert.ToInt32(dataGridView1.Rows[0].Cells[4].Value) }); for (int i = 0; i < 4; i++) list_input.Items.Add(testbook.mas[i].ToString()); foreach (Plane p in planes) { testbook.addPlane(p.number, detect_sign(testbook, p)); } foreach (int p in deleted_planes) { testbook.signs.Remove(p); } ClassType testtype = ClassType.Unknown; foreach (Book b in used_books) { if (Equals_deleted(testbook.signs, b.signs, deleted_planes)) testtype = b.type; } //MessageBox.Show(testtype.ToString()); textBox1.Text = testtype.ToString(); string s = ""; foreach (int key in testbook.signs.Keys) { s += String.Format("{0}", testbook.signs[key]); } list_test.Items.Add(s); textBox2.Text = s; dataGridView1.Rows[0].Cells[0].Value = testtype.ToString(); }
public void generate_lambdas(Book b1, Book b2) { int sum1 = 0; int sum2 = 0; int seed = 45; Random random = new Random(seed); int[] lambdas = new int[N+1]; for (int i = 0; i < N; i++) { if (i == 0) lambdas[i] = GenerateRandomNumber(80, 400); else if (i == 1) lambdas[i] = GenerateRandomNumber(20, 80); else if (i == 2) lambdas[i] = GenerateRandomNumber(0, 90); else if (i == 3) lambdas[i] = GenerateRandomNumber(4, 9); sum1 += b1.mas[i] * lambdas[i]; sum2 += b2.mas[i] * lambdas[i]; } int lam = GenerateRandomNumber(0, B); while ((lam > Math.Max(sum1, sum2))&& (lam < Math.Min(sum1, sum2))) { lam = GenerateRandomNumber(0, B); } lambdas[N] = lam; Plane plane = new Plane(lambdas, planes.Count); planes.Add(plane); if (sum1 - lam > 0) { b1.addPlane(plane.number, 1); b2.addPlane(plane.number, 0); } else { b1.addPlane(plane.number, 0); b2.addPlane(plane.number, 1); } foreach (Book b in used_books) { foreach (Plane p in planes) { if (!b.signs.ContainsKey(p.number)) b.addPlane(p.number, detect_sign(b, p)); } } if (!used_books.Contains(b1)) used_books.Add(b1); if (!used_books.Contains(b2)) used_books.Add(b2); }