Beispiel #1
0
        static void MainWithOptions(Options options)
        {
            Stopwatch stopwatch = null;

            BoardState board = Risk.RandomizedBoardPlacement(0);
            var        pool  = new ControlledThreadPool(options.Cores - 1);

            if (options.Time)
            {
                stopwatch = new Stopwatch();
                stopwatch.Start();
            }

            Move move = (options.AlphaBeta, options.Parallel, options.YoungBrothersWait) switch
            {
                (true, false, true) => AlphaBeta.ParallelYbw <BoardState, Move>(board, options.MaxDepth, pool),
                (true, true, false) => AlphaBeta.Parallel <BoardState, Move>(board, options.MaxDepth),
                (true, false, false) => AlphaBeta.Serial <BoardState, Move>(board, options.MaxDepth),
                (false, false, true) => Minimax.ParallelYbw <BoardState, Move>(board, options.MaxDepth, pool),
                (false, true, false) => Minimax.Parallel <BoardState, Move>(board, options.MaxDepth),
                (false, false, false) => Minimax.Serial <BoardState, Move>(board, options.MaxDepth),
                _ => throw new ArgumentException()
            };

            stopwatch?.Stop();

            if (move.IsAttack)
            {
                Console.WriteLine($"Attack dotfrom {(Risk.Id)move.FromId} to {(Risk.Id)move.ToId}");
            }
            else if (move.FortifyCount > 0)
            {
                Console.WriteLine($"Pass turn and fortify {move.FortifyCount} troops from {(Risk.Id)move.FromId} to {(Risk.Id)move.ToId}");
            }
            else
            {
                Console.WriteLine("Pass turn and don't fortify.");
            }

            if (options.Time)
            {
                Console.WriteLine($"Runtime (s): {stopwatch.Elapsed.TotalSeconds}");
            }
        }