Exemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (numericUpDown2.Value != 0)
            {
                listBox1.DataSource = null;
                listBox2.DataSource = null;

                Lbltc.Text  = "0";
                lblavg.Text = "0";
                int           attackerType = 0;
                int           defenderType = 0;
                List <string> dataSet      = null;
                List <string> attackerList;
                int           totalNoOfCatches = 0;

                RadioButton attackerRB = groupBox3.Controls.OfType <RadioButton>().FirstOrDefault(r => r.Checked);
                RadioButton defenderRB = groupBox2.Controls.OfType <RadioButton>().FirstOrDefault(r => r.Checked);

                attackerType = Convert.ToInt16(attackerRB.Tag);
                defenderType = Convert.ToInt16(defenderRB.Tag);


                if (rdbtnadaptivewsb.Checked)
                {
                    AprioriAlgorithm.associationMatrix = new int[11, 11]
                    {
                        { 0, 7, 7, 19, 7, 7, 7, 7, 25, 7, 7 },
                        { 0, 7, 7, 19, 7, 7, 7, 7, 25, 7, 7 },
                        { 0, 7, 7, 19, 7, 7, 7, 7, 25, 7, 7 },
                        { 0, 7, 7, 19, 7, 7, 7, 7, 25, 7, 7 },
                        { 0, 7, 7, 19, 7, 7, 7, 7, 25, 7, 7 },
                        { 0, 7, 7, 19, 7, 7, 7, 7, 25, 7, 7 },
                        { 0, 7, 7, 19, 7, 7, 7, 7, 25, 7, 7 },
                        { 0, 7, 7, 19, 7, 7, 7, 7, 25, 7, 7 },
                        { 0, 7, 7, 19, 7, 7, 7, 7, 25, 7, 7 },
                        { 0, 7, 7, 19, 7, 7, 7, 7, 25, 7, 7 },
                        { 0, 7, 7, 19, 7, 7, 7, 7, 25, 7, 7 }
                    };
                }

                RunGame runGame = new RunGame(defenderType, attackerType, (int)numericUpDown1.Value, (int)numericUpDown2.Value);

                if (rdbtnadaptivewsb.Checked)
                {
                    dataSet = runGame.getDataSet();
                    AprioriAlgorithm.CalculateAssociations(dataSet);
                }

                attackerList        = runGame.runAttacker();
                listBox2.DataSource = attackerList;
                listBox1.DataSource = runGame.runDefender(attackerList);
                totalNoOfCatches    = runGame.getTotalCatches();


                Lbltc.Text  = (totalNoOfCatches) + " / " + numericUpDown2.Value.ToString();
                lblavg.Text = ((totalNoOfCatches / numericUpDown2.Value) * 100).ToString("#.##") + " %";
            }
        }
Exemplo n.º 2
0
        private String getAdaptiveTarget(string attackLastTarget)
        {
            int index    = -1;
            int attackLT = 0;

            switch (attackLastTarget)
            {
            case "T1":
                attackLT = 1;
                break;

            case "T2":
                attackLT = 2;
                break;

            case "T3":
                attackLT = 3;
                break;

            case "T4":
                attackLT = 4;
                break;

            case "T5":
                attackLT = 5;
                break;

            case "T6":
                attackLT = 6;
                break;

            case "T7":
                attackLT = 7;
                break;

            case "T8":
                attackLT = 8;
                break;

            case "T9":
                attackLT = 9;
                break;

            case "T10":
                attackLT = 10;
                break;
            }
            string[]      targets            = Targets.getTargets();
            double[]      mixedStartegy      = AprioriAlgorithm.getMixedStrategy(attackLT);
            List <string> transformedTargets = new List <string>();

            for (int j = 0; j < mixedStartegy.Length; j++)
            {
                for (int i = 0; i < mixedStartegy[j] * 1000; i++)
                {
                    transformedTargets.Add(targets[j]);
                }
            }

            index = random.Next(0, transformedTargets.Count);

            return(transformedTargets[index]);
        }