コード例 #1
0
        public string displayResults(double[][] inputs, double[][] targets, double[][] results)
        {
            //Collapse results into this string before sending to textbox;
            string s = "";

            //Counter for incorrect actions
            int countIncorrectActions = 0;

            //Display in results box
            s = "Health" + "\t" + "Knife" + "\t" + "Gun" + "\t" + "Enemies" + "\t" + "Target" + "\t" + "Calculated" + Environment.NewLine;
            for (int i = 0; i < results.Length; i++)
            {
                //Pick entry
                double[] inputItem    = inputs[i];
                double[] targetAction = targets[i];

                //Show input
                int health  = Convert.ToInt32(inputItem[0]);
                int knife   = Convert.ToInt32(inputItem[1]);
                int gun     = Convert.ToInt32(inputItem[2]);
                int enemies = Convert.ToInt32(inputItem[3]);
                s += health + "\t" + knife + "\t" + gun + "\t" + enemies;

                //Show target
                string targetActionString = TrainingData.outputToText(targetAction);
                s += "\t" + targetActionString;

                //Show calculation
                double[] calculatedAction       = results[i];
                string   calculatedActionString = TrainingData.outputToText(calculatedAction);
                s += "\t" + calculatedActionString;

                //Count if not same action
                if (calculatedActionString != targetActionString)
                {
                    countIncorrectActions++;
                }

                //Next line
                s += Environment.NewLine;
            }

            //Show number of incorrect actions
            s += "Incorrect actions: " + countIncorrectActions.ToString();

            //Send to text box
            return(s);

            //string results2String = string.Join(",", Array.ConvertAll(results2, x => Math.Round(x, 3)));
        }
コード例 #2
0
        private void tbUseNetwork_TextChanged(object sender, EventArgs e)
        {
            //Default inputs
            int health  = 2;
            int knife   = 1;
            int gun     = 0;
            int enemies = 0;

            //Try to get inputs from form
            try {
                health = Convert.ToInt32(tbHealth.Text); if (health <= 0)
                {
                    throw new ArgumentException();
                }
                knife = Convert.ToInt32(tbKnife.Text); if (knife < 0 || knife > 1)
                {
                    throw new ArgumentException();
                }
                gun = Convert.ToInt32(tbGun.Text); if (gun < 0 || gun > 1)
                {
                    throw new ArgumentException();
                }
                enemies = Convert.ToInt32(tbEnemies.Text); if (enemies < 0)
                {
                    throw new ArgumentException();
                }
            }
            catch
            {
                //Return if any errors
                tbAction.Text = "";
                return;
            }

            //Calculate the action using the network
            double[] calcActionArray  = net.ProcessInput(new double[] { health, knife, gun, enemies });
            string   calcActionString = TrainingData.outputToText(calcActionArray);

            tbAction.Text = calcActionString;
        }