예제 #1
0
        private static int SolveField(int currentFieldNumber)
        {
            while (true)
            {
                currentFieldNumber++;

                var field = PatienceField.FillWithRandomCards(new Random(currentFieldNumber));
                field.DumpToConsole();
                TimeSpan timeout   = TimeSpan.FromSeconds(10);
                var      stopwatch = Stopwatch.StartNew();
                var      solution  = TrySolve(field, timeout);
                stopwatch.Stop();
                if (solution == null)
                {
                    Console.WriteLine("No solution found for field {0} in {1} seconds :(", currentFieldNumber, stopwatch.Elapsed.TotalSeconds);
                }
                else
                {
                    Console.WriteLine("Solution found for field {0} in {1} seconds :)({2} steps) ",
                                      currentFieldNumber, stopwatch.Elapsed.TotalSeconds, solution.GetSequence().Count());
                    File.AppendAllText(solvableFieldsFile, String.Format("{0};{1};{2}\r\n",
                                                                         currentFieldNumber,
                                                                         stopwatch.Elapsed.TotalMilliseconds,
                                                                         String.Join(",", solution.WinningMoves().ToArray())));
                }
            }
        }
예제 #2
0
 static void Main(string[] args)
 {
     if (args.FirstOrDefault() == "play")
     {
         int field;
         if (!int.TryParse(args.LastOrDefault(), out field))
         {
             field = new Random().Next();
         }
         Console.WriteLine("Playing field {0}", field);
         PlayGame(PatienceField.FillWithRandomCards(new Random(field)));
     }
     else
     {
         SolveField(GetLastField());
     }
 }