public List <RunResult> Process() { const TaskContinuationOptions opts = TaskContinuationOptions.OnlyOnRanToCompletion; var repo = new ExecReportRepository(_workingDir); var cts = new CancellationTokenSource(); var tasks = new List <Task <RunResult> >(); foreach (var player in ListPlayers()) { var eng = new BattleshipGame(player.Name, player.ExePath, repo); var run = Task.Factory.StartNew(() => eng.PrepareGame()) .ContinueWith((parent) => eng.StartProgram(), opts) .ContinueWith((parent) => eng.AttachToProgramOutput(), opts) .ContinueWith <RunResult>((parent) => eng.ProcessRunResults(), opts); tasks.Add(run); } Task.WaitAll(tasks.ToArray()); var results = tasks.Where(x => x.IsCompleted).Select(x => x.Result).ToList(); return(results); }
public BattleshipGame(string playerName, string exePath, ExecReportRepository repository) { _repository = repository; _exePath = exePath; _gen = new BoardGenerator(); _board = new char[10, 10]; _playerName = playerName; _moves = new List <string>(); State = GameState.Starting; }
public EngineExecutor(string workingDirectory, ExecReportRepository reportRepo) { if (reportRepo == null) { throw new ArgumentNullException(); } if (!Directory.Exists(workingDirectory)) { throw new DirectoryNotFoundException(); } _workingDir = workingDirectory; _reportRepo = reportRepo; _players = new ConcurrentBag <Player>(); }