Exemple #1
0
        /// <summary>
        ///     Computes the specified input.
        /// </summary>
        /// <typeparam name="TGameOptimizer">The type of the game optimizer.</typeparam>
        /// <typeparam name="TGame">The type of the game.</typeparam>
        /// <typeparam name="TGameOutput">The type of the game output.</typeparam>
        /// <typeparam name="TInput">The type of the input.</typeparam>
        /// <param name="input">The input.</param>
        /// <param name="optimizer">The optimizer.</param>
        private static void Compute <TGameOptimizer, TGame, TGameOutput, TInput>(TInput input, TGameOptimizer optimizer)
            where TGameOptimizer : IGameOptimizer <TGame, TGameOutput>
            where TGame : IGame, new()
            where TGameOutput : IGameOutput
        {
            Console.WriteLine("Working with algo #{0}", optimizer.GetType().Name);
            string directory      = Path.GetDirectoryName(optimizer.GetType().Assembly.Location) ?? string.Empty;
            string sourceFilePath = Path.Combine(directory, "InputFiles", string.Format("{0}.in", input.ToString().ToLower()));

            Console.WriteLine("on input {0} (file: {1})", input, sourceFilePath);

            TGame     game  = new TGame();
            Stopwatch watch = new Stopwatch();

            watch.Start();
            Stopwatch totalDuration = new Stopwatch();

            totalDuration.Start();
            Console.WriteLine("Reading...");
            game.Read(sourceFilePath);
            watch.DisplayTime("Read !", true);
            int idx = 1;

            foreach (TGameOutput gameOutput in optimizer.Optimize(game))
            {
                watch.DisplayTime(string.Format("Optimized #{0}", idx), true);
                string targetFilePath = Path.Combine(directory, string.Format("{0}.{1}.{2}_{3}.out", input.ToString().ToLower(), optimizer.OptimizerId, idx, DateTime.Now));
                gameOutput.Export(targetFilePath);
                watch.DisplayTime(string.Format("Exported #{0}", idx), true);
                watch.DisplayTime(string.Format("GetResult ! result = {0} : ", gameOutput.GetResult()), true);
                idx++;
            }
            totalDuration.DisplayTime(string.Format("Done {0}!", input));
        }
Exemple #2
0
        /// <summary>
        ///     Defines the entry point of the application.
        /// </summary>
        /// <param name="args">The arguments.</param>
        public static void Main(string[] args)
        {
            //TestBoardExtensions();
            GameInputs  input         = GameProcessor.GetEnumFromArg(args, 0, GameInputs.Unset);
            OptimizerId optimizer     = GameProcessor.GetEnumFromArg(args, 1, OptimizerId.Schaepi);
            Stopwatch   totalDuration = new Stopwatch();

            totalDuration.Start();
            if (input == GameInputs.Unset)
            {
                GameProcessor.ComputeAll <IGameOptimizer <Game, CacheUsages>, Game, CacheUsages, GameInputs>(optimizer, EnumExtensions.GetValues <GameInputs>().ExceptElts(GameInputs.Unset).ToArray());
            }
            else
            {
                GameProcessor.Compute <IGameOptimizer <Game, CacheUsages>, Game, CacheUsages, GameInputs>(optimizer, input);
            }
            totalDuration.DisplayTime("Finished !");
            Console.ReadLine();
            Console.WriteLine("Tap to quit");
            Console.ReadLine();
        }
Exemple #3
0
        /// <summary>
        ///     Defines the entry point of the application.
        /// </summary>
        /// <param name="args">The arguments.</param>
        public static void Main(string[] args)
        {
            //TestBoardExtensions();
            GameInputs  input     = GameProcessor.GetEnumFromArg(args, 0, GameInputs.Unset);
            OptimizerId optimizer = GameProcessor.GetEnumFromArg(args, 1, OptimizerId.Schepi);
            //OptimizerId optimizer = GameProcessor.GetEnumFromArg(args, 1, OptimizerId.Jon);
            Stopwatch totalDuration = new Stopwatch();

            totalDuration.Start();
            if (input == GameInputs.Unset)
            {
                GameProcessor.ComputeAll <IGameOptimizer <Game, PizzaSlices>, Game, PizzaSlices, GameInputs>(optimizer);
            }
            else
            {
                GameProcessor.Compute <IGameOptimizer <Game, PizzaSlices>, Game, PizzaSlices, GameInputs>(input, optimizer);
            }
            totalDuration.DisplayTime("Finished !");
            Console.ReadLine();
            Console.WriteLine("Tap to quit");
            Console.ReadLine();
        }