private double run2048(Genome genome) { _2048 = new game2048(); _2048.initGame(); while (_2048.state == game2048.GameState.Playing) { double[] inputs = new double[16]; inputs = _2048.getInputs(); double[] ans = genome.calculateMove(inputs); game2048.Direction move; if (ans[0] < 0.25) { move = game2048.Direction.Down; } else if (ans[0] < 0.50) { move = game2048.Direction.Up; } else if (ans[0] < 0.75) { move = game2048.Direction.Left; } else { move = game2048.Direction.Right; } _2048.moveTiles(move); } return(_2048.score); }
private void demo2048(Genome genome) { InfoManager.clearLine(); _2048 = new game2048(); _2048.background = false; _2048.initGame(); _2048.background = false; _2048.StartPosition = FormStartPosition.CenterScreen; _2048.Show(); String moves = ""; while (_2048.state == game2048.GameState.Playing) { double[] inputs = new double[16]; inputs = _2048.getInputs(); double[] ans = genome.calculateMove(inputs); game2048.Direction move; if (ans[0] < 0.25) { move = game2048.Direction.Down; } else if (ans[0] < 0.50) { move = game2048.Direction.Up; } else if (ans[0] < 0.75) { move = game2048.Direction.Left; } else { move = game2048.Direction.Right; } _2048.moveTiles(move); moves += ((string)move.ToString())[0]; Console.WriteLine(move); _2048.Refresh(); Thread.Sleep(1000 / 2); } InfoManager.addLine("Genome ran with a fitness score of " + _2048.score); InfoManager.addLine("Moves made: " + moves); }