void Awake() { AI = GetComponent <SnakeAI> (); boxCollider = GetComponent <BoxCollider2D> (); snakeMeshContainer = GetComponentInChildren <SnakeMeshContainer> (); ownedGroundPieces = new List <GroundPiece> (); }
static void Main(string[] args) { Console.CursorVisible = false; Console.WriteLine("Press 1 to train new neural network"); Console.WriteLine("Press 2 start snake with hardcoded AI"); Console.WriteLine("Press 3 to load trained network"); var key = Console.ReadKey(); bool isTraining = false; SnakeAI snakeAI = null; if (key.KeyChar == '1') { isTraining = true; new Thread(() => { Thread.CurrentThread.Priority = ThreadPriority.BelowNormal; TrainNeuralAI(); }).Start(); } else if (key.KeyChar == '2') { snakeAI = new SnakeFakeAI(); } else { snakeAI = new SnakeNeuralAI() { Network = NeuralNetwork.Load(@"AI\TrainedNetwork") }; } Console.Clear(); while (true) { if (isTraining) { lock (_lockObjectFile) { snakeAI = SnakeNeuralAI.Clone(SuperNetwork, false); } } World world = new World(worldWidth, worldHeigh, foodPoints); Stopwatch stopwatch = new Stopwatch(); while (world.Snake.Alive) { stopwatch.Restart(); snakeAI.MakeDecision(world); lock (_lockObjectConsole) { ConsoleRenderer.Render(world); } Thread.Sleep(Math.Max(0, 50 - (int)stopwatch.ElapsedMilliseconds)); if (Console.KeyAvailable) { Console.ReadKey(); break; } } lock (_lockObjectConsole) { ConsoleRenderer.Render(world); } Thread.Sleep(2000); } }
private void Awake() { instance = this; }