private void visualizeFromFile_Click(object sender, EventArgs e) { Form form = new Form(); form.Show(); string bitstring = Clipboard.GetText(); if (game == null) { MessageBox.Show("Game not set"); return; } NNMaker nnMaker = new SimpleNNMaker(game); if (bitstring.Length != nnMaker.ChromosomeLength()) { MessageBox.Show("Clipboard text has length " + bitstring.Length + ", required bitstring length is " + nnMaker.ChromosomeLength()); } else if (bitstring.Any(p => (p != '0' && p != '1'))) { MessageBox.Show("Clipboard text does not only contain 0's and 1's"); } else { AIPlayer aip = new AIPlayer(new Chromosome(Clipboard.GetText()), nnMaker); game.Visualize(aip, form); } }
public void TestOutputOnChromosome() { AITrainableGame game = new GameWith7Inputs8Outputs(); NNMaker nnMaker = new SimpleNNMaker(game); Chromosome chromosome = new Chromosome(nnMaker.ChromosomeLength()); NeuralNetwork neuralNetwork = nnMaker.MakeNeuralNetwork(chromosome); double[] input = new double[7]; double[] lastInput = new double[7]; double[] output; double[] lastOutput = new double[0]; for (int p = 0; p < 7; p++) { input[p] = Utility.RandomNum.RandomDouble() * 100.0 - 50.0; lastInput[p] = input[p]; } for (int i = 0; i < 10; i++) { neuralNetwork.SetInput(input); output = neuralNetwork.GetOutput(); if (lastOutput.Length != 0) { for (int s = 0; s < 8; s++) { Assert.AreEqual(output[s], lastOutput[s]); } } lastOutput = output; if (lastInput.Length != 0) { for (int s = 0; s < 7; s++) { Assert.AreEqual(input[s], lastInput[s]); } } lastInput = input; } }