예제 #1
0
파일: Program.cs 프로젝트: martugin/tetris
        static void Main(string[] args)
        {
            var argParser = new ArgParser(args);
            var outputDatas = new List<OutputData>();

            int timeLimit = (argParser.TimeLimit > 0 ? argParser.TimeLimit : 10000000);
            DateTime criticalTime = DateTime.Now + new TimeSpan(0, 0, timeLimit);

            foreach (var fileName in argParser.InputFileNames)
            {
                DebugPrinter.WriteLine("Processing {0}", fileName);
                DebugPrinter.WriteTrace("Processing {0}", fileName);

                var f = new StreamReader(fileName);
                var s = f.ReadToEnd();
                var inputData = JsonConvert.DeserializeObject<InputData>(s);
                var gameData = new GameData(inputData, argParser);

                DebugPrinter.WriteLine(PrettyPrinter.PrettyPrint(gameData.InputData));

                DateTime startTime = DateTime.Now;

                for (int seedIdx = 0; seedIdx < gameData.InputData.sourceSeeds.Length; ++seedIdx)
                {
                    int seed = gameData.InputData.sourceSeeds[seedIdx];
                    DebugPrinter.WriteTrace("    seed #{0}/{1}: {2}", seedIdx + 1, gameData.InputData.sourceSeeds.Length, seed);

                    string moves = new Algo2(gameData).Run(seed).String;
                    var outputData = new OutputData
                    {
                        problemId = inputData.id,
                        seed = seed,
                        solution = moves,
                    };

                    outputDatas.Add(outputData);
                    gameData.Reset();

                    DateTime now = DateTime.Now;
                    int avgTimeMs = (int)((now - startTime).TotalMilliseconds / (seedIdx + 1));
                    if (now + new TimeSpan(0, 0, 0, 0, avgTimeMs) > criticalTime)
                    {
                        DebugPrinter.WriteLine("Break due to time limit");
                        break;
                    }
                }
            }

            string outputStr = JsonConvert.SerializeObject(outputDatas);

            DebugPrinter.WriteLine("{0}", outputStr.Replace("\"", "\\\""));

            Console.WriteLine(outputStr);
        }
예제 #2
0
파일: Program.cs 프로젝트: martugin/tetris
        static void Main(string[] args)
        {
            //var fileNames = new[] { "problem_0.json", "problem_2.json", "problem_3.json", "problem_5.json",  "problem_7.json", "problem_8.json", "problem_9.json", "problem_10.json", "problem_11.json", "problem_15.json", "problem_16.json"};
            var fileNames = new[] { "problem_16.json"};
            var maxMetrics = new Metrics(new [] {0, 0}, 0, 0, 0, 0,0);
            for (MetricConst.KilledRows = 200; MetricConst.KilledRows <= 200; MetricConst.KilledRows += 100)
                for (MetricConst.RowPowerFactor = 0.9; MetricConst.RowPowerFactor  <= 0.9; MetricConst.RowPowerFactor += 0.1)
                    for (MetricConst.NewHolesCount = 100; MetricConst.NewHolesCount <= 100; MetricConst.NewHolesCount += 100)
                        for (MetricConst.JoinedCellsCount = 50; MetricConst.JoinedCellsCount <= 50; MetricConst.JoinedCellsCount += 10)
                            for (MetricConst.DownCellsCount = 20; MetricConst.DownCellsCount <= 20; MetricConst.DownCellsCount += 20)
                            {
                                var score = 0;
                                int[] scores = new int[fileNames.Length];
                                for (int i = 0; i < fileNames.Length; i++ )
                                {
                                    var fileName = fileNames[i];
                                    var f = new StreamReader(fileName);
                                    var s = f.ReadToEnd();
                                    var inputData = JsonConvert.DeserializeObject<InputData>(s);
                                    var gameData = new GameData(inputData, new ArgParser(new string[0]));

                                    int sidScore = 0;
                                    for (int seedIdx = 0; seedIdx < gameData.InputData.sourceSeeds.Length; ++seedIdx)
                                    //for (int seedIdx = 0; seedIdx < 3; ++seedIdx)
                                    {
                                        int seed = gameData.InputData.sourceSeeds[seedIdx];
                                        sidScore += new Algo1(gameData).Run(seed).Score;
                                    }
                                    scores[i] = sidScore / gameData.InputData.sourceSeeds.Length;
                                    score += scores[i];
                                }
                                Console.WriteLine("KilledRows: {0}, RowPowerFactor: {1}, N: {2}, J: {3}, D: {4}",
                                        MetricConst.KilledRows, MetricConst.RowPowerFactor, MetricConst.NewHolesCount, MetricConst.JoinedCellsCount, MetricConst.DownCellsCount);
                                //Console.WriteLine("KilledRows: {0}, RowPowerFactor: {1}", MetricConst.KilledRows, MetricConst.RowPowerFactor);
                                string ss = "";
                                for (int j = 0; j < fileNames.Length; j++)
                                    ss += fileNames[j] + ": " + scores[j] + ". ";
                                Console.WriteLine(ss + "Total: " + score + "\n");
                                if (score > maxMetrics.Score)
                                    maxMetrics = new Metrics(scores, MetricConst.KilledRows, MetricConst.RowPowerFactor, MetricConst.NewHolesCount, MetricConst.JoinedCellsCount, MetricConst.DownCellsCount);
                            }
                Console.WriteLine("Max");
                Console.WriteLine("KilledRows: {0}, RowPowerFactor: {1}, N: {2}, J: {3} , D: {4}",
                                maxMetrics.KilledRows, maxMetrics.RowPowerFactor, maxMetrics.NewHolesCount, maxMetrics.JointCellsCount, maxMetrics.DownCellsCount);
                //Console.WriteLine("KilledRows: {0}, RowPowerFactor: {1}", maxMetrics.KilledRows, maxMetrics.RowPowerFactor);
                string st = "";
                for (int j = 0; j < fileNames.Length; j++)
                    st += fileNames[j] + ": " + maxMetrics.Scores[j] + ". ";
                Console.WriteLine(st + "Total: " + maxMetrics.Score + "\n");
        }
예제 #3
0
파일: Algo1.cs 프로젝트: martugin/tetris
 public Algo1(GameData gameData)
 {
     _gameData = gameData;
 }
예제 #4
0
파일: BFS2.cs 프로젝트: martugin/tetris
 public BFS2(Field field, Unit unit, GameData gameData)
 {
     _field = field;
     _unit = unit;
     _gameData = gameData;
 }