private void RunNN(InitialNeuralNetwork net) { if (net.outNodes[0] >= 4) { cube.Translate(Vector2.right * 4f * Time.deltaTime); } if (net.outNodes[1] >= 5) { ; cube.Translate(Vector2.left * 2f * Time.deltaTime); } if (grounded == true && net.outNodes[2] >= 2) { grounded = false; GetComponent <Rigidbody2D>().velocity = new Vector2 (GetComponent <Rigidbody2D>().velocity.x, 12.5f); } fitness = cube.position.x; }
void Update() { Debug.DrawRay(cube.transform.position, forward * distance, Color.white); Debug.DrawRay(cube.transform.position, back * distance, Color.white); Debug.DrawRay(cube.transform.position, up * distance, Color.white); Debug.DrawRay(cube.transform.position, down * distance, Color.white); Debug.DrawRay(cube.transform.position, northEast * distance, Color.white); Debug.DrawRay(cube.transform.position, northWest * distance, Color.white); Debug.DrawRay(cube.transform.position, southEast * distance, Color.white); Debug.DrawRay(cube.transform.position, southWest * distance, Color.white); if (col) { if (Physics2D.Raycast(cube.transform.position, northEast, distance, ((1 << 9) | (1 << 10) | (1 << 11) | (1 << 12)))) { first = 1; } else { first = 0; } if (Physics2D.Raycast(cube.transform.position, forward, distance, ((1 << 9) | (1 << 10) | (1 << 11) | (1 << 12)))) { second = 1; } else { second = 0; } if (Physics2D.Raycast(cube.transform.position, southEast, distance, ((1 << 9) | (1 << 10) | (1 << 11) | (1 << 12)))) { third = 1; } else { third = 0; } if (Physics2D.Raycast(cube.transform.position, down, distance, ((1 << 9) | (1 << 10) | (1 << 11) | (1 << 12)))) { fourth = 1; } else { fourth = 0; } if (Physics2D.Raycast(cube.transform.position, southWest, distance, ((1 << 9) | (1 << 10) | (1 << 11) | (1 << 12)))) { fifth = 1; } else { fifth = 0; } if (Physics2D.Raycast(cube.transform.position, back, distance, ((1 << 9) | (1 << 10) | (1 << 11) | (1 << 12)))) { sixth = 1; } else { sixth = 0; } if (Physics2D.Raycast(cube.transform.position, northWest, distance, ((1 << 9) | (1 << 10) | (1 << 11) | (1 << 12)))) { seventh = 1; } else { seventh = 0; } if (Physics2D.Raycast(cube.transform.position, up, distance, ((1 << 9) | (1 << 10) | (1 << 11) | (1 << 12)))) { eighth = 1; } else { eighth = 0; } input[0] = first; input[1] = second; input[2] = third; input[3] = fourth; input[4] = fifth; input[5] = sixth; input[6] = seventh; input[7] = eighth; firstNetwork = new InitialNeuralNetwork(input, con); secondNetwork = new InitialNeuralNetwork(input, con2); thirdNetwork = new InitialNeuralNetwork(input, con3); fourthNetwork = new InitialNeuralNetwork(input, con4); fifthNetwork = new InitialNeuralNetwork(input, con5); sixthNetwork = new InitialNeuralNetwork(input, con6); seventhNetwork = new InitialNeuralNetwork(input, con7); eighthNetwork = new InitialNeuralNetwork(input, con8); ninthNetwork = new InitialNeuralNetwork(input, con9); tenthNetwork = new InitialNeuralNetwork(input, con10); switch (counter) { case 1: network = firstNetwork; RunNN(network); break; case 2: network = secondNetwork; RunNN(network); break; case 3: network = thirdNetwork; RunNN(network); break; case 4: network = fourthNetwork; RunNN(network); break; case 5: network = fifthNetwork; RunNN(network); break; case 6: network = sixthNetwork; RunNN(network); break; case 7: network = seventhNetwork; RunNN(network); break; case 8: network = eighthNetwork; RunNN(network); break; case 9: network = ninthNetwork; RunNN(network); break; case 10: network = tenthNetwork; RunNN(network); break; } } }